Skip to content

Commit 4e39fad

Browse files
fix more cubic-dev-ai findings, includes a solution for missing jackson-databind-nullable
1 parent caca305 commit 4e39fad

11 files changed

Lines changed: 161 additions & 444 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ public void processOpts() {
458458
convertPropertyToBooleanAndWriteBack(FAIL_ON_UNKNOWN_PROPERTIES, this::setFailOnUnknownProperties);
459459
convertPropertyToBooleanAndWriteBack(SUPPORT_VERTX_FUTURE, this::setSupportVertxFuture);
460460
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
461+
if (useJackson3 && openApiNullable) {
462+
LOGGER.warn("openApiNullable is not supported with useJackson3=true (jackson-databind-nullable has no Jackson 3 release). Disabling openApiNullable.");
463+
openApiNullable = false;
464+
additionalProperties.put(OPENAPI_NULLABLE, false);
465+
}
461466

462467
// add URL query deepObject support to native, apache-httpclient by default
463468
if (!additionalProperties.containsKey(SUPPORT_URL_QUERY)) {

modules/openapi-generator/src/main/resources/Java/libraries/native/README.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
Building the API client library requires:
2424

25-
1. Java 11+
25+
{{^useJackson3}}1. Java 11+{{/useJackson3}}{{#useJackson3}}1. Java 17+{{/useJackson3}}
2626
2. Maven/Gradle
2727

2828
## Installation

modules/openapi-generator/src/main/resources/Java/libraries/native/travis.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
#
44
language: java
55
jdk:
6+
{{^useJackson3}}
67
- oraclejdk11
8+
{{/useJackson3}}
9+
{{#useJackson3}}
10+
- oraclejdk17
11+
{{/useJackson3}}
712
before_install:
813
# ensure gradlew has proper permission
914
- chmod a+x ./gradlew

samples/client/petstore/java/native-jackson3/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
language: java
55
jdk:
6-
- oraclejdk11
6+
- oraclejdk17
77
before_install:
88
# ensure gradlew has proper permission
99
- chmod a+x ./gradlew

samples/client/petstore/java/native-jackson3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
1515

1616
Building the API client library requires:
1717

18-
1. Java 11+
18+
1. Java 17+
1919
2. Maven/Gradle
2020

2121
## Installation

samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
import java.util.Arrays;
3030
import java.util.HashMap;
3131
import java.util.Map;
32-
import org.openapitools.jackson.nullable.JsonNullable;
33-
import com.fasterxml.jackson.annotation.JsonIgnore;
34-
import org.openapitools.jackson.nullable.JsonNullable;
35-
import java.util.NoSuchElementException;
3632
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
3733

3834

@@ -61,7 +57,8 @@ public class AdditionalPropertiesClass {
6157
private Map<String, Map<String, String>> mapOfMapProperty = new HashMap<>();
6258

6359
public static final String JSON_PROPERTY_ANYTYPE1 = "anytype_1";
64-
private JsonNullable<Object> anytype1 = JsonNullable.<Object>of(null);
60+
@javax.annotation.Nullable
61+
private Object anytype1 = null;
6562

6663
public static final String JSON_PROPERTY_MAP_WITH_UNDECLARED_PROPERTIES_ANYTYPE1 = "map_with_undeclared_properties_anytype_1";
6764
@javax.annotation.Nullable
@@ -151,7 +148,7 @@ public void setMapOfMapProperty(@javax.annotation.Nullable Map<String, Map<Strin
151148

152149

153150
public AdditionalPropertiesClass anytype1(@javax.annotation.Nullable Object anytype1) {
154-
this.anytype1 = JsonNullable.<Object>of(anytype1);
151+
this.anytype1 = anytype1;
155152
return this;
156153
}
157154

@@ -160,25 +157,17 @@ public AdditionalPropertiesClass anytype1(@javax.annotation.Nullable Object anyt
160157
* @return anytype1
161158
*/
162159
@javax.annotation.Nullable
163-
@JsonIgnore
164-
public Object getAnytype1() {
165-
return anytype1.orElse(null);
166-
}
167-
168160
@JsonProperty(value = JSON_PROPERTY_ANYTYPE1, required = false)
169161
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
170-
171-
public JsonNullable<Object> getAnytype1_JsonNullable() {
162+
public Object getAnytype1() {
172163
return anytype1;
173164
}
174-
175-
@JsonProperty(JSON_PROPERTY_ANYTYPE1)
176-
public void setAnytype1_JsonNullable(JsonNullable<Object> anytype1) {
177-
this.anytype1 = anytype1;
178-
}
179165

166+
167+
@JsonProperty(value = JSON_PROPERTY_ANYTYPE1, required = false)
168+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
180169
public void setAnytype1(@javax.annotation.Nullable Object anytype1) {
181-
this.anytype1 = JsonNullable.<Object>of(anytype1);
170+
this.anytype1 = anytype1;
182171
}
183172

184173

@@ -326,22 +315,11 @@ public boolean equals(Object o) {
326315
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
327316
}
328317

329-
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
330-
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
331-
}
332-
333318
@Override
334319
public int hashCode() {
335320
return HashCodeBuilder.reflectionHashCode(this);
336321
}
337322

338-
private static <T> int hashCodeNullable(JsonNullable<T> a) {
339-
if (a == null) {
340-
return 1;
341-
}
342-
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
343-
}
344-
345323
@Override
346324
public String toString() {
347325
StringBuilder sb = new StringBuilder();
@@ -481,10 +459,6 @@ public AdditionalPropertiesClass.Builder mapOfMapProperty(Map<String, Map<String
481459
return this;
482460
}
483461
public AdditionalPropertiesClass.Builder anytype1(Object anytype1) {
484-
this.instance.anytype1 = JsonNullable.<Object>of(anytype1);
485-
return this;
486-
}
487-
public AdditionalPropertiesClass.Builder anytype1(JsonNullable<Object> anytype1) {
488462
this.instance.anytype1 = anytype1;
489463
return this;
490464
}

samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Drawing.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
import org.openapitools.client.model.NullableShape;
3838
import org.openapitools.client.model.Shape;
3939
import org.openapitools.client.model.ShapeOrNull;
40-
import org.openapitools.jackson.nullable.JsonNullable;
41-
import com.fasterxml.jackson.annotation.JsonIgnore;
42-
import org.openapitools.jackson.nullable.JsonNullable;
43-
import java.util.NoSuchElementException;
4440
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4541

4642

@@ -65,7 +61,8 @@ public class Drawing {
6561
private ShapeOrNull shapeOrNull;
6662

6763
public static final String JSON_PROPERTY_NULLABLE_SHAPE = "nullableShape";
68-
private JsonNullable<NullableShape> nullableShape = JsonNullable.<NullableShape>undefined();
64+
@javax.annotation.Nullable
65+
private NullableShape nullableShape;
6966

7067
public static final String JSON_PROPERTY_SHAPES = "shapes";
7168
@javax.annotation.Nullable
@@ -123,7 +120,7 @@ public void setShapeOrNull(@javax.annotation.Nullable ShapeOrNull shapeOrNull) {
123120

124121

125122
public Drawing nullableShape(@javax.annotation.Nullable NullableShape nullableShape) {
126-
this.nullableShape = JsonNullable.<NullableShape>of(nullableShape);
123+
this.nullableShape = nullableShape;
127124
return this;
128125
}
129126

@@ -132,25 +129,17 @@ public Drawing nullableShape(@javax.annotation.Nullable NullableShape nullableSh
132129
* @return nullableShape
133130
*/
134131
@javax.annotation.Nullable
135-
@JsonIgnore
136-
public NullableShape getNullableShape() {
137-
return nullableShape.orElse(null);
138-
}
139-
140132
@JsonProperty(value = JSON_PROPERTY_NULLABLE_SHAPE, required = false)
141133
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
142-
143-
public JsonNullable<NullableShape> getNullableShape_JsonNullable() {
134+
public NullableShape getNullableShape() {
144135
return nullableShape;
145136
}
146-
147-
@JsonProperty(JSON_PROPERTY_NULLABLE_SHAPE)
148-
public void setNullableShape_JsonNullable(JsonNullable<NullableShape> nullableShape) {
149-
this.nullableShape = nullableShape;
150-
}
151137

138+
139+
@JsonProperty(value = JSON_PROPERTY_NULLABLE_SHAPE, required = false)
140+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
152141
public void setNullableShape(@javax.annotation.Nullable NullableShape nullableShape) {
153-
this.nullableShape = JsonNullable.<NullableShape>of(nullableShape);
142+
this.nullableShape = nullableShape;
154143
}
155144

156145

@@ -237,22 +226,11 @@ public boolean equals(Object o) {
237226
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
238227
}
239228

240-
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
241-
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
242-
}
243-
244229
@Override
245230
public int hashCode() {
246231
return HashCodeBuilder.reflectionHashCode(this);
247232
}
248233

249-
private static <T> int hashCodeNullable(JsonNullable<T> a) {
250-
if (a == null) {
251-
return 1;
252-
}
253-
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
254-
}
255-
256234
@Override
257235
public String toString() {
258236
StringBuilder sb = new StringBuilder();
@@ -358,10 +336,6 @@ public Drawing.Builder shapeOrNull(ShapeOrNull shapeOrNull) {
358336
return this;
359337
}
360338
public Drawing.Builder nullableShape(NullableShape nullableShape) {
361-
this.instance.nullableShape = JsonNullable.<NullableShape>of(nullableShape);
362-
return this;
363-
}
364-
public Drawing.Builder nullableShape(JsonNullable<NullableShape> nullableShape) {
365339
this.instance.nullableShape = nullableShape;
366340
return this;
367341
}

samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EnumTest.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
import org.openapitools.client.model.OuterEnumDefaultValue;
3232
import org.openapitools.client.model.OuterEnumInteger;
3333
import org.openapitools.client.model.OuterEnumIntegerDefaultValue;
34-
import org.openapitools.jackson.nullable.JsonNullable;
35-
import com.fasterxml.jackson.annotation.JsonIgnore;
36-
import org.openapitools.jackson.nullable.JsonNullable;
37-
import java.util.NoSuchElementException;
3834
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
3935

4036

@@ -255,7 +251,8 @@ public static EnumNumberEnum fromValue(Double value) {
255251
private EnumNumberEnum enumNumber;
256252

257253
public static final String JSON_PROPERTY_OUTER_ENUM = "outerEnum";
258-
private JsonNullable<OuterEnum> outerEnum = JsonNullable.<OuterEnum>undefined();
254+
@javax.annotation.Nullable
255+
private OuterEnum outerEnum;
259256

260257
public static final String JSON_PROPERTY_OUTER_ENUM_INTEGER = "outerEnumInteger";
261258
@javax.annotation.Nullable
@@ -393,7 +390,7 @@ public void setEnumNumber(@javax.annotation.Nullable EnumNumberEnum enumNumber)
393390

394391

395392
public EnumTest outerEnum(@javax.annotation.Nullable OuterEnum outerEnum) {
396-
this.outerEnum = JsonNullable.<OuterEnum>of(outerEnum);
393+
this.outerEnum = outerEnum;
397394
return this;
398395
}
399396

@@ -402,25 +399,17 @@ public EnumTest outerEnum(@javax.annotation.Nullable OuterEnum outerEnum) {
402399
* @return outerEnum
403400
*/
404401
@javax.annotation.Nullable
405-
@JsonIgnore
406-
public OuterEnum getOuterEnum() {
407-
return outerEnum.orElse(null);
408-
}
409-
410402
@JsonProperty(value = JSON_PROPERTY_OUTER_ENUM, required = false)
411403
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
412-
413-
public JsonNullable<OuterEnum> getOuterEnum_JsonNullable() {
404+
public OuterEnum getOuterEnum() {
414405
return outerEnum;
415406
}
416-
417-
@JsonProperty(JSON_PROPERTY_OUTER_ENUM)
418-
public void setOuterEnum_JsonNullable(JsonNullable<OuterEnum> outerEnum) {
419-
this.outerEnum = outerEnum;
420-
}
421407

408+
409+
@JsonProperty(value = JSON_PROPERTY_OUTER_ENUM, required = false)
410+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
422411
public void setOuterEnum(@javax.annotation.Nullable OuterEnum outerEnum) {
423-
this.outerEnum = JsonNullable.<OuterEnum>of(outerEnum);
412+
this.outerEnum = outerEnum;
424413
}
425414

426415

@@ -504,22 +493,11 @@ public boolean equals(Object o) {
504493
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
505494
}
506495

507-
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
508-
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
509-
}
510-
511496
@Override
512497
public int hashCode() {
513498
return HashCodeBuilder.reflectionHashCode(this);
514499
}
515500

516-
private static <T> int hashCodeNullable(JsonNullable<T> a) {
517-
if (a == null) {
518-
return 1;
519-
}
520-
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
521-
}
522-
523501
@Override
524502
public String toString() {
525503
StringBuilder sb = new StringBuilder();
@@ -661,10 +639,6 @@ public EnumTest.Builder enumNumber(EnumNumberEnum enumNumber) {
661639
return this;
662640
}
663641
public EnumTest.Builder outerEnum(OuterEnum outerEnum) {
664-
this.instance.outerEnum = JsonNullable.<OuterEnum>of(outerEnum);
665-
return this;
666-
}
667-
public EnumTest.Builder outerEnum(JsonNullable<OuterEnum> outerEnum) {
668642
this.instance.outerEnum = outerEnum;
669643
return this;
670644
}

0 commit comments

Comments
 (0)