我尝试从我的java rest端点生成swagger.json。
POM
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.9</version>
</dependency>
Applicationpath
import javax.ws.rs.ApplicationPath;
@ApplicationPath("/rest")
public class RestApplication extends Application {
public RestApplication() {
BeanConfig beanConfig = new BeanConfig();
//beanConfig.setVersion("1.0");
beanConfig.setSchemes(new String[] { "http" });
beanConfig.setTitle("My API");
beanConfig.setBasePath("/rest");
beanConfig.setResourcePackage("com.test.rest");
beanConfig.setScan(true);
}
@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
set.add(com.test.AddressEndpoint.class);
set.add(com.test.ATGEndpoint.class);
set.add(com.test.CompanyEndpoint.class)
set.add(io.swagger.jaxrs.listing.ApiListingResource.class);
set.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
return set;
}
}
AddressEndpoint
@Api
@Singleton
@Path("/Addresss")
@Produces("application/json")
@ConcurrencyManagement
@Lock(LockType.READ)
public class AddressEndpoint {
private static final Logger log = Logger.getLogger(AddressEndpoint.class.getName());
@Context
private HttpRequest httpRequest;
@Inject
AddressService AddressService;
/**
* @description creates a new Address
* @status 400 Address country cannot be null
* @status 400 Address address2 cannot be null
* @status 400 Address city cannot be null
* @status 400 Address address1 cannot be null
* @status 400 Address postcode cannot be null
* @status 400 Address id cannot be null
* @status 400 Address state cannot be null
* @status 201 Address created successfully
*/
@POST
@Consumes("application/json")
public Response create(Address entity) {
AddressService.insert(entity);
return Response.created(UriBuilder.fromResource(AddressEndpoint.class).path(String.valueOf(entity.getId())).build()).build();
}
...
当我在wildfly中部署testdbwar时,
我尝试访问我的json;
的 http://localhost:8080/testdbwar/rest/swagger.json?
我得到一个包含所有jsons的大json。
答案 0 :(得分:0)
all_resource_listing_url/pathName
。当我用google搜索jax-rs时,this是我发现的与你的问题有些相关的问题,尽管那是wordnik.swagger库。在您的情况下,路径http://localhost:8080/testdbwar/rest/swagger.json/Addresss
下列出的apis应为'Addresss'
。我不知道你是否拼错了地址&#39;用&#39; sss&#39;并试过&#39; s&#39;已经。另请尝试使用小写路径名称。