我在我的Tapestry 5.4项目中使用肉桂酒。我想将Swagger合并到文档中,并与其他团队共享API。虽然我看到swagger已经在RestEasy的项目依赖项中了,但它不能“开箱即用”。
我增加了
@Api到"Resource“类(位于/rest/包中),@ApiOperation指向GET方法
我是否需要更改AppModule或web.xml来挂起傲慢的UI?有例子(github等)吗?我能跟踪的地方吗?
另外,swagger是否可以在localhost/swagger/myendpoint上使用?
发布于 2017-06-05 00:19:34
下面是一个逐步的过程:
招摇过市: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 (Tapestry5.4)
@ImportModule(SwaggerModule.class)
public class AppModule {...
}现在可以以以下方式访问swagger.json和swagger.yaml:
http://localhost:8080/mysite/rest/swagger.json感谢上面的@ascandroli指出了基本知识
发布于 2017-05-31 10:08:46
看看这个旧的提交:https://github.com/tynamo/tapestry-resteasy/commit/9a4c2979fda83900480449f25df8cb5e919e4306
特别注意SwaggerModule。这段代码相当古老,我几乎可以肯定,如果您按原样复制和粘贴它,它将不会在方框外工作,但它会让您很好地了解项目之间的连接以及所需的设置。
发布于 2020-04-21 21:33:57
看起来我离派对只晚了三年,但无论如何,我需要一个项目的集成,所以我把@ascandroli的代码更新为OpenAPI 3.0 (摆芯2.x),并将swagger集成作为自己的独立子模块,通过添加依赖项,使其为用户打开方框。细节有点粗略,但tapestry-resteasy-swagger模块源代码在github上和GAV坐标现在是org.tynamo:tapestry-resteasy-swagger:0.0.2。我将在时间允许的情况下添加更多信息,但同时检查集成测试项目。
https://stackoverflow.com/questions/44249777
复制相似问题