BeanConfig (or similar?) in Swagger 2.0 (OpenApi 3.0)(Swagger 2.0 (OpenApi 3.0) 中的 BeanConfig(或类似的?))
问题描述
我目前正在将我们的 API 文档(即 Swagger 1.5)迁移到 Swagger 2.0 (OpenApi 3.0)
I am currently migrating our API docs (which were Swagger 1.5) to Swagger 2.0 (OpenApi 3.0)
API 文档是使用 maven 包 swagger-annotations
和 swagger-jaxrs
生成的 Swagger 文档.我已经用新版本更新了 pom.xml,所以它看起来像:
The API docs are Swagger docs which get generated with java annotations using maven packages swagger-annotations
and swagger-jaxrs
. I have already updated the pom.xml with new versions so it looks like:
<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>
而且所有旧注释都被新注释替换(变化很大)并且看起来很好.
And also all the old annotations are replaced with the new ones (which change quite a lot) and looks fine.
问题是我们使用 BeanConfig
来定义文档常规配置并自动扫描所有 REST 资源,以便在 /swagger.json
自动生成文档.
The thing is we were using a BeanConfig
to define the docs general config and auto-scan all the REST resources so the documentation got generated automatically at /swagger.json
.
问题是我找不到创建 BeanConfig 和自动扫描资源这样的新方法",以便在 /swagger.json
或 /openapi.json
(也许现在类似于 OpenAPIDefinition?)
The problem is I can't find the "new way" of doing such thing as creating a BeanConfig and auto-scan the resources so everything gets generated at /swagger.json
or /openapi.json
(maybe now is something like OpenAPIDefinition?)
如果有人能指出我正确的方向,我将不胜感激......
If somebody could point me to the right direction I would be very grateful...
推荐答案
经过一番研究,我可以在他们的 Github 用于 JAX-RS 应用程序,所以结果类似于我正在做,但现在不是使用 BeanConfig
,而是使用 OpenAPI
和 Info
:
After some research, I could find some documentation about it in their Github for JAX-RS application, so the result is something similar to what I was doing but now instead of using a BeanConfig
, it uses 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("apiteam@swagger.io"))
.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);
}
}
}
这篇关于Swagger 2.0 (OpenApi 3.0) 中的 BeanConfig(或类似的?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swagger 2.0 (OpenApi 3.0) 中的 BeanConfig(或类似的?)
基础教程推荐
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01