Open API 代码生成器 Maven 插件使用旧的 Swagger 2 注释而不是 Swagger 3 注释 [英] Open API code generator Maven plugin uses old Swagger 2 annotations instead of Swagger 3 annotations

查看:31
本文介绍了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.

根据官网https://openapi-generator.tech/docs/plugins/ ,我应该包含这个依赖:

According to the official website https://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:
https://github.com/OpenAPITools/openapi-generator/pull/4779
https://github.com/OpenAPITools/openapi-generator/pull/6306

更多信息:
https://github.com/OpenAPITools/openapi-generator/issues/6108
https://github.com/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 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆