Open API 代码生成器 Maven 插件使用旧的 Swagger 2 注释而不是 Swagger 3 注释

编程入门 行业动态 更新时间:2024-10-23 02:45:39
本文介绍了Open API 代码生成器 Maven 插件使用旧的 Swagger 2 注释而不是 Swagger 3 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 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 注释

本文发布于:2023-11-17 12:01:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   而不是   插件   代码生成器   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!