简体   繁体   English

OpenAPI 生成器在字段级别添加注释

[英]OpenAPI generator add annotation on field level

I am using openapi generator (5.4.0) with gradle(7.3.3) and SpringBoot (2.6.6).我将 openapi 生成器 (5.4.0) 与 gradle(7.3.3) 和 SpringBoot (2.6.6) 一起使用。

my OpenApi configuration:我的 OpenApi 配置:

  ext.openApiConfigOptions = [
            library                       : "spring-boot",
            dateLibrary                   : "java8",
            delegatePattern               : "true",
            useTags                       : "true",
            openApiNullable               : "false",
            additionalModelTypeAnnotations: "@lombok.Builder @lombok.NoArgsConstructor @lombok.AllArgsConstructor",
            booleanGetterPrefix           : "is"
    ]

My goal is to add the @lombok.Builder.Default annotation over the field.我的目标是在该字段上添加 @lombok.Builder.Default 注释。

From documentation:从文档: 在此处输入图像描述

According to this: link to example I tried using x-field-extra-annotation: in my spec, but it doesn't work in my case.根据这个: 链接到示例我尝试使用 x-field-extra-annotation: 在我的规范中,但它在我的情况下不起作用。

In my case it works like this;就我而言,它是这样工作的;

  • x-extra-annotation:"@lombok.Builder.Default" adds an annotation over the getter. x-extra-annotation:"@lombok.Builder.Default" 在 getter 上添加注释。
  • The;这; x-setter-extra-annotation:"@lombok.Builder.Default" results in adding an annotation to the setter. x-setter-extra-annotation:"@lombok.Builder.Default" 导致向设置器添加注释。
  • But;但; x-field-extra-annotation has no effect. x-field-extra-annotation 无效。

Similar unanswered question: link类似未回答的问题: 链接

将 openapi 生成器升级到 6.0.0 版本即可解决问题。

You tried with x-field-extra-annotation, but that is for field only.您尝试使用 x-field-extra-annotation,但这仅适用于字段。 If you want to add it on the class level, you can use x-class-extra-annotation.如果想在class层添加,可以使用x-class-extra-annotation。 Example:例子:

ArticlesDto:
  x-class-extra-annotation: '@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)'
  type: object
  properties:
    articles:
      type: array
      items:
        $ref: '#/components/schemas/ArticleDto'
      description: 'list of articles'
    pageable:
      $ref: '#/components/schemas/PageRequestDto'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM