OpenAPI generator:configure lombok with Builder/Builder.Default
Asked Answered
V

1

4

I am using openapi generator (5.4.0) with gradle.

It is configured with spring generator name, and added lombok configOptions.

additionalModelTypeAnnotations : "@lombok.Builder; @lombok.NoArgsConstructor;@lombok.AllArgsConstructor;"

As some fields are nullable, I get a compile warning:

 warning: @Builder will ignore the initializing expression entirely. 
If you want the initializing expression to serve as default, 
add @Builder.Default.

Is there anyway to rectify this without adding @Builder.Default to the mustache pojo template?

Thanks, B

Valais answered 20/5, 2022 at 15:12 Comment(1)
#47884431 according to this comment, move the @Builder annotation to constructer level. The core issue is still being addressed github.com/projectlombok/lombok/issues/2340Variegation
S
0

You can try to add

x-field-extra-annotation: "@lombok.Builder.Default"

to your OpenAPI object spec definition see: https://openapi-generator.tech/docs/generators/spring/

example:

components:
  schemas:
    MyObject:
      type: object
      properties: 
        myCollection:
          type: array
          x-field-extra-annotation: "@lombok.Builder.Default"
          items: 
            $ref: '#/components/schemas/MyCollectionElement' 
Smoot answered 10/9 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.