我正在使用 Open API 代码生成器 Maven 插件从文件生成 Open API 3.0.我在我的 pom.xml 中使用了这个插件:
I'm using Open API code generator Maven plugin to generate Open API 3.0 from a file. I'm using this plugin in in my pom.xml:
<groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>4.3.0</version>插件生成 API 时没有任何问题,但它不使用 Swagger v3 注释,而是使用旧的 Swagger 注释.例如参数使用 @ApiParam 注释,而 @Parameter 注释应该使用 io.swagger.v3.oas.annotations 包:
The plugin generates the API without any issues but instead of using Swagger v3 annotations it uses old Swagger annotations. For example parameters are annotated using @ApiParam, instead @Parameter annotation should be used from io.swagger.v3.oas.annotations package:
default ResponseEntity<Fault> getFault(@ApiParam(value = "",required=true) @PathVariable("jobId") String jobId) {因此,最新的 Swagger UI 无法正确显示文档.当我使用 swagger.v3 注释创建端点时,Swagger UI 工作正常.
Because of it the latest Swagger UI isn't showing the documentation correctly. When I create an endpoint using swagger.v3 annotations then Swagger UI is working properly.
根据官网openapi-generator.tech/docs/plugins/ ,我应该包含这个依赖:
According to the official website openapi-generator.tech/docs/plugins/ , I should include this dependency:
<dependency> <groupId>io.swagger.parser.v3</groupId> <artifactId>swagger-parser</artifactId> </dependency>但即使有这种依赖关系,插件仍然会生成带有旧注释的源代码.
But even with this dependency the plugin still generates sources with the old annotations.
如何强制 Open API 代码生成器使用 Swagger v3 注释?
How can I force Open API code generator to use Swagger v3 annotations?
推荐答案目前不支持V3注解.
您需要覆盖 mustache 模板.
You need to override mustache templates.
检查这些 PR:github/OpenAPITools/openapi-generator/pull/4779github/OpenAPITools/openapi-generator/pull/6306
更多信息:github/OpenAPITools/openapi-generator/issues/6108github/OpenAPITools/openapi-generator/issues/5803
您可以使用上述 PR 中的升级模板或在合并时等待.
You can use upgraded templates from PRs above or wait when merged.
更多推荐
Open API 代码生成器 Maven 插件使用旧的 Swagger 2 注释而不是 Swagger 3 注释
发布评论