-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
@Nonnull
/ @Nullable
annotation to OpenAPI generated model classes…to annotation-openapi-generator
There was a problem hiding this 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.
...ain/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java
Outdated
Show resolved
Hide resolved
...ain/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java
Outdated
Show resolved
Hide resolved
...napi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache
Outdated
Show resolved
Hide resolved
...enapi-generator/src/main/resources/openapi-generator/mustache-templates/pojoBuilder.mustache
Outdated
Show resolved
Hide resolved
/** | ||
* 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)); | ||
} |
There was a problem hiding this comment.
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.
Some improvements on the POJO classes generated for OpenAPI specifications.
@Nonnull
and@Nullable
on fields. We already had them on the regular accessors.<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}}
)