使用Maven插件生成春季应用程序来源的OpenAPI 3.0 JSON/YAML
我想从现有Spring(注意:不是引导)应用程序源在编译时生成OpenAPI 3.0定义。
我已经在控制器类中设置了 io.swagger.v3.oas.annotations
:
package com.acme.rest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "Dummy Controller", description = "Dummy controller.")
@RestController
@RequestMapping("/api/v1/dummy")
public class DummyController {
@Operation(summary = "dummy(). Does litrally nothing.")
@RequestMapping(value = "/", method = RequestMethod.GET)
public String doStuff() {
return "dummy";
}
}
并尝试了 Swagger-Maven-Plugin
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<outputPath>${project.build.directory}/swagger-def</outputPath>
<resourcePackages>com.acme</resourcePackages>
<prettyPrint>true</prettyPrint>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
但是,除了 OpenApi
版本外,我什么也没得到。
MVN CLEAN COMPILE
,生产:
{
"openapi" : "3.0.1"
}
我通过实现挖掘一点,似乎没有 io.swagger.v3.oas.integration.api.openapireader
和/或 io.swagger.v3.oas.integration.api.openapiscanner
实现以实际获取相关的注释并解析它们。我从一个事实中得出结论:如果我按照 docs 我可以生成的来源。
<scannerClass>com.acme.util.SwaggerOpenApiScanner</scannerClass>
<readerClass>com.acme.util.SwaggerOpenApiReader</readerClass>
我只是不明白为什么启动Swagger插件不会解析摇摇注释,尽管它们俩都来自同一组 io.swagger.core.v3
?
什么是什么我错过了什么?您可以推荐一些替代插件来完成这项工作吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用项目中的Swagger V3注释,并且正面临同样的问题。
我找到了使用Maven中
springdoc-openapi-ui
springdoc-openapi-maven-plugin
,它与生成的摇摇欲坠文档搭配得很好。这是我在Maven中的配置:
此处有关此插件的更多信息:
I am using the Swagger v3 annotations in my project and I was facing the same issue.
I have found the
springdoc-openapi-maven-plugin
that works well with the generated Swagger docs using thespringdoc-openapi-ui
dependency in Maven.Here is my configuration in Maven:
More information on this plugin here: