From 509471de37626558a5c47f96fff5e824e4a0e04d Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Mar 2023 17:50:17 +0800 Subject: [PATCH 1/3] fix allOf handling in fromProperty --- .../org/openapitools/codegen/DefaultCodegen.java | 4 ++-- .../org/openapitools/codegen/DefaultCodegenTest.java | 12 ++++++++++++ .../src/test/resources/3_0/issue-5676-enums.yaml | 3 +++ 3 files changed, 17 insertions(+), 2 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 241e0626b788..ca78f683cec8 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 @@ -3791,7 +3791,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo Schema original = null; // check if it's allOf (only 1 sub schema) with default/nullable/etc set in the top level - if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1 && ModelUtils.hasCommonAttributesDefined(p) ) { + if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1) { if (p.getAllOf().get(0) instanceof Schema) { original = p; p = (Schema) p.getAllOf().get(0); @@ -3997,7 +3997,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo // restore original schema with default value, nullable, readonly etc if (original != null) { p = original; - // evaluate common attributes defined in the top level + // evaluate common attributes if defined in the top level if (p.getNullable() != null) { property.isNullable = p.getNullable(); } else if (p.getExtensions() != null && p.getExtensions().containsKey("x-nullable")) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 107fd4e72c40..799d564ada53 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -4587,6 +4587,18 @@ public void testAllOfDefaultEnumType() { Assert.assertFalse(defaultEnumSchemaProperty.isContainer); Assert.assertFalse(defaultEnumSchemaProperty.isPrimitiveType); Assert.assertEquals(defaultEnumSchemaProperty.defaultValue, "2"); + + // test allOf with a single sub-schema and no default value set in the top level + CodegenProperty allOfEnumSchemaProperty = modelWithReferencedSchema.vars.get(5); + Assert.assertEquals(allOfEnumSchemaProperty.getName(), "allofMinusnumberMinusenum"); + Assert.assertFalse(allOfEnumSchemaProperty.isEnum); + Assert.assertTrue(allOfEnumSchemaProperty.getIsEnumOrRef()); + Assert.assertTrue(allOfEnumSchemaProperty.isEnumRef); + Assert.assertFalse(allOfEnumSchemaProperty.isInnerEnum); + Assert.assertFalse(allOfEnumSchemaProperty.isString); + Assert.assertFalse(allOfEnumSchemaProperty.isContainer); + Assert.assertFalse(allOfEnumSchemaProperty.isPrimitiveType); + Assert.assertEquals(allOfEnumSchemaProperty.defaultValue, "null"); } @Test diff --git a/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml b/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml index cbfa2e6000e9..68746de926e5 100644 --- a/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml @@ -215,4 +215,7 @@ components: default: 2 allOf: - $ref: "#/components/schemas/NumberEnum" + allof-number-enum: + allOf: + - $ref: "#/components/schemas/NumberEnum" From 7c678452349efbd9e22b365e9c948b41970ac47a Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Mar 2023 18:11:59 +0800 Subject: [PATCH 2/3] add null check, update samples --- .../codegen/languages/AbstractDartCodegen.java | 4 +++- .../lib/src/model/all_of_with_single_ref.dart | 9 +++++++++ .../lib/src/model/all_of_with_single_ref.dart | 2 ++ .../generated/3_0/model/AllOfWithSingleRef.cpp | 5 +---- .../cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h | 3 ++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java index 9ddfc6e42c99..30c66569c3cb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java @@ -545,7 +545,9 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert property.items.setEnumName(enumName); } else { // plain enum property - property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, enumName)); + if (property.enumName != null) { + property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, enumName)); + } } property.setEnumName(enumName); } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart index dd3a19e9d93f..76b513437efe 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart @@ -70,4 +70,13 @@ class AllOfWithSingleRef { } +enum AllOfWithSingleRefnull { + @JsonValue(r'admin') + admin, + @JsonValue(r'user') + user, + @JsonValue(r'unknown_default_open_api') + unknownDefaultOpenApi, +} + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart index 04f59d360128..3c8bbe966ee8 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart @@ -3,6 +3,7 @@ // // ignore_for_file: unused_element +import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/single_ref_type.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -21,6 +22,7 @@ abstract class AllOfWithSingleRef implements Built #include #include +#include #include #include #include @@ -63,7 +64,6 @@ ptree AllOfWithSingleRef::toPropertyTree() const ptree pt; ptree tmp_node; pt.put("username", m_Username); - pt.add_child("SingleRefType", m_SingleRefType.toPropertyTree()); return pt; } @@ -71,9 +71,6 @@ void AllOfWithSingleRef::fromPropertyTree(ptree const &pt) { ptree tmp_node; m_Username = pt.get("username", ""); - if (pt.get_child_optional("SingleRefType")) { - m_SingleRefType = fromPt(pt.get_child("SingleRefType")); - } } std::string AllOfWithSingleRef::getUsername() const diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h index 7c4c278079d2..9d0052abb415 100644 --- a/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h @@ -25,6 +25,7 @@ #include "SingleRefType.h" #include #include +#include #include #include "helpers.h" @@ -72,7 +73,7 @@ class AllOfWithSingleRef protected: std::string m_Username = ""; - SingleRefType m_SingleRefType; + SingleRefType m_SingleRefType = SingleRefType{}; }; std::vector createAllOfWithSingleRefVectorFromJsonString(const std::string& json); From be2239c2499a3dcd99091d80e9aed71166da61eb Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Mar 2023 18:36:43 +0800 Subject: [PATCH 3/3] update dart generator to handle allof with a single ref --- .../openapitools/codegen/DefaultCodegen.java | 5 +++-- .../languages/AbstractDartCodegen.java | 8 +++---- .../model/all_of_with_single_ref.ex | 6 +++-- .../mp/docs/AllOfWithSingleRef.md | 2 +- .../se/docs/AllOfWithSingleRef.md | 2 +- .../docs/AllOfWithSingleRef.md | 2 +- .../client/model/AllOfWithSingleRef.java | 7 +++++- .../docs/AllOfWithSingleRef.md | 2 +- .../java/webclient/docs/AllOfWithSingleRef.md | 2 +- .../docs/Model/AllOfWithSingleRef.md | 2 +- .../lib/Model/AllOfWithSingleRef.php | 6 ++--- .../petstore/models/all_of_with_single_ref.rb | 22 +++++++++++++++++++ .../petstore/models/all_of_with_single_ref.rb | 22 +++++++++++++++++++ .../petstore/models/all_of_with_single_ref.rb | 22 +++++++++++++++++++ .../lib/src/model/all_of_with_single_ref.dart | 11 ---------- .../lib/src/model/all_of_with_single_ref.dart | 1 - .../lib/model/all_of_with_single_ref.dart | 6 +++++ .../models/all_of_with_single_ref.py | 10 ++++----- .../models/all_of_with_single_ref.py | 10 ++++----- .../server/model/AllOfWithSingleRef.java | 2 ++ .../server/model/AllOfWithSingleRef.java | 2 ++ .../model/AllOfWithSingleRef.java | 1 + .../lib/app/Models/AllOfWithSingleRef.php | 2 +- 23 files changed, 111 insertions(+), 44 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 ca78f683cec8..4b4dd2f44053 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 @@ -50,6 +50,7 @@ import org.openapitools.codegen.api.TemplatingEngineAdapter; import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.examples.ExampleGenerator; +import org.openapitools.codegen.languages.PythonClientCodegen; import org.openapitools.codegen.languages.RustServerCodegen; import org.openapitools.codegen.meta.FeatureSet; import org.openapitools.codegen.meta.GeneratorMetadata; @@ -3790,8 +3791,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo } Schema original = null; - // check if it's allOf (only 1 sub schema) with default/nullable/etc set in the top level - if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1) { + // check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level + if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1 && !(this instanceof PythonClientCodegen)) { if (p.getAllOf().get(0) instanceof Schema) { original = p; p = (Schema) p.getAllOf().get(0); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java index 30c66569c3cb..e542f21b74fb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java @@ -545,9 +545,7 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert property.items.setEnumName(enumName); } else { // plain enum property - if (property.enumName != null) { - property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, enumName)); - } + property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.enumName, enumName)); } property.setEnumName(enumName); } @@ -557,8 +555,8 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert public CodegenProperty fromProperty(String name, Schema p, boolean required) { final CodegenProperty property = super.fromProperty(name, p, required); - // Handle composed properties - if (ModelUtils.isComposedSchema(p)) { + // Handle composed properties and it's NOT allOf with a single ref only + if (ModelUtils.isComposedSchema(p) && !(ModelUtils.isAllOf(p) && p.getAllOf().size() == 1)) { ComposedSchema composed = (ComposedSchema) p; // Count the occurrences of allOf/anyOf/oneOf with exactly one child element diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex index df660951bc44..cb9ace8ec80c 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex @@ -14,13 +14,15 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do @type t :: %__MODULE__{ :username => String.t | nil, - :SingleRefType => any() | nil + :SingleRefType => OpenapiPetstore.Model.SingleRefType.t | nil } end defimpl Poison.Decoder, for: OpenapiPetstore.Model.AllOfWithSingleRef do - def decode(value, _options) do + import OpenapiPetstore.Deserializer + def decode(value, options) do value + |> deserialize(:SingleRefType, :struct, OpenapiPetstore.Model.SingleRefType, options) end end diff --git a/samples/client/petstore/java-helidon-client/mp/docs/AllOfWithSingleRef.md b/samples/client/petstore/java-helidon-client/mp/docs/AllOfWithSingleRef.md index 0a9e61bc682d..4146d56a372b 100644 --- a/samples/client/petstore/java-helidon-client/mp/docs/AllOfWithSingleRef.md +++ b/samples/client/petstore/java-helidon-client/mp/docs/AllOfWithSingleRef.md @@ -8,7 +8,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| |**username** | **String** | | [optional] | -|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] | +|**singleRefType** | **SingleRefType** | | [optional] | diff --git a/samples/client/petstore/java-helidon-client/se/docs/AllOfWithSingleRef.md b/samples/client/petstore/java-helidon-client/se/docs/AllOfWithSingleRef.md index 0a9e61bc682d..4146d56a372b 100644 --- a/samples/client/petstore/java-helidon-client/se/docs/AllOfWithSingleRef.md +++ b/samples/client/petstore/java-helidon-client/se/docs/AllOfWithSingleRef.md @@ -8,7 +8,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| |**username** | **String** | | [optional] | -|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] | +|**singleRefType** | **SingleRefType** | | [optional] | diff --git a/samples/client/petstore/java/apache-httpclient/docs/AllOfWithSingleRef.md b/samples/client/petstore/java/apache-httpclient/docs/AllOfWithSingleRef.md index 0a9e61bc682d..4146d56a372b 100644 --- a/samples/client/petstore/java/apache-httpclient/docs/AllOfWithSingleRef.md +++ b/samples/client/petstore/java/apache-httpclient/docs/AllOfWithSingleRef.md @@ -8,7 +8,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| |**username** | **String** | | [optional] | -|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] | +|**singleRefType** | **SingleRefType** | | [optional] | diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/AllOfWithSingleRef.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/AllOfWithSingleRef.java index 68f60026b899..bd81167203f3 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/AllOfWithSingleRef.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/AllOfWithSingleRef.java @@ -180,7 +180,12 @@ public String toUrlQueryString(String prefix) { // add `SingleRefType` to the URL query string if (getSingleRefType() != null) { - joiner.add(getSingleRefType().toUrlQueryString(prefix + "SingleRefType" + suffix)); + try { + joiner.add(String.format("%sSingleRefType%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getSingleRefType()), "UTF-8").replaceAll("\\+", "%20"))); + } catch (UnsupportedEncodingException e) { + // Should never happen, UTF-8 is always supported + throw new RuntimeException(e); + } } return joiner.toString(); diff --git a/samples/client/petstore/java/webclient-jakarta/docs/AllOfWithSingleRef.md b/samples/client/petstore/java/webclient-jakarta/docs/AllOfWithSingleRef.md index 0a9e61bc682d..4146d56a372b 100644 --- a/samples/client/petstore/java/webclient-jakarta/docs/AllOfWithSingleRef.md +++ b/samples/client/petstore/java/webclient-jakarta/docs/AllOfWithSingleRef.md @@ -8,7 +8,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| |**username** | **String** | | [optional] | -|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] | +|**singleRefType** | **SingleRefType** | | [optional] | diff --git a/samples/client/petstore/java/webclient/docs/AllOfWithSingleRef.md b/samples/client/petstore/java/webclient/docs/AllOfWithSingleRef.md index 0a9e61bc682d..4146d56a372b 100644 --- a/samples/client/petstore/java/webclient/docs/AllOfWithSingleRef.md +++ b/samples/client/petstore/java/webclient/docs/AllOfWithSingleRef.md @@ -8,7 +8,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| |**username** | **String** | | [optional] | -|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] | +|**singleRefType** | **SingleRefType** | | [optional] | diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/AllOfWithSingleRef.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/AllOfWithSingleRef.md index a8da431674c0..d8a2b54b5a01 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/AllOfWithSingleRef.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/AllOfWithSingleRef.md @@ -5,6 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **username** | **string** | | [optional] -**single_ref_type** | [**SingleRefType**](SingleRefType.md) | | [optional] +**single_ref_type** | [**\OpenAPI\Client\Model\SingleRefType**](SingleRefType.md) | | [optional] [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AllOfWithSingleRef.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AllOfWithSingleRef.php index e217bd93f3cd..1615517c1109 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AllOfWithSingleRef.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AllOfWithSingleRef.php @@ -58,7 +58,7 @@ class AllOfWithSingleRef implements ModelInterface, ArrayAccess, \JsonSerializab */ protected static $openAPITypes = [ 'username' => 'string', - 'single_ref_type' => 'SingleRefType' + 'single_ref_type' => '\OpenAPI\Client\Model\SingleRefType' ]; /** @@ -326,7 +326,7 @@ public function setUsername($username) /** * Gets single_ref_type * - * @return SingleRefType|null + * @return \OpenAPI\Client\Model\SingleRefType|null */ public function getSingleRefType() { @@ -336,7 +336,7 @@ public function getSingleRefType() /** * Sets single_ref_type * - * @param SingleRefType|null $single_ref_type single_ref_type + * @param \OpenAPI\Client\Model\SingleRefType|null $single_ref_type single_ref_type * * @return self */ diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb index ea186df537a6..4ee2a0ec2050 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb @@ -19,6 +19,28 @@ class AllOfWithSingleRef attr_accessor :single_ref_type + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb index ea186df537a6..4ee2a0ec2050 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb @@ -19,6 +19,28 @@ class AllOfWithSingleRef attr_accessor :single_ref_type + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb index ea186df537a6..4ee2a0ec2050 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb @@ -19,6 +19,28 @@ class AllOfWithSingleRef attr_accessor :single_ref_type + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart index 76b513437efe..b654a66733e9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart @@ -69,14 +69,3 @@ class AllOfWithSingleRef { } - -enum AllOfWithSingleRefnull { - @JsonValue(r'admin') - admin, - @JsonValue(r'user') - user, - @JsonValue(r'unknown_default_open_api') - unknownDefaultOpenApi, -} - - diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart index 3c8bbe966ee8..5bcd7d9dee8a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart @@ -3,7 +3,6 @@ // // ignore_for_file: unused_element -import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/single_ref_type.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/all_of_with_single_ref.dart index e98860d25a8d..c21911eeec80 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/all_of_with_single_ref.dart @@ -25,6 +25,12 @@ class AllOfWithSingleRef { /// String? username; + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// SingleRefType? singleRefType; @override diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/all_of_with_single_ref.py index a68465d4aac6..c6826c1a651d 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/all_of_with_single_ref.py @@ -19,15 +19,16 @@ import json -from typing import Any, Optional +from typing import Optional from pydantic import BaseModel, Field, StrictStr +from petstore_api.models.single_ref_type import SingleRefType class AllOfWithSingleRef(BaseModel): """ AllOfWithSingleRef """ username: Optional[StrictStr] = None - single_ref_type: Optional[Any] = Field(None, alias="SingleRefType") + single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType") __properties = ["username", "SingleRefType"] class Config: @@ -53,9 +54,6 @@ def to_dict(self): exclude={ }, exclude_none=True) - # override the default output from pydantic by calling `to_dict()` of single_ref_type - if self.single_ref_type: - _dict['SingleRefType'] = self.single_ref_type.to_dict() return _dict @classmethod @@ -69,7 +67,7 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef: _obj = AllOfWithSingleRef.parse_obj({ "username": obj.get("username"), - "single_ref_type": SingleRefType.from_dict(obj.get("SingleRefType")) if obj.get("SingleRefType") is not None else None + "single_ref_type": obj.get("SingleRefType") }) return _obj diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_single_ref.py index 9b0dca364e59..7480ccec361d 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_single_ref.py @@ -19,15 +19,16 @@ import json -from typing import Any, Optional +from typing import Optional from pydantic import BaseModel, Field, StrictStr +from petstore_api.models.single_ref_type import SingleRefType class AllOfWithSingleRef(BaseModel): """ AllOfWithSingleRef """ username: Optional[StrictStr] = None - single_ref_type: Optional[Any] = Field(None, alias="SingleRefType") + single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType") additional_properties: Dict[str, Any] = {} __properties = ["username", "SingleRefType"] @@ -55,9 +56,6 @@ def to_dict(self): "additional_properties" }, exclude_none=True) - # override the default output from pydantic by calling `to_dict()` of single_ref_type - if self.single_ref_type: - _dict['SingleRefType'] = self.single_ref_type.to_dict() # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: for _key, _value in self.additional_properties.items(): @@ -76,7 +74,7 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef: _obj = AllOfWithSingleRef.parse_obj({ "username": obj.get("username"), - "single_ref_type": SingleRefType.from_dict(obj.get("SingleRefType")) if obj.get("SingleRefType") is not None else None + "single_ref_type": obj.get("SingleRefType") }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java index c6f0778d346c..40e102a9cb32 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java @@ -12,6 +12,8 @@ package org.openapitools.server.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import org.openapitools.server.model.SingleRefType; import jakarta.validation.constraints.*; import jakarta.validation.Valid; diff --git a/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java b/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java index b40d9201c0e5..cdf67cc9aa49 100644 --- a/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java +++ b/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/AllOfWithSingleRef.java @@ -1,5 +1,7 @@ package org.openapitools.server.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import org.openapitools.server.model.SingleRefType; diff --git a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/AllOfWithSingleRef.java b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/AllOfWithSingleRef.java index fb68166b6b23..443173966fec 100644 --- a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/AllOfWithSingleRef.java +++ b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/AllOfWithSingleRef.java @@ -16,6 +16,7 @@ import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.openapitools.model.SingleRefType; diff --git a/samples/server/petstore/php-laravel/lib/app/Models/AllOfWithSingleRef.php b/samples/server/petstore/php-laravel/lib/app/Models/AllOfWithSingleRef.php index 90a2bca8d56f..97b38ffcf769 100644 --- a/samples/server/petstore/php-laravel/lib/app/Models/AllOfWithSingleRef.php +++ b/samples/server/petstore/php-laravel/lib/app/Models/AllOfWithSingleRef.php @@ -12,7 +12,7 @@ class AllOfWithSingleRef { /** @var string $username */ public $username = ""; - /** @var SingleRefType $singleRefType */ + /** @var \app\Models\SingleRefType $singleRefType */ public $singleRefType; }