Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
levitin opened this issue May 16, 2024 · 0 comments
Open
3 tasks done

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

levitin opened this issue May 16, 2024 · 0 comments

Comments

@levitin
Copy link

levitin commented May 16, 2024

Bug Report Checklist

  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
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;

  ...
}
levitin pushed a commit to levitin/openapi-generator that referenced this issue May 16, 2024
levitin pushed a commit to levitin/openapi-generator that referenced this issue May 21, 2024
levitin pushed a commit to levitin/openapi-generator that referenced this issue May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant