Ensures a JsonCreator annotated constructor is present if there are required fields, ensure the getters and setters are properly annotated for jaxrs-spec generator.#19578
Conversation
| @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}} | ||
| @org.eclipse.microprofile.openapi.annotations.media.Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useMicroProfileOpenAPIAnnotations}} | ||
| @JsonProperty("{{baseName}}") | ||
| @JsonProperty({{#required}}required = {{required}}, {{/required}}value = "{{baseName}}") |
There was a problem hiding this comment.
Moving the close of the required check could eliminate adding value in case where it is redundant.
| @JsonProperty({{#required}}required = {{required}}, {{/required}}value = "{{baseName}}") | |
| @JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}") |
There was a problem hiding this comment.
Would also significantly shrink the changeset of this PR 😄
There was a problem hiding this comment.
Thanks for the review!
Doing as you suggested is indeed better, diff is "only" 64 files modified now 😃
(Had to change a bit more than your suggestion to get rid of an unwanted line break)
There was a problem hiding this comment.
Something is not right, in case #required but no #generateBuilders, we wouldn't get an empty constructor and this could break some existing code.
I updated the PR to always generate an empty constructor without any condition, so diff is less small 🥲
a1b84a5 to
e1898e0
Compare
…equired fields, and ensure the getters and setters are properly annotated with required=true / required=false for jaxrs-spec generator.
e1898e0 to
a13ff51
Compare
| } | ||
| {{/additionalProperties}} | ||
| {{/generateBuilders}} | ||
| public {{classname}}() { |
There was a problem hiding this comment.
I'm not familiar with the JavaJaxRS code, but should this have a ^hasRequired around it? Or are both constructors valid?
There was a problem hiding this comment.
We need a default constructor for cases where there is a constructor with arguments in order not to break existing code.
This can happen with hasRequired (new case) or with generateBuilders (existing case), but as far as I know it is not possible to do a OR in mustache.
So I took the simple route and put the default constructor unconditionally, thinking that if in the future a new case with another constructor with arguments arises, it will not be forgotten.
See my comment here #19578 (comment)
|
I think I answered all the remarks, is there something else to do on my side? |
|
@kevinferrare thanks for the PR. Let's give it a try |
Fixes #19577
Actual change is modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache
Other files diff is the result of updating the samples
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)@chameleon82 @wing328 @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @cachescrubber @welshm @MelleD @borsch