Skip to content

Commit 7eb5d5e

Browse files
committed
fix spring default value
1 parent 8114f96 commit 7eb5d5e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
9696
{{#openApiNullable}}
9797
{{^required}}
9898
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
99-
this.{{name}} = {{#isNullable}}JsonNullable.of({{{defaultValue}}}){{/isNullable}}{{^isNullable}}{{{defaultValue}}}{{/isNullable}};
99+
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}};
100100
}
101101
{{/required}}
102102
this.{{name}}{{#isNullable}}.get(){{/isNullable}}.add({{name}}Item);
@@ -115,7 +115,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
115115
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
116116
{{^required}}
117117
if (this.{{name}} == null) {
118-
this.{{name}} = {{{defaultValue}}};
118+
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}};
119119
}
120120
{{/required}}
121121
this.{{name}}.put(key, {{name}}Item);

samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/model/ObjectWithUniqueItems.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ObjectWithUniqueItems nullSet(Set<String> nullSet) {
6262

6363
public ObjectWithUniqueItems addNullSetItem(String nullSetItem) {
6464
if (this.nullSet == null || !this.nullSet.isPresent()) {
65-
this.nullSet = JsonNullable.of(null);
65+
this.nullSet = JsonNullable.of(new LinkedHashSet<>());
6666
}
6767
this.nullSet.get().add(nullSetItem);
6868
return this;
@@ -117,7 +117,7 @@ public ObjectWithUniqueItems nullList(List<String> nullList) {
117117

118118
public ObjectWithUniqueItems addNullListItem(String nullListItem) {
119119
if (this.nullList == null || !this.nullList.isPresent()) {
120-
this.nullList = JsonNullable.of(null);
120+
this.nullList = JsonNullable.of(new ArrayList<>());
121121
}
122122
this.nullList.get().add(nullListItem);
123123
return this;

0 commit comments

Comments
 (0)