Java 向swagger生成的类添加lombok(或任何)注释

Java 向swagger生成的类添加lombok(或任何)注释,java,spring-boot,swagger-2.0,lombok,Java,Spring Boot,Swagger 2.0,Lombok,我搜索了一下互联网,但没有找到任何解决这个问题的方法。 是否可以在生成时在swagger类中添加lombok注释 我有一个招摇过市的模式: Product: type: "object" required: - idSeller - model - name - description - price properties: id: type: string idSeller: type: string model: type: strin

我搜索了一下互联网,但没有找到任何解决这个问题的方法。 是否可以在生成时在swagger类中添加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
生成此代码的代码:

@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数据、生成器、NoArgsConstructor和AllArgsConstructor注释

你能帮我一下吗?

怎么样

perl -pi -e 's/(?=^public class )/\@Data\n\@Builder\n\@NoArgsConstructor\n\@AllArgsConstructor\n/' *.java
??我想,这并不是您所期望的,但您可以将其集成到构建过程中,并获得一个经得起时间考验的解决方案


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

我建议使用一个实际的java文件解析器,它适用于所有版本的javafar@smac89当然,你的解决方案更干净。。。。我的工作很大程度上取决于知道文件的外观。我使用perl处理一些琐碎的任务,到目前为止已经足够好了。当有更大的事情发生时,我也会使用一个合适的解析器。如果你使用一个允许它的构建工具,你可以编写一个简单的插件来读取你生成的文件并向它们添加注释。我可以看到gradle很容易做到这一点