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

Van*_*sis 5 java lombok spring-boot swagger-2.0

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

我有这个招摇的模式:

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
Run Code Online (Sandbox Code Playgroud)

生成了这段代码:

@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
} 
Run Code Online (Sandbox Code Playgroud)

但我需要它来生成这个:

@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
}
Run Code Online (Sandbox Code Playgroud)

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

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

maa*_*nus 1

关于什么

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

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

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