Skip to content

Commit 73c8728

Browse files
[Java] [Spring-client] Exclude discriminator from nullable annotation (#21981)
* Exclude the discriminator from getting a nullable-annotation * Update samples
1 parent ac3c370 commit 73c8728

File tree

27 files changed

+39
-24
lines changed

27 files changed

+39
-24
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
6767
{{#gson}}
6868
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
6969
{{/gson}}
70+
{{^isDiscriminator}}
7071
{{>nullable_var_annotations}}{{! prevent indent}}
72+
{{/isDiscriminator}}
73+
{{#isDiscriminator}}
74+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
75+
{{/isDiscriminator}}
7176
{{#vendorExtensions.x-field-extra-annotation}}
7277
{{{vendorExtensions.x-field-extra-annotation}}}
7378
{{/vendorExtensions.x-field-extra-annotation}}

modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pojo.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
6767
{{#gson}}
6868
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
6969
{{/gson}}
70+
{{^isDiscriminator}}
7071
{{>nullable_var_annotations}}{{! prevent indent}}
72+
{{/isDiscriminator}}
73+
{{#isDiscriminator}}
74+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
75+
{{/isDiscriminator}}
7176
{{#vendorExtensions.x-field-extra-annotation}}
7277
{{{vendorExtensions.x-field-extra-annotation}}}
7378
{{/vendorExtensions.x-field-extra-annotation}}

modules/openapi-generator/src/main/resources/Java/libraries/webclient/pojo.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
6767
{{#gson}}
6868
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
6969
{{/gson}}
70+
{{^isDiscriminator}}
7071
{{>nullable_var_annotations}}{{! prevent indent}}
72+
{{/isDiscriminator}}
73+
{{#isDiscriminator}}
74+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
75+
{{/isDiscriminator}}
7176
{{#vendorExtensions.x-field-extra-annotation}}
7277
{{{vendorExtensions.x-field-extra-annotation}}}
7378
{{/vendorExtensions.x-field-extra-annotation}}

samples/client/others/java/webclient-sealedInterface/src/main/java/org/openapitools/client/model/Apple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class Apple implements Fruit {
4141
private Integer seeds;
4242

4343
public static final String JSON_PROPERTY_FRUIT_TYPE = "fruitType";
44-
@javax.annotation.Nonnull
44+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
4545
private FruitType fruitType;
4646

4747
public Apple() {

samples/client/others/java/webclient-sealedInterface/src/main/java/org/openapitools/client/model/Banana.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class Banana implements Fruit {
4141
private Integer length;
4242

4343
public static final String JSON_PROPERTY_FRUIT_TYPE = "fruitType";
44-
@javax.annotation.Nonnull
44+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
4545
private FruitType fruitType;
4646

4747
public Banana() {

samples/client/others/java/webclient-sealedInterface/src/main/java/org/openapitools/client/model/Entity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class Entity {
7070
protected String atBaseType;
7171

7272
public static final String JSON_PROPERTY_AT_TYPE = "@type";
73-
@javax.annotation.Nonnull
73+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
7474
protected String atType;
7575

7676
public Entity() {

samples/client/others/java/webclient-sealedInterface/src/main/java/org/openapitools/client/model/EntityRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class EntityRef {
7676
protected String atBaseType;
7777

7878
public static final String JSON_PROPERTY_AT_TYPE = "@type";
79-
@javax.annotation.Nonnull
79+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
8080
protected String atType;
8181

8282
public EntityRef() {

samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/Animal.java

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

4949
public class Animal {
5050
public static final String JSON_PROPERTY_CLASS_NAME = "className";
51-
@jakarta.annotation.Nonnull
51+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
5252
protected String className;
5353

5454
public static final String JSON_PROPERTY_COLOR = "color";

samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/ParentWithNullable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static TypeEnum fromValue(String value) {
8484
}
8585

8686
public static final String JSON_PROPERTY_TYPE = "type";
87-
@jakarta.annotation.Nullable
87+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
8888
protected TypeEnum type;
8989

9090
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

samples/client/petstore/java/restclient-useSingleRequestParameter-static/src/main/java/org/openapitools/client/model/Animal.java

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

4848
public class Animal {
4949
public static final String JSON_PROPERTY_CLASS_NAME = "className";
50-
@jakarta.annotation.Nonnull
50+
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
5151
protected String className;
5252

5353
public static final String JSON_PROPERTY_COLOR = "color";

0 commit comments

Comments
 (0)