简体   繁体   English

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

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

I scavenged the internet but didn't find anything to solve this problem.我搜索了互联网,但没有找到任何解决这个问题的方法。 Is it possible to add the lombok annotations in a swagger class UPON generation?是否可以在 swagger class UPON 生成中添加 lombok 注释?

I have this swagger schema:我有这个 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

Which generated this code:生成了以下代码:

@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
} 

But I need it to generate this:但我需要它来生成这个:

@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
}

With the lombok Data, Builder, NoArgsConstructor and AllArgsConstructor annotations.使用 lombok Data、Builder、NoArgsConstructor 和 AllArgsConstructor 注释。

Could you help me on this?你能帮我解决这个问题吗?

What about关于什么

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

? ? I guess, that's not what you expected, but you can integrate it into your build process and have a time-proof solution.我想,这不是您所期望的,但您可以将其集成到您的构建过程中并拥有一个经得起时间考验的解决方案。

Actually, you'll need the imports, too, but that's equally simple.实际上,您也需要导入,但这同样简单。

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

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