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

Add optional builder pattern to OpenAPI mustache POJO template #508

Merged
merged 28 commits into from
Jul 30, 2024

Conversation

newtork
Copy link
Contributor

@newtork newtork commented Jul 24, 2024

Some improvements on the POJO classes generated for OpenAPI specifications.

  • @Nonnull and @Nullable on fields. We already had them on the regular accessors.
  • Enable (step) builder pattern.
    • Optional, disabled by default.
    • Configurable via <additionalProperties>, e.g. to match Lombok style:
      • <pojoBuilderMethodName>builder</pojoBuilderMethodName> (when empty -> disabled)
      • <pojoBuildMethodName>build</pojoBuilderMethodName> (when empty -> implicit instantiation)
      • <pojoConstructorVisibility>public</pojoConstructorVisibility> (when empty -> no explicit constructor)

For AI project we consider to use

  • builderMethodName="create"
  • buildMethodName=""
  • pojoConstructorVisibility="protected"

(I couldn't find an easy way to omit empty lines being added. It seems to be a side effect of {{>pojoBuilder}})

@newtork newtork marked this pull request as draft July 24, 2024 15:31
@newtork newtork added do not merge Pull request must not be merged please review Request to review a pull request labels Jul 25, 2024
@newtork newtork changed the title Add @Nonnull / @Nullable annotation to OpenAPI generated model classes Add (and enforce) optional builder pattern to OpenAPI mustache POJO template Jul 25, 2024
@newtork newtork changed the title Add (and enforce) optional builder pattern to OpenAPI mustache POJO template Add optional builder pattern to OpenAPI mustache POJO template Jul 25, 2024
@newtork newtork marked this pull request as ready for review July 26, 2024 15:40
@newtork newtork added please merge Request to merge a pull request and removed do not merge Pull request must not be merged labels Jul 26, 2024
Copy link
Contributor

@CharlesDuboisSAP CharlesDuboisSAP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters of type List don't have a builder interface and are missing in create(). You should add a test for List types.

@CharlesDuboisSAP CharlesDuboisSAP removed their assignment Jul 29, 2024
Comment on lines +341 to +356
/**
* Set the flavors of this {@link Soda} instance.
*
* @param flavors The flavors of this {@link Soda}
* @return The Soda builder.
*/
Builder3 flavors( @Nonnull final List<String> flavors);
/**
* Set the flavors of this {@link Soda} instance.
*
* @param flavors The flavors of this {@link Soda}
* @return The Soda builder.
*/
default Builder3 flavors( @Nonnull final String... flavors) {
return flavors(Arrays.asList(flavors));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CharlesDuboisSAP here I added a test case for builder feature. We do longer need to rely on the sample module.

@newtork newtork dismissed CharlesDuboisSAP’s stale review July 29, 2024 20:52

Addressed review comments

@newtork newtork merged commit e162af6 into main Jul 30, 2024
14 checks passed
@newtork newtork deleted the annotation-openapi-generator branch July 30, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please merge Request to merge a pull request please review Request to review a pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants