用于 Tapestry 5.4 的带有 Tynamo Resteasy 的 Swagger UI [英] Swagger UI with Tynamo Resteasy for Tapestry 5.4
问题描述
我在 Tapestry 5.4 项目中使用 tynamo resteasy.我想合并 Swagger 来记录并与其他团队共享 API.虽然我看到 swagger 已经在 RestEasy 的项目依赖中,但它不能开箱即用"
I am using tynamo resteasy with my Tapestry 5.4 project. I'd like to incorporate Swagger to document and share API with other other teams. While I see that swagger is already in RestEasy's project dependency, it does not work "out of the box"
我已添加
@Api
到Resource"类(位于 /rest/
包中)和@ApiOperation
到 GET
方法
@Api
to the "Resource" class (located in /rest/
package)
and
@ApiOperation
to the GET
method
我是否需要更改 AppModule
或 web.xml
以挂钩 swagger UI?是否有任何我可以遵循的示例(github 等)?
Do I need to change AppModule
or web.xml
in anyway to hook the swagger UI?
Is there an example (github etc.) anywhere that I can follow?
此外,localhost/swagger/myendpoint
是否可以使用 swagger api?
Also, will the swagger api be available at localhost/swagger/myendpoint
?
推荐答案
以下是分步过程:
获取 swagger-jaxrs:https://mvnrepository.com/神器/io.swagger/swagger-jaxrs/1.5.0
Get swagger-jaxrs: https://mvnrepository.com/artifact/io.swagger/swagger-jaxrs/1.5.0
在modules"目录下创建一个SwaggerModule.java
(例如:com.mysite.mypkg.modules
)
Create a SwaggerModule.java
in "modules" directory (example: 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)
On your AppModule.java, import the SwaggerModule (Tapestry 5.4)
@ImportModule(SwaggerModule.class)
public class AppModule {...
}
swagger.json
和 swagger.yaml
现在可以通过以下方式访问:
The swagger.json
and swagger.yaml
can now be accessed as:
http://localhost:8080/mysite/rest/swagger.json
非常感谢上面的@ascandroli 指出基础
Many thanks to @ascandroli above for pointing out the basics
这篇关于用于 Tapestry 5.4 的带有 Tynamo Resteasy 的 Swagger UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!