Skip to content

Commit 942ec96

Browse files
committed
fixes(spring) add JsonProperty on setter
* extract jacksonAnnotation partial template * extract xmkAccessorAnnotation partial template * apply jacksonAnnotation partial template on both getter and setter Fixes #22757
1 parent b1022e7 commit 942ec96

File tree

1,343 files changed

+4756
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,343 files changed

+4756
-92
lines changed

.github/workflows/samples-spring-jdk17.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ name: Samples Java Spring (JDK17)
33
on:
44
push:
55
paths:
6-
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
7-
- samples/openapi3/client/petstore/spring-cloud-4-with-optional
8-
- samples/client/petstore/spring-http-interface-springboot-4
9-
- samples/openapi3/server/petstore/springboot-3
10-
- samples/openapi3/server/petstore/springboot-4
11-
- samples/server/petstore/springboot-api-response-examples
12-
- samples/server/petstore/springboot-lombok-data
13-
- samples/server/petstore/springboot-lombok-tostring
14-
- samples/server/petstore/springboot-file-delegate-optional
15-
- samples/server/petstore/springboot-petstore-with-api-response-examples
16-
- samples/server/petstore/spring-boot-oneof-sealed
17-
- samples/openapi3/server/petstore/spring-boot-oneof-interface
6+
- samples/openapi3/client/petstore/spring-cloud-3-with-optional/**
7+
- samples/openapi3/client/petstore/spring-cloud-4-with-optional/**
8+
- samples/client/petstore/spring-http-interface-springboot-4/**
9+
- samples/openapi3/server/petstore/springboot-3/**
10+
- samples/openapi3/server/petstore/springboot-4/**
11+
- samples/server/petstore/springboot-api-response-examples/**
12+
- samples/server/petstore/springboot-lombok-data/**
13+
- samples/server/petstore/springboot-lombok-tostring/**
14+
- samples/server/petstore/springboot-file-delegate-optional/**
15+
- samples/server/petstore/springboot-petstore-with-api-response-examples/**
16+
- samples/openapi3/server/petstore/spring-boot-oneof-sealed/
17+
- samples/openapi3/server/petstore/spring-boot-oneof-interface/**
1818
pull_request:
1919
paths:
20-
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
21-
- samples/openapi3/client/petstore/spring-cloud-4-with-optional
22-
- samples/client/petstore/spring-http-interface-springboot-4
23-
- samples/openapi3/server/petstore/springboot-3
24-
- samples/openapi3/server/petstore/springboot-4
25-
- samples/server/petstore/springboot-api-response-examples
26-
- samples/server/petstore/springboot-lombok-data
27-
- samples/server/petstore/springboot-lombok-tostring
28-
- samples/server/petstore/springboot-file-delegate-optional
29-
- samples/server/petstore/springboot-petstore-with-api-response-examples
30-
- samples/server/petstore/spring-boot-oneof-sealed
31-
- samples/openapi3/server/petstore/spring-boot-oneof-interface
20+
- samples/openapi3/client/petstore/spring-cloud-3-with-optional/**
21+
- samples/openapi3/client/petstore/spring-cloud-4-with-optional/**
22+
- samples/client/petstore/spring-http-interface-springboot-4/**
23+
- samples/openapi3/server/petstore/springboot-3/**
24+
- samples/openapi3/server/petstore/springboot-4/**
25+
- samples/server/petstore/springboot-api-response-examples/**
26+
- samples/server/petstore/springboot-lombok-data/**
27+
- samples/server/petstore/springboot-lombok-tostring/**
28+
- samples/server/petstore/springboot-file-delegate-optional/**
29+
- samples/server/petstore/springboot-petstore-with-api-response-examples/**
30+
- samples/openapi3/server/petstore/spring-boot-oneof-sealed/**
31+
- samples/openapi3/server/petstore/spring-boot-oneof-interface/**
3232
jobs:
3333
build:
3434
name: Build Java Spring (JDK17)
@@ -49,7 +49,7 @@ jobs:
4949
- samples/server/petstore/springboot-lombok-tostring
5050
- samples/server/petstore/springboot-file-delegate-optional
5151
- samples/server/petstore/springboot-petstore-with-api-response-examples
52-
- samples/server/petstore/spring-boot-oneof-sealed
52+
- samples/openapi3/server/petstore/spring-boot-oneof-sealed
5353
- samples/openapi3/server/petstore/spring-boot-oneof-interface
5454
steps:
5555
- uses: actions/checkout@v5
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@JsonProperty("{{baseName}}")
2+
{{#withXml}}
3+
@JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
4+
{{#isContainer}}
5+
@JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
6+
{{/isContainer}}
7+
{{/withXml}}

modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@
2323
{{#swagger2AnnotationLibrary}}
2424
@Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}})
2525
{{/swagger2AnnotationLibrary}}
26-
{{#jackson}}@JsonProperty("{{baseName}}")
27-
{{#withXml}}
28-
@JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
29-
{{#isContainer}}
30-
@JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
31-
{{/isContainer}}
32-
{{/withXml}}
33-
{{/jackson}}
26+
{{#jackson}}{{>jackson_annotations}}{{/jackson}}
3427
{{/lombok.Data}}
3528
{{#lombok.Builder}}
3629
{{#defaultValue}}

modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,10 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
226226
{{#swagger1AnnotationLibrary}}
227227
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}")
228228
{{/swagger1AnnotationLibrary}}
229-
{{#jackson}}
230-
@JsonProperty("{{baseName}}")
231-
{{#withXml}}
232-
@JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
233-
{{#isContainer}}
234-
@JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
235-
{{/isContainer}}
236-
{{/withXml}}
237-
{{/jackson}}
238-
{{#withXml}}
239-
@Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
240-
{{#isXmlWrapped}}
241-
@XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
242-
{{/isXmlWrapped}}
243-
{{/withXml}}
244229
{{#deprecated}}
245230
@Deprecated
246231
{{/deprecated}}
247-
public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
232+
{{#jackson}}{{>jackson_annotations}}{{/jackson}}{{#withXml}}{{>xmlAccessorAnnotation}}{{/withXml}} public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
248233
return {{name}};
249234
}
250235
{{/lombok.Getter}}
@@ -261,7 +246,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
261246
{{#deprecated}}
262247
@Deprecated
263248
{{/deprecated}}
264-
public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
249+
{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{>jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
265250
this.{{name}} = {{name}};
266251
}
267252
{{/lombok.Setter}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
2+
{{#isXmlWrapped}}
3+
@XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
4+
{{/isXmlWrapped}}

samples/client/petstore/spring-cloud-date-time/src/main/java/org/openapitools/model/Pet.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public String getAtType() {
6868
return atType;
6969
}
7070

71+
@JsonProperty("@type")
7172
public void setAtType(String atType) {
7273
this.atType = atType;
7374
}
@@ -88,6 +89,7 @@ public Integer getAge() {
8889
return age;
8990
}
9091

92+
@JsonProperty("age")
9193
public void setAge(Integer age) {
9294
this.age = age;
9395
}
@@ -108,6 +110,7 @@ public Boolean getHappy() {
108110
return happy;
109111
}
110112

113+
@JsonProperty("happy")
111114
public void setHappy(Boolean happy) {
112115
this.happy = happy;
113116
}
@@ -128,6 +131,7 @@ public BigDecimal getPrice() {
128131
return price;
129132
}
130133

134+
@JsonProperty("price")
131135
public void setPrice(BigDecimal price) {
132136
this.price = price;
133137
}
@@ -148,6 +152,7 @@ public OffsetDateTime getLastFeed() {
148152
return lastFeed;
149153
}
150154

155+
@JsonProperty("lastFeed")
151156
public void setLastFeed(OffsetDateTime lastFeed) {
152157
this.lastFeed = lastFeed;
153158
}
@@ -168,6 +173,7 @@ public LocalDate getDateOfBirth() {
168173
return dateOfBirth;
169174
}
170175

176+
@JsonProperty("dateOfBirth")
171177
public void setDateOfBirth(LocalDate dateOfBirth) {
172178
this.dateOfBirth = dateOfBirth;
173179
}

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/Category.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public Category id(@Nullable Long id) {
4343
return id;
4444
}
4545

46+
@JsonProperty("id")
4647
public void setId(@Nullable Long id) {
4748
this.id = id;
4849
}
@@ -63,6 +64,7 @@ public Category name(@Nullable String name) {
6364
return name;
6465
}
6566

67+
@JsonProperty("name")
6668
public void setName(@Nullable String name) {
6769
this.name = name;
6870
}

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/ModelApiResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public ModelApiResponse code(@Nullable Integer code) {
4747
return code;
4848
}
4949

50+
@JsonProperty("code")
5051
public void setCode(@Nullable Integer code) {
5152
this.code = code;
5253
}
@@ -67,6 +68,7 @@ public ModelApiResponse type(@Nullable String type) {
6768
return type;
6869
}
6970

71+
@JsonProperty("type")
7072
public void setType(@Nullable String type) {
7173
this.type = type;
7274
}
@@ -87,6 +89,7 @@ public ModelApiResponse message(@Nullable String message) {
8789
return message;
8890
}
8991

92+
@JsonProperty("message")
9093
public void setMessage(@Nullable String message) {
9194
this.message = message;
9295
}

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/Order.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public Order id(@Nullable Long id) {
9494
return id;
9595
}
9696

97+
@JsonProperty("id")
9798
public void setId(@Nullable Long id) {
9899
this.id = id;
99100
}
@@ -114,6 +115,7 @@ public Order petId(@Nullable Long petId) {
114115
return petId;
115116
}
116117

118+
@JsonProperty("petId")
117119
public void setPetId(@Nullable Long petId) {
118120
this.petId = petId;
119121
}
@@ -134,6 +136,7 @@ public Order quantity(@Nullable Integer quantity) {
134136
return quantity;
135137
}
136138

139+
@JsonProperty("quantity")
137140
public void setQuantity(@Nullable Integer quantity) {
138141
this.quantity = quantity;
139142
}
@@ -154,6 +157,7 @@ public Order shipDate(@Nullable OffsetDateTime shipDate) {
154157
return shipDate;
155158
}
156159

160+
@JsonProperty("shipDate")
157161
public void setShipDate(@Nullable OffsetDateTime shipDate) {
158162
this.shipDate = shipDate;
159163
}
@@ -174,6 +178,7 @@ public Order status(@Nullable StatusEnum status) {
174178
return status;
175179
}
176180

181+
@JsonProperty("status")
177182
public void setStatus(@Nullable StatusEnum status) {
178183
this.status = status;
179184
}
@@ -194,6 +199,7 @@ public Boolean getComplete() {
194199
return complete;
195200
}
196201

202+
@JsonProperty("complete")
197203
public void setComplete(Boolean complete) {
198204
this.complete = complete;
199205
}

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/Pet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public Pet id(@Nullable Long id) {
109109
return id;
110110
}
111111

112+
@JsonProperty("id")
112113
public void setId(@Nullable Long id) {
113114
this.id = id;
114115
}
@@ -129,6 +130,7 @@ public Pet category(@Nullable Category category) {
129130
return category;
130131
}
131132

133+
@JsonProperty("category")
132134
public void setCategory(@Nullable Category category) {
133135
this.category = category;
134136
}
@@ -149,6 +151,7 @@ public JsonNullable<String> getName() {
149151
return name;
150152
}
151153

154+
@JsonProperty("name")
152155
public void setName(JsonNullable<String> name) {
153156
this.name = name;
154157
}
@@ -173,8 +176,8 @@ public Pet addPhotoUrlsItem(String photoUrlsItem) {
173176
*/
174177
@NotNull
175178
@Schema(name = "photoUrls", deprecated = true, requiredMode = Schema.RequiredMode.REQUIRED)
176-
@JsonProperty("photoUrls")
177179
@Deprecated
180+
@JsonProperty("photoUrls")
178181
public List<String> getPhotoUrls() {
179182
return photoUrls;
180183
}
@@ -183,6 +186,7 @@ public List<String> getPhotoUrls() {
183186
* @deprecated
184187
*/
185188
@Deprecated
189+
@JsonProperty("photoUrls")
186190
public void setPhotoUrls(List<String> photoUrls) {
187191
this.photoUrls = photoUrls;
188192
}
@@ -211,6 +215,7 @@ public Pet addTagsItem(Tag tagsItem) {
211215
return tags;
212216
}
213217

218+
@JsonProperty("tags")
214219
public void setTags(List<@Valid Tag> tags) {
215220
this.tags = tags;
216221
}
@@ -231,6 +236,7 @@ public Pet status(@Nullable StatusEnum status) {
231236
return status;
232237
}
233238

239+
@JsonProperty("status")
234240
public void setStatus(@Nullable StatusEnum status) {
235241
this.status = status;
236242
}

0 commit comments

Comments
 (0)