繁体   English   中英

将 lombok(或任何)注释添加到 swagger 生成的 class

[英]Add lombok (or any) annotation to swagger generated class

我搜索了互联网,但没有找到任何解决这个问题的方法。 是否可以在 swagger class UPON 生成中添加 lombok 注释?

我有这个 swagger 模式:

Product:
type: "object"
required:
  - idSeller
  - model
  - name
  - description
  - price
properties:
  id:
    type: string
  idSeller:
    type: string
  model:
    type: string
  name:
    type: string
  description:
    type: string
  price:
    type: number
    format: currency
    minimum: 0.01

生成了以下代码:

@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-18T20:36:31.834-03:00")

public class Product   {
    @JsonProperty("id")
    private String id = null;

    @JsonProperty("idSeller")
    private String idSeller = null;

    //rest of the code ommited
} 

但我需要它来生成这个:

@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-18T20:36:31.834-03:00")

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Product   {
    @JsonProperty("id")
    private String id = null;

    @JsonProperty("idSeller")
    private String idSeller = null;

    //rest of the code ommited
}

使用 lombok Data、Builder、NoArgsConstructor 和 AllArgsConstructor 注释。

你能帮我解决这个问题吗?

关于什么

perl -pi -e 's/(?=^public class )/\@Data\n\@Builder\n\@NoArgsConstructor\n\@AllArgsConstructor\n/' *.java

? 我想,这不是您所期望的,但您可以将其集成到您的构建过程中并拥有一个经得起时间考验的解决方案。

实际上,您也需要导入,但这同样简单。

暂无
暂无

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

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