这是一个逐步的过程:
获取 swagger-jaxrs:https ://mvnrepository.com/artifact/io.swagger/swagger-jaxrs/1.5.0
SwaggerModule.java
在“模块”目录中创建一个(例如com.mysite.mypkg.modules
:)
public class SwaggerModule {
@Contribute(SymbolProvider.class)
@ApplicationDefaults
public static void provideSymbols(MappedConfiguration<String, Object> configuration) {
configuration.add(ResteasySymbols.CORS_ENABLED, true);
}
@Contribute(javax.ws.rs.core.Application.class)
public static void contributeApplication(Configuration<Object> singletons) {
singletons.addInstance(io.swagger.jaxrs.listing.ApiListingResource.class);
singletons.addInstance(io.swagger.jaxrs.listing.SwaggerSerializers.class);
}
@Startup
public static void swagger(javax.ws.rs.core.Application application,
BaseURLSource baseURLSource,
@Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM) String basePackage,
@Symbol(ResteasySymbols.MAPPING_PREFIX) String restPath,
@Symbol(SymbolConstants.APPLICATION_VERSION) String version) {
application.getSingletons();
BeanConfig config = new BeanConfig();
config.setSchemes(new String[]{"http"});
config.setVersion("1.0.2");
config.setHost("localhost:8080");
config.setBasePath("/mysite" + restPath);
config.setTitle("Mysite Rest Documentation");
config.setResourcePackage("com.mysite.mypkg.rest");//where your rest resources are located
config.setScan(true);
}
在您的 AppModule.java 上,导入 SwaggerModule (Tapestry 5.4)
@ImportModule(SwaggerModule.class)
public class AppModule {...
}
swagger.json
和现在swagger.yaml
可以访问为:
http://localhost:8080/mysite/rest/swagger.json
非常感谢上面的@ascandroli 指出了基础知识