fixes(spring) add JsonProperty on setter#22978
fixes(spring) add JsonProperty on setter#22978antechrestos wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
81ab5b7 to
e397869
Compare
|
@cubic-dev-ai rerun a review |
@antechrestos I have started the AI code review. It will take a few minutes to complete. |
|
@wing328 here's the fix I was waiting to push after the merge of #22854 As suggested in the issue #22757 , I applied the fix that already is present on java side; also, I used partial so as not to repeat myself. There are tons of modified files yet difference consist in thee diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache
new file mode 100644
index 00000000000..0668f40785c
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache
@@ -0,0 +1,7 @@
+ @JsonProperty("{{baseName}}")
+{{#withXml}}
+ @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+ {{#isContainer}}
+ @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
+ {{/isContainer}}
+{{/withXml}}
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
index 82a0a6eb00c..8a93fb054f1 100644
--- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
@@ -226,25 +226,10 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{#swagger1AnnotationLibrary}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}")
{{/swagger1AnnotationLibrary}}
- {{#jackson}}
- @JsonProperty("{{baseName}}")
- {{#withXml}}
- @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
- {{#isContainer}}
- @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
- {{/isContainer}}
- {{/withXml}}
- {{/jackson}}
- {{#withXml}}
- @Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
- {{#isXmlWrapped}}
- @XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
- {{/isXmlWrapped}}
- {{/withXml}}
{{#deprecated}}
@Deprecated
{{/deprecated}}
- public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
+{{#jackson}}{{>jackson_annotations}}{{/jackson}}{{#withXml}}{{>xmlAccessorAnnotation}}{{/withXml}} public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
return {{name}};
}
{{/lombok.Getter}}
@@ -261,7 +246,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{#deprecated}}
@Deprecated
{{/deprecated}}
- public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
+{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{>jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
this.{{name}} = {{name}};
}
{{/lombok.Setter}}
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache
new file mode 100644
index 00000000000..ee5195c0eb5
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache
@@ -0,0 +1,4 @@
+ @Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+{{#isXmlWrapped}}
+ @XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+{{/isXmlWrapped}} |
|
Thanks for the PR cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) |
e397869 to
21562c7
Compare
* extract jacksonAnnotation partial template * extract xmkAccessorAnnotation partial template * apply jacksonAnnotation partial template on both getter and setter Fixes OpenAPITools#22757
21562c7 to
c00186a
Compare
|
@wing328 I was wondering why previous run of Sample Java Spring were not launched. When taking a look at the action page, I saw that it was only launched on release 😨 To cap it all, one of the path was wrong. To fix it, I made the following fixes and now job are launched. |
In order to fix #22757, I applied same logic used on java side by #9041
jacksonAnnotationpartial templatexmlAccessorAnnotationpartial templatejacksonAnnotationandxmlAccessorAnnotationpartial templates on both getter and setterSummary by cubic
Add @JsonProperty to generated Java Spring model setters so Jackson maps JSON names correctly during deserialization, skipping JsonNullable/Optional fields. Regenerated Spring samples to reflect the change and cover special property names (fixes #22757).
Bug Fixes
Refactors
Written for commit c00186a. Summary will update on new commits.