Skip to content

Commit fb74567

Browse files
fix: add @nullable annotation to fluent setter parameters when useJspecify is enabled
The Spring generator was missing @nullable annotations on fluent setter parameters when useJspecify is enabled, while regular setters and getters had them correctly applied. This created an inconsistent nullness contract that caused static analysis tools to flag passing null to fluent setters as errors, even though the underlying field is nullable. Changes: - Updated JavaSpring/pojo.mustache to use {{>nullableDataType}} instead of {{{datatypeWithEnum}}} for fluent setter parameters - Applied the same fix to inherited property fluent setters - Updated java-camel-server/pojo.mustache with the same fix (extends SpringCodegen) This ensures consistent nullness annotations across: - Fields: private @nullable String firstName; - Getters: public @nullable String getFirstName() - Regular setters: public void setFirstName(@nullable String firstName) - Fluent setters: public UserBase firstName(@nullable String firstName)
1 parent eb2767c commit fb74567

200 files changed

Lines changed: 451 additions & 451 deletions

File tree

Some content is hidden

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
144144
{{^lombok.Data}}
145145

146146
{{! begin feature: fluent setter methods }}
147-
public {{classname}} {{name}}({{>nullableAnnotation}}{{{datatypeWithEnum}}} {{name}}) {
147+
public {{classname}} {{name}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
148148
{{#openApiNullable}}
149149
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of{{#optionalAcceptNullable}}Nullable{{/optionalAcceptNullable}}({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
150150
{{/openApiNullable}}
@@ -260,7 +260,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
260260

261261
{{^lombok.Setter}}
262262
{{! begin feature: fluent setter methods for inherited properties }}
263-
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
263+
public {{classname}} {{name}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
264264
super.{{name}}({{name}});
265265
return this;
266266
}

modules/openapi-generator/src/main/resources/java-camel-server/pojo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
155155
{{^lombok.Data}}
156156

157157
{{! begin feature: fluent setter methods }}
158-
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
158+
public {{classname}} {{name}}({{>nullableDataType}} {{name}}) {
159159
{{#openApiNullable}}
160160
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
161161
{{/openApiNullable}}
@@ -280,7 +280,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
280280

281281
{{^lombok.Setter}}
282282
{{! begin feature: fluent setter methods for inherited properties }}
283-
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
283+
public {{classname}} {{name}}({{>nullableDataType}} {{name}}) {
284284
super.{{name}}({{name}});
285285
return this;
286286
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void setCategory(@Nullable Category category) {
135135
this.category = category;
136136
}
137137

138-
public Pet name(String name) {
138+
public Pet name(JsonNullable<String> name) {
139139
this.name = JsonNullable.of(name);
140140
return this;
141141
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/AdditionalPropertiesClassDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void setAnytype1(@Nullable Object anytype1) {
303303
this.anytype1 = anytype1;
304304
}
305305

306-
public AdditionalPropertiesClassDto anytype2(Object anytype2) {
306+
public AdditionalPropertiesClassDto anytype2(JsonNullable<Object> anytype2) {
307307
this.anytype2 = JsonNullable.of(anytype2);
308308
return this;
309309
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/BigCatDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void setKind(@Nullable KindEnum kind) {
9494
}
9595

9696

97-
public BigCatDto declawed(Boolean declawed) {
97+
public BigCatDto declawed(@Nullable Boolean declawed) {
9898
super.declawed(declawed);
9999
return this;
100100
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ChildWithNullableDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public void setOtherProperty(@Nullable String otherProperty) {
5353
}
5454

5555

56-
public ChildWithNullableDto type(TypeEnum type) {
56+
public ChildWithNullableDto type(@Nullable TypeEnum type) {
5757
super.type(type);
5858
return this;
5959
}
6060

61-
public ChildWithNullableDto nullableProperty(String nullableProperty) {
61+
public ChildWithNullableDto nullableProperty(JsonNullable<String> nullableProperty) {
6262
super.nullableProperty(nullableProperty);
6363
return this;
6464
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ContainerDefaultValueDto() {
4343
super();
4444
}
4545

46-
public ContainerDefaultValueDto nullableArray(List<String> nullableArray) {
46+
public ContainerDefaultValueDto nullableArray(JsonNullable<List<String>> nullableArray) {
4747
this.nullableArray = JsonNullable.of(nullableArray);
4848
return this;
4949
}
@@ -70,7 +70,7 @@ public void setNullableArray(JsonNullable<List<String>> nullableArray) {
7070
this.nullableArray = nullableArray;
7171
}
7272

73-
public ContainerDefaultValueDto nullableRequiredArray(List<String> nullableRequiredArray) {
73+
public ContainerDefaultValueDto nullableRequiredArray(JsonNullable<List<String>> nullableRequiredArray) {
7474
this.nullableRequiredArray = JsonNullable.of(nullableRequiredArray);
7575
return this;
7676
}
@@ -126,7 +126,7 @@ public void setRequiredArray(List<String> requiredArray) {
126126
this.requiredArray = requiredArray;
127127
}
128128

129-
public ContainerDefaultValueDto nullableArrayWithDefault(List<String> nullableArrayWithDefault) {
129+
public ContainerDefaultValueDto nullableArrayWithDefault(JsonNullable<List<String>> nullableArrayWithDefault) {
130130
this.nullableArrayWithDefault = JsonNullable.of(nullableArrayWithDefault);
131131
return this;
132132
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/NullableMapPropertyDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class NullableMapPropertyDto {
3030

3131
private JsonNullable<Map<String, String>> languageValues = JsonNullable.<Map<String, String>>undefined();
3232

33-
public NullableMapPropertyDto languageValues(Map<String, String> languageValues) {
33+
public NullableMapPropertyDto languageValues(JsonNullable<Map<String, String>> languageValues) {
3434
this.languageValues = JsonNullable.of(languageValues);
3535
return this;
3636
}

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ParentWithNullableDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void setType(@Nullable TypeEnum type) {
9494
this.type = type;
9595
}
9696

97-
public ParentWithNullableDto nullableProperty(String nullableProperty) {
97+
public ParentWithNullableDto nullableProperty(JsonNullable<String> nullableProperty) {
9898
this.nullableProperty = JsonNullable.of(nullableProperty);
9999
return this;
100100
}

samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void setAnytype1(@Nullable Object anytype1) {
301301
this.anytype1 = anytype1;
302302
}
303303

304-
public AdditionalPropertiesClass anytype2(Object anytype2) {
304+
public AdditionalPropertiesClass anytype2(JsonNullable<Object> anytype2) {
305305
this.anytype2 = JsonNullable.of(anytype2);
306306
return this;
307307
}

0 commit comments

Comments
 (0)