0
我嘗試從我的Java休息端點生成swagger.json。如何分開獲得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。
- 如何爲每個端點分別獲取json?
- 我可以讓它們在文件系統中本地生成嗎?
- 大JSON文件一次加載UI。我想要爲每個端點類型分開鏈接。
什麼是您使用的Java框架?或者你可以發佈任何鏈接,如果有的話,你遵循配置Swagger? –
@SweetWijerathne io.swagger圖書館 – Ratha
不,我問的是應用程序框架,例如:Spring MVC,Play等? –