我目前正在将我们的 API 文档(Swagger 1.5)迁移到 Swagger 2.0(OpenApi 3.0)
API 文档是 Swagger 文档,它是使用 maven 包通过 java 注释生成的swagger-annotations
and swagger-jaxrs
。我已经用新版本更新了 pom.xml,所以它看起来像:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.6</version>
</dependency>
而且所有旧的注释都被新的注释所取代(变化很大)并且看起来不错。
问题是我们使用的是BeanConfig
定义文档常规配置并自动扫描所有 REST 资源,以便自动生成文档/swagger.json
.
The problem是我找不到执行诸如创建 BeanConfig 并自动扫描资源之类的“新方法”,以便在以下位置生成所有内容/swagger.json
or /openapi.json
(也许现在是类似 OpenAPIDefinition 的东西?)
如果有人能指出我正确的方向,我将非常感激......
经过一番研究,我可以在他们的网站中找到一些有关它的文档Github对于 JAX-RS 应用程序,所以结果与我所做的类似,但现在不是使用BeanConfig
, 它用OpenAPI
and Info
:
@ApplicationPath("/sample")
public class MyApplication extends Application {
public MyApplication(@Context ServletConfig servletConfig) {
super();
OpenAPI oas = new OpenAPI();
Info info = new Info()
.title("Swagger Sample App bootstrap code")
.description("This is a sample server Petstore server. You can find out more about Swagger " +
"at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, " +
"you can use the api key `special-key` to test the authorization filters.")
.termsOfService("http://swagger.io/terms/")
.contact(new Contact()
.email("[email protected]"))
.license(new License()
.name("Apache 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
oas.info(info);
SwaggerConfiguration oasConfig = new SwaggerConfiguration()
.openAPI(oas)
.prettyPrint(true)
.resourcePackages(Stream.of("io.swagger.sample.resource").collect(Collectors.toSet()));
try {
new JaxrsOpenApiContextBuilder()
.servletConfig(servletConfig)
.application(this)
.openApiConfiguration(oasConfig)
.buildContext(true);
} catch (OpenApiConfigurationException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)