From d400d7fb15e94cdbac94627de22d33b2dde51ee6 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 24 Feb 2023 15:24:34 +0800 Subject: [PATCH] Better handling of x-nullable in codegen property (#14800) * add failed tests * add logic to handle x-nullable in property * update samples * update test --- .../openapitools/codegen/DefaultCodegen.java | 4 ++ .../src/test/resources/3_0/echo_api.yaml | 5 ++ .../java/apache-httpclient/api/openapi.yaml | 5 ++ .../apache-httpclient/docs/DefaultValue.md | 1 + .../client/model/DefaultValue.java | 68 ++++++++++++++++++- .../org/openapitools/client/CustomTest.java | 4 +- .../echo_api/java/feign-gson/api/openapi.yaml | 5 ++ .../client/model/DefaultValue.java | 35 +++++++++- .../echo_api/java/native/api/openapi.yaml | 5 ++ .../echo_api/java/native/docs/DefaultValue.md | 1 + .../client/model/DefaultValue.java | 62 ++++++++++++++++- .../org/openapitools/client/CustomTest.java | 4 ++ .../java/okhttp-gson/api/openapi.yaml | 5 ++ .../java/okhttp-gson/docs/DefaultValue.md | 1 + .../client/model/DefaultValue.java | 40 ++++++++++- .../python-nextgen/docs/DefaultValue.md | 1 + .../openapi_client/models/default_value.py | 8 ++- 17 files changed, 247 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 0d77a20a74d..40ff3a93ad7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3877,8 +3877,12 @@ public class DefaultCodegen implements CodegenConfig { } } + // set isNullable using nullable or x-nullable in the schema if (referencedSchema.getNullable() != null) { property.isNullable = referencedSchema.getNullable(); + } else if (referencedSchema.getExtensions() != null && + referencedSchema.getExtensions().containsKey("x-nullable")) { + property.isNullable = (Boolean) referencedSchema.getExtensions().get("x-nullable"); } property.dataType = getTypeDeclaration(p); diff --git a/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml b/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml index 1ac0a44ab12..860d590a829 100644 --- a/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml @@ -451,6 +451,11 @@ components: type: array items: type: string + array_string_extension_nullable: + x-nullable: true + type: array + items: + type: string string_nullable: type: string nullable: true diff --git a/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml b/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml index 7986a81dcfe..776a22706c7 100644 --- a/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml +++ b/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml @@ -466,6 +466,11 @@ components: type: string nullable: true type: array + array_string_extension_nullable: + items: + type: string + type: array + x-nullable: true string_nullable: nullable: true type: string diff --git a/samples/client/echo_api/java/apache-httpclient/docs/DefaultValue.md b/samples/client/echo_api/java/apache-httpclient/docs/DefaultValue.md index 2eda5b585b0..20a9b8ee250 100644 --- a/samples/client/echo_api/java/apache-httpclient/docs/DefaultValue.md +++ b/samples/client/echo_api/java/apache-httpclient/docs/DefaultValue.md @@ -14,6 +14,7 @@ to test the default value of properties |**arrayIntegerDefault** | **List<Integer>** | | [optional] | |**arrayString** | **List<String>** | | [optional] | |**arrayStringNullable** | **List<String>** | | [optional] | +|**arrayStringExtensionNullable** | **List<String>** | | [optional] | |**stringNullable** | **String** | | [optional] | diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java index 859afd7a981..0cc2f5932b9 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -43,6 +43,7 @@ import java.util.StringJoiner; DefaultValue.JSON_PROPERTY_ARRAY_INTEGER_DEFAULT, DefaultValue.JSON_PROPERTY_ARRAY_STRING, DefaultValue.JSON_PROPERTY_ARRAY_STRING_NULLABLE, + DefaultValue.JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE, DefaultValue.JSON_PROPERTY_STRING_NULLABLE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") @@ -102,6 +103,9 @@ public class DefaultValue { public static final String JSON_PROPERTY_ARRAY_STRING_NULLABLE = "array_string_nullable"; private JsonNullable> arrayStringNullable = JsonNullable.>undefined(); + public static final String JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE = "array_string_extension_nullable"; + private JsonNullable> arrayStringExtensionNullable = JsonNullable.>undefined(); + public static final String JSON_PROPERTY_STRING_NULLABLE = "string_nullable"; private JsonNullable stringNullable = JsonNullable.undefined(); @@ -324,6 +328,52 @@ public class DefaultValue { } + public DefaultValue arrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = JsonNullable.>of(arrayStringExtensionNullable); + + return this; + } + + public DefaultValue addArrayStringExtensionNullableItem(String arrayStringExtensionNullableItem) { + if (this.arrayStringExtensionNullable == null || !this.arrayStringExtensionNullable.isPresent()) { + this.arrayStringExtensionNullable = JsonNullable.>of(new ArrayList<>()); + } + try { + this.arrayStringExtensionNullable.get().add(arrayStringExtensionNullableItem); + } catch (java.util.NoSuchElementException e) { + // this can never happen, as we make sure above that the value is present + } + return this; + } + + /** + * Get arrayStringExtensionNullable + * @return arrayStringExtensionNullable + **/ + @javax.annotation.Nullable + @JsonIgnore + + public List getArrayStringExtensionNullable() { + return arrayStringExtensionNullable.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public JsonNullable> getArrayStringExtensionNullable_JsonNullable() { + return arrayStringExtensionNullable; + } + + @JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE) + public void setArrayStringExtensionNullable_JsonNullable(JsonNullable> arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + } + + public void setArrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = JsonNullable.>of(arrayStringExtensionNullable); + } + + public DefaultValue stringNullable(String stringNullable) { this.stringNullable = JsonNullable.of(stringNullable); @@ -373,6 +423,7 @@ public class DefaultValue { Objects.equals(this.arrayIntegerDefault, defaultValue.arrayIntegerDefault) && Objects.equals(this.arrayString, defaultValue.arrayString) && equalsNullable(this.arrayStringNullable, defaultValue.arrayStringNullable) && + equalsNullable(this.arrayStringExtensionNullable, defaultValue.arrayStringExtensionNullable) && equalsNullable(this.stringNullable, defaultValue.stringNullable); } @@ -382,7 +433,7 @@ public class DefaultValue { @Override public int hashCode() { - return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, hashCodeNullable(arrayStringNullable), hashCodeNullable(stringNullable)); + return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, hashCodeNullable(arrayStringNullable), hashCodeNullable(arrayStringExtensionNullable), hashCodeNullable(stringNullable)); } private static int hashCodeNullable(JsonNullable a) { @@ -402,6 +453,7 @@ public class DefaultValue { sb.append(" arrayIntegerDefault: ").append(toIndentedString(arrayIntegerDefault)).append("\n"); sb.append(" arrayString: ").append(toIndentedString(arrayString)).append("\n"); sb.append(" arrayStringNullable: ").append(toIndentedString(arrayStringNullable)).append("\n"); + sb.append(" arrayStringExtensionNullable: ").append(toIndentedString(arrayStringExtensionNullable)).append("\n"); sb.append(" stringNullable: ").append(toIndentedString(stringNullable)).append("\n"); sb.append("}"); return sb.toString(); @@ -536,6 +588,20 @@ public class DefaultValue { } } + // add `array_string_extension_nullable` to the URL query string + if (getArrayStringExtensionNullable() != null) { + for (int i = 0; i < getArrayStringExtensionNullable().size(); i++) { + try { + joiner.add(String.format("%sarray_string_extension_nullable%s%s=%s", prefix, suffix, + "".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix), + URLEncoder.encode(String.valueOf(getArrayStringExtensionNullable().get(i)), "UTF-8").replaceAll("\\+", "%20"))); + } catch (UnsupportedEncodingException e) { + // Should never happen, UTF-8 is always supported + throw new RuntimeException(e); + } + } + } + // add `string_nullable` to the URL query string if (getStringNullable() != null) { try { diff --git a/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/CustomTest.java b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/CustomTest.java index a4dd87b883c..3517d1b5b95 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/CustomTest.java +++ b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/CustomTest.java @@ -220,7 +220,7 @@ public class CustomTest { Assert.assertNull(d.getArrayStringNullable()); Assert.assertEquals(d.getArrayString().size(), 0); - Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"success\",\"failure\"],\"array_string_enum_default\":[\"success\",\"failure\"],\"array_string_default\":[\"failure\",\"skipped\"],\"array_integer_default\":[1,3],\"array_string\":[],\"array_string_nullable\":{\"present\":false},\"string_nullable\":{\"present\":false}}"); + Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"success\",\"failure\"],\"array_string_enum_default\":[\"success\",\"failure\"],\"array_string_default\":[\"failure\",\"skipped\"],\"array_integer_default\":[1,3],\"array_string\":[],\"array_string_nullable\":{\"present\":false},\"array_string_extension_nullable\":{\"present\":false},\"string_nullable\":{\"present\":false}}"); } @Test @@ -248,7 +248,7 @@ public class CustomTest { Assert.assertNull(d.getArrayStringNullable()); Assert.assertEquals(d.getArrayString().size(), 0); - Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"unclassified\"],\"array_string_enum_default\":[\"unclassified\"],\"array_string_default\":[\"failure\"],\"array_integer_default\":[1,3],\"array_string\":[],\"array_string_nullable\":{\"present\":false},\"string_nullable\":{\"present\":false}}"); + Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"unclassified\"],\"array_string_enum_default\":[\"unclassified\"],\"array_string_default\":[\"failure\"],\"array_integer_default\":[1,3],\"array_string\":[],\"array_string_nullable\":{\"present\":false},\"array_string_extension_nullable\":{\"present\":false},\"string_nullable\":{\"present\":false}}"); } @Test diff --git a/samples/client/echo_api/java/feign-gson/api/openapi.yaml b/samples/client/echo_api/java/feign-gson/api/openapi.yaml index 7986a81dcfe..776a22706c7 100644 --- a/samples/client/echo_api/java/feign-gson/api/openapi.yaml +++ b/samples/client/echo_api/java/feign-gson/api/openapi.yaml @@ -466,6 +466,11 @@ components: type: string nullable: true type: array + array_string_extension_nullable: + items: + type: string + type: array + x-nullable: true string_nullable: nullable: true type: string diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java index 84ac9669049..df9a694da6e 100644 --- a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -104,6 +104,10 @@ public class DefaultValue { @SerializedName(SERIALIZED_NAME_ARRAY_STRING_NULLABLE) private List arrayStringNullable; + public static final String SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE = "array_string_extension_nullable"; + @SerializedName(SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE) + private List arrayStringExtensionNullable; + public static final String SERIALIZED_NAME_STRING_NULLABLE = "string_nullable"; @SerializedName(SERIALIZED_NAME_STRING_NULLABLE) private String stringNullable; @@ -288,6 +292,33 @@ public class DefaultValue { } + public DefaultValue arrayStringExtensionNullable(List arrayStringExtensionNullable) { + + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + return this; + } + + public DefaultValue addArrayStringExtensionNullableItem(String arrayStringExtensionNullableItem) { + this.arrayStringExtensionNullable.add(arrayStringExtensionNullableItem); + return this; + } + + /** + * Get arrayStringExtensionNullable + * @return arrayStringExtensionNullable + **/ + @javax.annotation.Nullable + + public List getArrayStringExtensionNullable() { + return arrayStringExtensionNullable; + } + + + public void setArrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + } + + public DefaultValue stringNullable(String stringNullable) { this.stringNullable = stringNullable; @@ -325,6 +356,7 @@ public class DefaultValue { Objects.equals(this.arrayIntegerDefault, defaultValue.arrayIntegerDefault) && Objects.equals(this.arrayString, defaultValue.arrayString) && Objects.equals(this.arrayStringNullable, defaultValue.arrayStringNullable) && + Objects.equals(this.arrayStringExtensionNullable, defaultValue.arrayStringExtensionNullable) && Objects.equals(this.stringNullable, defaultValue.stringNullable); } @@ -334,7 +366,7 @@ public class DefaultValue { @Override public int hashCode() { - return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, arrayStringNullable, stringNullable); + return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, arrayStringNullable, arrayStringExtensionNullable, stringNullable); } private static int hashCodeNullable(JsonNullable a) { @@ -354,6 +386,7 @@ public class DefaultValue { sb.append(" arrayIntegerDefault: ").append(toIndentedString(arrayIntegerDefault)).append("\n"); sb.append(" arrayString: ").append(toIndentedString(arrayString)).append("\n"); sb.append(" arrayStringNullable: ").append(toIndentedString(arrayStringNullable)).append("\n"); + sb.append(" arrayStringExtensionNullable: ").append(toIndentedString(arrayStringExtensionNullable)).append("\n"); sb.append(" stringNullable: ").append(toIndentedString(stringNullable)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/samples/client/echo_api/java/native/api/openapi.yaml b/samples/client/echo_api/java/native/api/openapi.yaml index 7986a81dcfe..776a22706c7 100644 --- a/samples/client/echo_api/java/native/api/openapi.yaml +++ b/samples/client/echo_api/java/native/api/openapi.yaml @@ -466,6 +466,11 @@ components: type: string nullable: true type: array + array_string_extension_nullable: + items: + type: string + type: array + x-nullable: true string_nullable: nullable: true type: string diff --git a/samples/client/echo_api/java/native/docs/DefaultValue.md b/samples/client/echo_api/java/native/docs/DefaultValue.md index 2eda5b585b0..20a9b8ee250 100644 --- a/samples/client/echo_api/java/native/docs/DefaultValue.md +++ b/samples/client/echo_api/java/native/docs/DefaultValue.md @@ -14,6 +14,7 @@ to test the default value of properties |**arrayIntegerDefault** | **List<Integer>** | | [optional] | |**arrayString** | **List<String>** | | [optional] | |**arrayStringNullable** | **List<String>** | | [optional] | +|**arrayStringExtensionNullable** | **List<String>** | | [optional] | |**stringNullable** | **String** | | [optional] | diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java index 28f3c70e634..fbeddeec813 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -45,6 +45,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; DefaultValue.JSON_PROPERTY_ARRAY_INTEGER_DEFAULT, DefaultValue.JSON_PROPERTY_ARRAY_STRING, DefaultValue.JSON_PROPERTY_ARRAY_STRING_NULLABLE, + DefaultValue.JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE, DefaultValue.JSON_PROPERTY_STRING_NULLABLE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") @@ -104,6 +105,9 @@ public class DefaultValue { public static final String JSON_PROPERTY_ARRAY_STRING_NULLABLE = "array_string_nullable"; private JsonNullable> arrayStringNullable = JsonNullable.>undefined(); + public static final String JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE = "array_string_extension_nullable"; + private JsonNullable> arrayStringExtensionNullable = JsonNullable.>undefined(); + public static final String JSON_PROPERTY_STRING_NULLABLE = "string_nullable"; private JsonNullable stringNullable = JsonNullable.undefined(); @@ -320,6 +324,51 @@ public class DefaultValue { } + public DefaultValue arrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = JsonNullable.>of(arrayStringExtensionNullable); + return this; + } + + public DefaultValue addArrayStringExtensionNullableItem(String arrayStringExtensionNullableItem) { + if (this.arrayStringExtensionNullable == null || !this.arrayStringExtensionNullable.isPresent()) { + this.arrayStringExtensionNullable = JsonNullable.>of(new ArrayList<>()); + } + try { + this.arrayStringExtensionNullable.get().add(arrayStringExtensionNullableItem); + } catch (java.util.NoSuchElementException e) { + // this can never happen, as we make sure above that the value is present + } + return this; + } + + /** + * Get arrayStringExtensionNullable + * @return arrayStringExtensionNullable + **/ + @javax.annotation.Nullable + @JsonIgnore + + public List getArrayStringExtensionNullable() { + return arrayStringExtensionNullable.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public JsonNullable> getArrayStringExtensionNullable_JsonNullable() { + return arrayStringExtensionNullable; + } + + @JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE) + public void setArrayStringExtensionNullable_JsonNullable(JsonNullable> arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + } + + public void setArrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = JsonNullable.>of(arrayStringExtensionNullable); + } + + public DefaultValue stringNullable(String stringNullable) { this.stringNullable = JsonNullable.of(stringNullable); return this; @@ -371,6 +420,7 @@ public class DefaultValue { Objects.equals(this.arrayIntegerDefault, defaultValue.arrayIntegerDefault) && Objects.equals(this.arrayString, defaultValue.arrayString) && equalsNullable(this.arrayStringNullable, defaultValue.arrayStringNullable) && + equalsNullable(this.arrayStringExtensionNullable, defaultValue.arrayStringExtensionNullable) && equalsNullable(this.stringNullable, defaultValue.stringNullable); } @@ -380,7 +430,7 @@ public class DefaultValue { @Override public int hashCode() { - return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, hashCodeNullable(arrayStringNullable), hashCodeNullable(stringNullable)); + return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, hashCodeNullable(arrayStringNullable), hashCodeNullable(arrayStringExtensionNullable), hashCodeNullable(stringNullable)); } private static int hashCodeNullable(JsonNullable a) { @@ -400,6 +450,7 @@ public class DefaultValue { sb.append(" arrayIntegerDefault: ").append(toIndentedString(arrayIntegerDefault)).append("\n"); sb.append(" arrayString: ").append(toIndentedString(arrayString)).append("\n"); sb.append(" arrayStringNullable: ").append(toIndentedString(arrayStringNullable)).append("\n"); + sb.append(" arrayStringExtensionNullable: ").append(toIndentedString(arrayStringExtensionNullable)).append("\n"); sb.append(" stringNullable: ").append(toIndentedString(stringNullable)).append("\n"); sb.append("}"); return sb.toString(); @@ -504,6 +555,15 @@ public class DefaultValue { } } + // add `array_string_extension_nullable` to the URL query string + if (getArrayStringExtensionNullable() != null) { + for (int i = 0; i < getArrayStringExtensionNullable().size(); i++) { + joiner.add(String.format("%sarray_string_extension_nullable%s%s=%s", prefix, suffix, + "".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix), + URLEncoder.encode(String.valueOf(getArrayStringExtensionNullable().get(i)), StandardCharsets.UTF_8).replaceAll("\\+", "%20"))); + } + } + // add `string_nullable` to the URL query string if (getStringNullable() != null) { joiner.add(String.format("%sstring_nullable%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getStringNullable()), StandardCharsets.UTF_8).replaceAll("\\+", "%20"))); diff --git a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java index d977367e873..16b304c998b 100644 --- a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java +++ b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java @@ -167,8 +167,10 @@ public class CustomTest { Assert.assertEquals(d.getArrayIntegerDefault().get(1), Integer.valueOf(3)); Assert.assertNull(d.getArrayStringNullable()); + Assert.assertNull(d.getArrayStringExtensionNullable()); Assert.assertEquals(d.getArrayString().size(), 0); + // test addItem d.addArrayStringEnumDefaultItem(DefaultValue.ArrayStringEnumDefaultEnum.UNCLASSIFIED); Assert.assertEquals(d.getArrayStringEnumDefault().size(), 3); @@ -209,6 +211,7 @@ public class CustomTest { Assert.assertEquals(d.getArrayIntegerDefault().get(1), Integer.valueOf(3)); Assert.assertNull(d.getArrayStringNullable()); + Assert.assertNull(d.getArrayStringExtensionNullable()); Assert.assertEquals(d.getArrayString().size(), 0); Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"success\",\"failure\"],\"array_string_enum_default\":[\"success\",\"failure\"],\"array_string_default\":[\"failure\",\"skipped\"],\"array_integer_default\":[1,3],\"array_string\":[]}"); @@ -237,6 +240,7 @@ public class CustomTest { Assert.assertEquals(d.getArrayIntegerDefault().get(1), Integer.valueOf(3)); Assert.assertNull(d.getArrayStringNullable()); + Assert.assertNull(d.getArrayStringExtensionNullable()); Assert.assertEquals(d.getArrayString().size(), 0); Assert.assertEquals(apiClient.getObjectMapper().writeValueAsString(d), "{\"array_string_enum_ref_default\":[\"unclassified\"],\"array_string_enum_default\":[\"unclassified\"],\"array_string_default\":[\"failure\"],\"array_integer_default\":[1,3],\"array_string\":[]}"); diff --git a/samples/client/echo_api/java/okhttp-gson/api/openapi.yaml b/samples/client/echo_api/java/okhttp-gson/api/openapi.yaml index 7986a81dcfe..776a22706c7 100644 --- a/samples/client/echo_api/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/echo_api/java/okhttp-gson/api/openapi.yaml @@ -466,6 +466,11 @@ components: type: string nullable: true type: array + array_string_extension_nullable: + items: + type: string + type: array + x-nullable: true string_nullable: nullable: true type: string diff --git a/samples/client/echo_api/java/okhttp-gson/docs/DefaultValue.md b/samples/client/echo_api/java/okhttp-gson/docs/DefaultValue.md index 2eda5b585b0..20a9b8ee250 100644 --- a/samples/client/echo_api/java/okhttp-gson/docs/DefaultValue.md +++ b/samples/client/echo_api/java/okhttp-gson/docs/DefaultValue.md @@ -14,6 +14,7 @@ to test the default value of properties |**arrayIntegerDefault** | **List<Integer>** | | [optional] | |**arrayString** | **List<String>** | | [optional] | |**arrayStringNullable** | **List<String>** | | [optional] | +|**arrayStringExtensionNullable** | **List<String>** | | [optional] | |**stringNullable** | **String** | | [optional] | diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java index 420af1f7ff6..dfdad0cadce 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -125,6 +125,10 @@ public class DefaultValue { @SerializedName(SERIALIZED_NAME_ARRAY_STRING_NULLABLE) private List arrayStringNullable; + public static final String SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE = "array_string_extension_nullable"; + @SerializedName(SERIALIZED_NAME_ARRAY_STRING_EXTENSION_NULLABLE) + private List arrayStringExtensionNullable; + public static final String SERIALIZED_NAME_STRING_NULLABLE = "string_nullable"; @SerializedName(SERIALIZED_NAME_STRING_NULLABLE) private String stringNullable; @@ -309,6 +313,33 @@ public class DefaultValue { } + public DefaultValue arrayStringExtensionNullable(List arrayStringExtensionNullable) { + + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + return this; + } + + public DefaultValue addArrayStringExtensionNullableItem(String arrayStringExtensionNullableItem) { + this.arrayStringExtensionNullable.add(arrayStringExtensionNullableItem); + return this; + } + + /** + * Get arrayStringExtensionNullable + * @return arrayStringExtensionNullable + **/ + @javax.annotation.Nullable + + public List getArrayStringExtensionNullable() { + return arrayStringExtensionNullable; + } + + + public void setArrayStringExtensionNullable(List arrayStringExtensionNullable) { + this.arrayStringExtensionNullable = arrayStringExtensionNullable; + } + + public DefaultValue stringNullable(String stringNullable) { this.stringNullable = stringNullable; @@ -347,6 +378,7 @@ public class DefaultValue { Objects.equals(this.arrayIntegerDefault, defaultValue.arrayIntegerDefault) && Objects.equals(this.arrayString, defaultValue.arrayString) && Objects.equals(this.arrayStringNullable, defaultValue.arrayStringNullable) && + Objects.equals(this.arrayStringExtensionNullable, defaultValue.arrayStringExtensionNullable) && Objects.equals(this.stringNullable, defaultValue.stringNullable); } @@ -356,7 +388,7 @@ public class DefaultValue { @Override public int hashCode() { - return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, arrayStringNullable, stringNullable); + return Objects.hash(arrayStringEnumRefDefault, arrayStringEnumDefault, arrayStringDefault, arrayIntegerDefault, arrayString, arrayStringNullable, arrayStringExtensionNullable, stringNullable); } private static int hashCodeNullable(JsonNullable a) { @@ -376,6 +408,7 @@ public class DefaultValue { sb.append(" arrayIntegerDefault: ").append(toIndentedString(arrayIntegerDefault)).append("\n"); sb.append(" arrayString: ").append(toIndentedString(arrayString)).append("\n"); sb.append(" arrayStringNullable: ").append(toIndentedString(arrayStringNullable)).append("\n"); + sb.append(" arrayStringExtensionNullable: ").append(toIndentedString(arrayStringExtensionNullable)).append("\n"); sb.append(" stringNullable: ").append(toIndentedString(stringNullable)).append("\n"); sb.append("}"); return sb.toString(); @@ -405,6 +438,7 @@ public class DefaultValue { openapiFields.add("array_integer_default"); openapiFields.add("array_string"); openapiFields.add("array_string_nullable"); + openapiFields.add("array_string_extension_nullable"); openapiFields.add("string_nullable"); // a set of required properties/fields (JSON key names) @@ -455,6 +489,10 @@ public class DefaultValue { if (jsonObj.get("array_string_nullable") != null && !jsonObj.get("array_string_nullable").isJsonArray()) { throw new IllegalArgumentException(String.format("Expected the field `array_string_nullable` to be an array in the JSON string but got `%s`", jsonObj.get("array_string_nullable").toString())); } + // ensure the optional json data is an array if present + if (jsonObj.get("array_string_extension_nullable") != null && !jsonObj.get("array_string_extension_nullable").isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected the field `array_string_extension_nullable` to be an array in the JSON string but got `%s`", jsonObj.get("array_string_extension_nullable").toString())); + } if ((jsonObj.get("string_nullable") != null && !jsonObj.get("string_nullable").isJsonNull()) && !jsonObj.get("string_nullable").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `string_nullable` to be a primitive type in the JSON string but got `%s`", jsonObj.get("string_nullable").toString())); } diff --git a/samples/client/echo_api/python-nextgen/docs/DefaultValue.md b/samples/client/echo_api/python-nextgen/docs/DefaultValue.md index 474a036bab8..fcdbebf0e0a 100644 --- a/samples/client/echo_api/python-nextgen/docs/DefaultValue.md +++ b/samples/client/echo_api/python-nextgen/docs/DefaultValue.md @@ -11,6 +11,7 @@ Name | Type | Description | Notes **array_integer_default** | **List[int]** | | [optional] [default to [1,3]] **array_string** | **List[str]** | | [optional] **array_string_nullable** | **List[str]** | | [optional] +**array_string_extension_nullable** | **List[str]** | | [optional] **string_nullable** | **str** | | [optional] ## Example diff --git a/samples/client/echo_api/python-nextgen/openapi_client/models/default_value.py b/samples/client/echo_api/python-nextgen/openapi_client/models/default_value.py index 61582bdcb70..ffe04f36996 100644 --- a/samples/client/echo_api/python-nextgen/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python-nextgen/openapi_client/models/default_value.py @@ -34,8 +34,9 @@ class DefaultValue(BaseModel): array_integer_default: Optional[List[StrictInt]] = None array_string: Optional[List[StrictStr]] = None array_string_nullable: Optional[List[StrictStr]] = None + array_string_extension_nullable: Optional[List[StrictStr]] = None string_nullable: Optional[StrictStr] = None - __properties = ["array_string_enum_ref_default", "array_string_enum_default", "array_string_default", "array_integer_default", "array_string", "array_string_nullable", "string_nullable"] + __properties = ["array_string_enum_ref_default", "array_string_enum_default", "array_string_default", "array_integer_default", "array_string", "array_string_nullable", "array_string_extension_nullable", "string_nullable"] @validator('array_string_enum_default') def array_string_enum_default_validate_enum(cls, v): @@ -73,6 +74,10 @@ class DefaultValue(BaseModel): if self.array_string_nullable is None: _dict['array_string_nullable'] = None + # set to None if array_string_extension_nullable (nullable) is None + if self.array_string_extension_nullable is None: + _dict['array_string_extension_nullable'] = None + # set to None if string_nullable (nullable) is None if self.string_nullable is None: _dict['string_nullable'] = None @@ -95,6 +100,7 @@ class DefaultValue(BaseModel): "array_integer_default": obj.get("array_integer_default"), "array_string": obj.get("array_string"), "array_string_nullable": obj.get("array_string_nullable"), + "array_string_extension_nullable": obj.get("array_string_extension_nullable"), "string_nullable": obj.get("string_nullable") }) return _obj