Add nullability annotations to Java generated clients (#19617)

* issue-1960: Add nullability annotations to Java generated clients

Motivations:
Have generated clients properly annotated for nullability to be able to check code using them with tools like NullAway

Modifications:
* Add nullable_var_annotations template to handle nullability annotation on vars
* Add pojo templates to use the nullability template
* Adapt tests

* issue-1960: Add nullability annotations to Java generated clients

Modifications:
* Run export_docs_generator.sh script to update samples
This commit is contained in:
Nicolas Vervelle
2024-10-16 10:14:29 +02:00
committed by GitHub
parent 8f7d9f7467
commit 65b1859161
1582 changed files with 14871 additions and 9980 deletions

View File

@@ -29,16 +29,18 @@ import java.io.IOException;
public class Bird {
public static final String SERIALIZED_NAME_SIZE = "size";
@SerializedName(SERIALIZED_NAME_SIZE)
@javax.annotation.Nullable
private String size;
public static final String SERIALIZED_NAME_COLOR = "color";
@SerializedName(SERIALIZED_NAME_COLOR)
@javax.annotation.Nullable
private String color;
public Bird() {
}
public Bird size(String size) {
public Bird size(@javax.annotation.Nullable String size) {
this.size = size;
return this;
@@ -55,12 +57,12 @@ public class Bird {
}
public void setSize(String size) {
public void setSize(@javax.annotation.Nullable String size) {
this.size = size;
}
public Bird color(String color) {
public Bird color(@javax.annotation.Nullable String color) {
this.color = color;
return this;
@@ -77,7 +79,7 @@ public class Bird {
}
public void setColor(String color) {
public void setColor(@javax.annotation.Nullable String color) {
this.color = color;
}

View File

@@ -29,16 +29,18 @@ import java.io.IOException;
public class Category {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nullable
private Long id;
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
@javax.annotation.Nullable
private String name;
public Category() {
}
public Category id(Long id) {
public Category id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
@@ -55,12 +57,12 @@ public class Category {
}
public void setId(Long id) {
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
public Category name(String name) {
public Category name(@javax.annotation.Nullable String name) {
this.name = name;
return this;
@@ -77,7 +79,7 @@ public class Category {
}
public void setName(String name) {
public void setName(@javax.annotation.Nullable String name) {
this.name = name;
}

View File

@@ -34,21 +34,24 @@ import org.openapitools.client.model.Query;
public class DataQuery extends Query {
public static final String SERIALIZED_NAME_SUFFIX = "suffix";
@SerializedName(SERIALIZED_NAME_SUFFIX)
@javax.annotation.Nullable
private String suffix;
public static final String SERIALIZED_NAME_TEXT = "text";
@SerializedName(SERIALIZED_NAME_TEXT)
@javax.annotation.Nullable
private String text;
public static final String SERIALIZED_NAME_DATE = "date";
@SerializedName(SERIALIZED_NAME_DATE)
@javax.annotation.Nullable
private OffsetDateTime date;
public DataQuery() {
}
public DataQuery suffix(String suffix) {
public DataQuery suffix(@javax.annotation.Nullable String suffix) {
this.suffix = suffix;
return this;
@@ -65,12 +68,12 @@ public class DataQuery extends Query {
}
public void setSuffix(String suffix) {
public void setSuffix(@javax.annotation.Nullable String suffix) {
this.suffix = suffix;
}
public DataQuery text(String text) {
public DataQuery text(@javax.annotation.Nullable String text) {
this.text = text;
return this;
@@ -87,12 +90,12 @@ public class DataQuery extends Query {
}
public void setText(String text) {
public void setText(@javax.annotation.Nullable String text) {
this.text = text;
}
public DataQuery date(OffsetDateTime date) {
public DataQuery date(@javax.annotation.Nullable OffsetDateTime date) {
this.date = date;
return this;
@@ -109,7 +112,7 @@ public class DataQuery extends Query {
}
public void setDate(OffsetDateTime date) {
public void setDate(@javax.annotation.Nullable OffsetDateTime date) {
this.date = date;
}

View File

@@ -34,6 +34,7 @@ import org.openapitools.jackson.nullable.JsonNullable;
public class DefaultValue {
public static final String SERIALIZED_NAME_ARRAY_STRING_ENUM_REF_DEFAULT = "array_string_enum_ref_default";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING_ENUM_REF_DEFAULT)
@javax.annotation.Nullable
private List<StringEnumRef> arrayStringEnumRefDefault = new ArrayList<>(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE));
/**
@@ -87,36 +88,43 @@ public class DefaultValue {
public static final String SERIALIZED_NAME_ARRAY_STRING_ENUM_DEFAULT = "array_string_enum_default";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING_ENUM_DEFAULT)
@javax.annotation.Nullable
private List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault = new ArrayList<>(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE));
public static final String SERIALIZED_NAME_ARRAY_STRING_DEFAULT = "array_string_default";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING_DEFAULT)
@javax.annotation.Nullable
private List<String> arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped"));
public static final String SERIALIZED_NAME_ARRAY_INTEGER_DEFAULT = "array_integer_default";
@SerializedName(SERIALIZED_NAME_ARRAY_INTEGER_DEFAULT)
@javax.annotation.Nullable
private List<Integer> arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3));
public static final String SERIALIZED_NAME_ARRAY_STRING = "array_string";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING)
@javax.annotation.Nullable
private List<String> arrayString = new ArrayList<>();
public static final String SERIALIZED_NAME_ARRAY_STRING_NULLABLE = "array_string_nullable";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING_NULLABLE)
@javax.annotation.Nullable
private List<String> arrayStringNullable;
public static final String SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE = "array_string_extension_nullable";
@SerializedName(SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE)
@javax.annotation.Nullable
private List<String> arrayStringExtensionNullable;
public static final String SERIALIZED_NAME_STRING_NULLABLE = "string_nullable";
@SerializedName(SERIALIZED_NAME_STRING_NULLABLE)
@javax.annotation.Nullable
private String stringNullable;
public DefaultValue() {
}
public DefaultValue arrayStringEnumRefDefault(List<StringEnumRef> arrayStringEnumRefDefault) {
public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List<StringEnumRef> arrayStringEnumRefDefault) {
this.arrayStringEnumRefDefault = arrayStringEnumRefDefault;
return this;
@@ -141,12 +149,12 @@ public class DefaultValue {
}
public void setArrayStringEnumRefDefault(List<StringEnumRef> arrayStringEnumRefDefault) {
public void setArrayStringEnumRefDefault(@javax.annotation.Nullable List<StringEnumRef> arrayStringEnumRefDefault) {
this.arrayStringEnumRefDefault = arrayStringEnumRefDefault;
}
public DefaultValue arrayStringEnumDefault(List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault) {
public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault) {
this.arrayStringEnumDefault = arrayStringEnumDefault;
return this;
@@ -171,12 +179,12 @@ public class DefaultValue {
}
public void setArrayStringEnumDefault(List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault) {
public void setArrayStringEnumDefault(@javax.annotation.Nullable List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault) {
this.arrayStringEnumDefault = arrayStringEnumDefault;
}
public DefaultValue arrayStringDefault(List<String> arrayStringDefault) {
public DefaultValue arrayStringDefault(@javax.annotation.Nullable List<String> arrayStringDefault) {
this.arrayStringDefault = arrayStringDefault;
return this;
@@ -201,12 +209,12 @@ public class DefaultValue {
}
public void setArrayStringDefault(List<String> arrayStringDefault) {
public void setArrayStringDefault(@javax.annotation.Nullable List<String> arrayStringDefault) {
this.arrayStringDefault = arrayStringDefault;
}
public DefaultValue arrayIntegerDefault(List<Integer> arrayIntegerDefault) {
public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List<Integer> arrayIntegerDefault) {
this.arrayIntegerDefault = arrayIntegerDefault;
return this;
@@ -231,12 +239,12 @@ public class DefaultValue {
}
public void setArrayIntegerDefault(List<Integer> arrayIntegerDefault) {
public void setArrayIntegerDefault(@javax.annotation.Nullable List<Integer> arrayIntegerDefault) {
this.arrayIntegerDefault = arrayIntegerDefault;
}
public DefaultValue arrayString(List<String> arrayString) {
public DefaultValue arrayString(@javax.annotation.Nullable List<String> arrayString) {
this.arrayString = arrayString;
return this;
@@ -261,12 +269,12 @@ public class DefaultValue {
}
public void setArrayString(List<String> arrayString) {
public void setArrayString(@javax.annotation.Nullable List<String> arrayString) {
this.arrayString = arrayString;
}
public DefaultValue arrayStringNullable(List<String> arrayStringNullable) {
public DefaultValue arrayStringNullable(@javax.annotation.Nullable List<String> arrayStringNullable) {
this.arrayStringNullable = arrayStringNullable;
return this;
@@ -291,12 +299,12 @@ public class DefaultValue {
}
public void setArrayStringNullable(List<String> arrayStringNullable) {
public void setArrayStringNullable(@javax.annotation.Nullable List<String> arrayStringNullable) {
this.arrayStringNullable = arrayStringNullable;
}
public DefaultValue arrayStringExtensionNullable(List<String> arrayStringExtensionNullable) {
public DefaultValue arrayStringExtensionNullable(@javax.annotation.Nullable List<String> arrayStringExtensionNullable) {
this.arrayStringExtensionNullable = arrayStringExtensionNullable;
return this;
@@ -321,12 +329,12 @@ public class DefaultValue {
}
public void setArrayStringExtensionNullable(List<String> arrayStringExtensionNullable) {
public void setArrayStringExtensionNullable(@javax.annotation.Nullable List<String> arrayStringExtensionNullable) {
this.arrayStringExtensionNullable = arrayStringExtensionNullable;
}
public DefaultValue stringNullable(String stringNullable) {
public DefaultValue stringNullable(@javax.annotation.Nullable String stringNullable) {
this.stringNullable = stringNullable;
return this;
@@ -343,7 +351,7 @@ public class DefaultValue {
}
public void setStringNullable(String stringNullable) {
public void setStringNullable(@javax.annotation.Nullable String stringNullable) {
this.stringNullable = stringNullable;
}

View File

@@ -30,20 +30,23 @@ import java.math.BigDecimal;
public class NumberPropertiesOnly {
public static final String SERIALIZED_NAME_NUMBER = "number";
@SerializedName(SERIALIZED_NAME_NUMBER)
@javax.annotation.Nullable
private BigDecimal number;
public static final String SERIALIZED_NAME_FLOAT = "float";
@SerializedName(SERIALIZED_NAME_FLOAT)
@javax.annotation.Nullable
private Float _float;
public static final String SERIALIZED_NAME_DOUBLE = "double";
@SerializedName(SERIALIZED_NAME_DOUBLE)
@javax.annotation.Nullable
private Double _double;
public NumberPropertiesOnly() {
}
public NumberPropertiesOnly number(BigDecimal number) {
public NumberPropertiesOnly number(@javax.annotation.Nullable BigDecimal number) {
this.number = number;
return this;
@@ -60,12 +63,12 @@ public class NumberPropertiesOnly {
}
public void setNumber(BigDecimal number) {
public void setNumber(@javax.annotation.Nullable BigDecimal number) {
this.number = number;
}
public NumberPropertiesOnly _float(Float _float) {
public NumberPropertiesOnly _float(@javax.annotation.Nullable Float _float) {
this._float = _float;
return this;
@@ -82,12 +85,12 @@ public class NumberPropertiesOnly {
}
public void setFloat(Float _float) {
public void setFloat(@javax.annotation.Nullable Float _float) {
this._float = _float;
}
public NumberPropertiesOnly _double(Double _double) {
public NumberPropertiesOnly _double(@javax.annotation.Nullable Double _double) {
this._double = _double;
return this;
@@ -106,7 +109,7 @@ public class NumberPropertiesOnly {
}
public void setDouble(Double _double) {
public void setDouble(@javax.annotation.Nullable Double _double) {
this._double = _double;
}

View File

@@ -34,22 +34,27 @@ import org.openapitools.client.model.Tag;
public class Pet {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nullable
private Long id;
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
@javax.annotation.Nonnull
private String name;
public static final String SERIALIZED_NAME_CATEGORY = "category";
@SerializedName(SERIALIZED_NAME_CATEGORY)
@javax.annotation.Nullable
private Category category;
public static final String SERIALIZED_NAME_PHOTO_URLS = "photoUrls";
@SerializedName(SERIALIZED_NAME_PHOTO_URLS)
@javax.annotation.Nonnull
private List<String> photoUrls = new ArrayList<>();
public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
@javax.annotation.Nullable
private List<Tag> tags = new ArrayList<>();
/**
@@ -103,12 +108,13 @@ public class Pet {
public static final String SERIALIZED_NAME_STATUS = "status";
@SerializedName(SERIALIZED_NAME_STATUS)
@javax.annotation.Nullable
private StatusEnum status;
public Pet() {
}
public Pet id(Long id) {
public Pet id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
@@ -125,12 +131,12 @@ public class Pet {
}
public void setId(Long id) {
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
public Pet name(String name) {
public Pet name(@javax.annotation.Nonnull String name) {
this.name = name;
return this;
@@ -147,12 +153,12 @@ public class Pet {
}
public void setName(String name) {
public void setName(@javax.annotation.Nonnull String name) {
this.name = name;
}
public Pet category(Category category) {
public Pet category(@javax.annotation.Nullable Category category) {
this.category = category;
return this;
@@ -169,12 +175,12 @@ public class Pet {
}
public void setCategory(Category category) {
public void setCategory(@javax.annotation.Nullable Category category) {
this.category = category;
}
public Pet photoUrls(List<String> photoUrls) {
public Pet photoUrls(@javax.annotation.Nonnull List<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
@@ -199,12 +205,12 @@ public class Pet {
}
public void setPhotoUrls(List<String> photoUrls) {
public void setPhotoUrls(@javax.annotation.Nonnull List<String> photoUrls) {
this.photoUrls = photoUrls;
}
public Pet tags(List<Tag> tags) {
public Pet tags(@javax.annotation.Nullable List<Tag> tags) {
this.tags = tags;
return this;
@@ -229,12 +235,12 @@ public class Pet {
}
public void setTags(List<Tag> tags) {
public void setTags(@javax.annotation.Nullable List<Tag> tags) {
this.tags = tags;
}
public Pet status(StatusEnum status) {
public Pet status(@javax.annotation.Nullable StatusEnum status) {
this.status = status;
return this;
@@ -251,7 +257,7 @@ public class Pet {
}
public void setStatus(StatusEnum status) {
public void setStatus(@javax.annotation.Nullable StatusEnum status) {
this.status = status;
}

View File

@@ -32,6 +32,7 @@ import java.util.List;
public class Query {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nullable
private Long id;
/**
@@ -85,12 +86,13 @@ public class Query {
public static final String SERIALIZED_NAME_OUTCOMES = "outcomes";
@SerializedName(SERIALIZED_NAME_OUTCOMES)
@javax.annotation.Nullable
private List<OutcomesEnum> outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE));
public Query() {
}
public Query id(Long id) {
public Query id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
@@ -107,12 +109,12 @@ public class Query {
}
public void setId(Long id) {
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
public Query outcomes(List<OutcomesEnum> outcomes) {
public Query outcomes(@javax.annotation.Nullable List<OutcomesEnum> outcomes) {
this.outcomes = outcomes;
return this;
@@ -137,7 +139,7 @@ public class Query {
}
public void setOutcomes(List<OutcomesEnum> outcomes) {
public void setOutcomes(@javax.annotation.Nullable List<OutcomesEnum> outcomes) {
this.outcomes = outcomes;
}

View File

@@ -29,16 +29,18 @@ import java.io.IOException;
public class Tag {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nullable
private Long id;
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
@javax.annotation.Nullable
private String name;
public Tag() {
}
public Tag id(Long id) {
public Tag id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
@@ -55,12 +57,12 @@ public class Tag {
}
public void setId(Long id) {
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
public Tag name(String name) {
public Tag name(@javax.annotation.Nullable String name) {
this.name = name;
return this;
@@ -77,7 +79,7 @@ public class Tag {
}
public void setName(String name) {
public void setName(@javax.annotation.Nullable String name) {
this.name = name;
}

View File

@@ -29,12 +29,13 @@ import java.io.IOException;
public class TestFormObjectMultipartRequestMarker {
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
@javax.annotation.Nullable
private String name;
public TestFormObjectMultipartRequestMarker() {
}
public TestFormObjectMultipartRequestMarker name(String name) {
public TestFormObjectMultipartRequestMarker name(@javax.annotation.Nullable String name) {
this.name = name;
return this;
@@ -51,7 +52,7 @@ public class TestFormObjectMultipartRequestMarker {
}
public void setName(String name) {
public void setName(@javax.annotation.Nullable String name) {
this.name = name;
}

View File

@@ -29,24 +29,28 @@ import java.io.IOException;
public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter {
public static final String SERIALIZED_NAME_SIZE = "size";
@SerializedName(SERIALIZED_NAME_SIZE)
@javax.annotation.Nullable
private String size;
public static final String SERIALIZED_NAME_COLOR = "color";
@SerializedName(SERIALIZED_NAME_COLOR)
@javax.annotation.Nullable
private String color;
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nullable
private Long id;
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
@javax.annotation.Nullable
private String name;
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter() {
}
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter size(String size) {
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter size(@javax.annotation.Nullable String size) {
this.size = size;
return this;
@@ -63,12 +67,12 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
}
public void setSize(String size) {
public void setSize(@javax.annotation.Nullable String size) {
this.size = size;
}
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter color(String color) {
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter color(@javax.annotation.Nullable String color) {
this.color = color;
return this;
@@ -85,12 +89,12 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
}
public void setColor(String color) {
public void setColor(@javax.annotation.Nullable String color) {
this.color = color;
}
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter id(Long id) {
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
@@ -107,12 +111,12 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
}
public void setId(Long id) {
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter name(String name) {
public TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter name(@javax.annotation.Nullable String name) {
this.name = name;
return this;
@@ -129,7 +133,7 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
}
public void setName(String name) {
public void setName(@javax.annotation.Nullable String name) {
this.name = name;
}

View File

@@ -32,12 +32,13 @@ import java.util.List;
public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
public static final String SERIALIZED_NAME_VALUES = "values";
@SerializedName(SERIALIZED_NAME_VALUES)
@javax.annotation.Nullable
private List<String> values = new ArrayList<>();
public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() {
}
public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter values(List<String> values) {
public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter values(@javax.annotation.Nullable List<String> values) {
this.values = values;
return this;
@@ -62,7 +63,7 @@ public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
}
public void setValues(List<String> values) {
public void setValues(@javax.annotation.Nullable List<String> values) {
this.values = values;
}