OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

[BUG][SPRING] Lombok Builder doesn't preserve default values #18689

Open levitin opened 1 month ago

levitin commented 1 month ago

Bug Report Checklist

Description

Adding Lombok Builder, as explained in this comment is working fine. However, there's a problem with default values. When utilizing Lombok Builder, the default values specified in the model classes aren't retained; instead, they're being set to null.

This problem can be resolved by leveraging Lombok's @Builder.Default annotation, which allows us to specify default values for fields within the builder pattern. More details about this annotation can be found here.

Related issues/PRs
Input
openapi: "3.0.3"
...
components:
  schemas:
    MyObject:
      type: object
      properties:
        propertyWithDefaultValue:
          type: integer
          format: int32
          default: 20
        simpleProperty:
          type: integer
          format: int32
...
<configuration>
    ...
   <configOptions>
      ...
      <additionalModelTypeAnnotations>@lombok.Builder</additionalModelTypeAnnotations>
      ...
   </configOptions>
   ...
</configuration>
Current output
@lombok.Builder
public class MyObject {
  ...

  private Integer propertyWithDefaultValue = 20;

  private Integer simpleProperty;

  ...
}
Expected output
@lombok.Builder
public class MyObject {
  ...

+ @lombok.Builder.Default
  private Integer propertyWithDefaultValue = 20;

  private Integer simpleProperty;

  ...
}
Degooya commented 3 days ago

Any progress for this issue?