如何单独获取swagger json? [英] How to get swagger json separately?
本文介绍了如何单独获取swagger json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从Java其余端点生成swagger.json.
I try to generate swagger.json from my java rest endpoints.
pom
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.9</version>
</dependency>
应用程序路径
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?
When i deploy my testdbwar in wildfly,
I try to access my json like;
http://localhost:8080/testdbwar/rest/swagger.json?
然后我得到一个包含所有json的大json.
And i get a big json which contains all jsons .
- 如何为每个端点分别获取json?
- 我可以在文件系统中本地生成它们吗?
- 大json文件可一次加载UI.我希望每种端点类型都有单独的链接.
推荐答案
- 通常对于任何swagger库,它都是
all_resource_listing_url/pathName
.当我用Google搜索jax-rs时, IBM . - 第1季度的解决方案也适用于此,对不对?在swagger-ui中,您可以为每个不同的路径以不同的方式调用swagger文档url.
- Generally for any swagger library, it is
all_resource_listing_url/pathName
. When I googled for jax-rs, this is one I found somewhat related to your problem though that was with wordnik.swagger library. In your case, it should behttp://localhost:8080/testdbwar/rest/swagger.json/Addresss
for apis listed under path'Addresss'
. I don't know, whether you misspelled 'Addresss' with 'sss' and tried with 'ss' already. And please also try with a lower-case path name. - I don't think there's an automated way with swagger configuration itself. But You can do that manually with a small-code right? Anyway It looks like, that kind of a support is available there with some commercial tools like IBM.
- A solution for Q1 is applicable to this one too, right? Inside the swagger-ui, you can invoke the swagger doc urls differently for each different paths.
这篇关于如何单独获取swagger json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文