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 17c1756d9ee2..2e8815959a45 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 @@ -235,6 +235,7 @@ public Map updateAllModels(Map objs) { allModels.put(modelName, cm); } } + // Fix up all parent and interface CodegenModel references. for (CodegenModel cm : allModels.values()) { if (cm.getParent() != null) { @@ -250,6 +251,7 @@ public Map updateAllModels(Map objs) { } } } + // Let parent know about all its children for (String name : allModels.keySet()) { CodegenModel cm = allModels.get(name); @@ -1820,7 +1822,7 @@ private CodegenDiscriminator createDiscriminator(String schemaName, Schema return null; } CodegenDiscriminator discriminator = new CodegenDiscriminator(); - discriminator.setPropertyName(schema.getDiscriminator().getPropertyName()); + discriminator.setPropertyName(toVarName(schema.getDiscriminator().getPropertyName())); discriminator.setMapping(schema.getDiscriminator().getMapping()); if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) { for (Entry e : schema.getDiscriminator().getMapping().entrySet()) { diff --git a/modules/openapi-generator/src/main/resources/php/model_generic.mustache b/modules/openapi-generator/src/main/resources/php/model_generic.mustache index 85610c2f5725..98a892cb927c 100644 --- a/modules/openapi-generator/src/main/resources/php/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php/model_generic.mustache @@ -166,8 +166,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{#discriminator}} // Initialize discriminator property with the model name. - $discriminator = array_search('{{discriminatorName}}', self::$attributeMap, true); - $this->container[$discriminator] = static::$openAPIModelName; + $this->container['{{discriminatorName}}'] = static::$openAPIModelName; {{/discriminator}} } 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 79e0f3ca17e9..6a3f790cdbaa 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 @@ -534,7 +534,7 @@ public void testLeadingSlashIsAddedIfMissing() { private void verifyPersonDiscriminator(CodegenDiscriminator discriminator) { CodegenDiscriminator test = new CodegenDiscriminator(); - test.setPropertyName("$_type"); + test.setPropertyName("DollarUnderscoretype"); test.setMapping(new HashMap<>()); test.getMapping().put("a", "#/components/schemas/Adult"); test.getMapping().put("c", "#/components/schemas/Child"); diff --git a/modules/openapi-generator/src/test/resources/3_0/allOfMultiParent.yaml b/modules/openapi-generator/src/test/resources/3_0/allOfMultiParent.yaml index 7e10f022581e..4d5abd85edd3 100644 --- a/modules/openapi-generator/src/test/resources/3_0/allOfMultiParent.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/allOfMultiParent.yaml @@ -44,9 +44,9 @@ components: firstName: type: string duplicated_optional: - type: string + type: integer duplicated_required: - type: string + type: integer person_required: type: string format: date-time diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/Animal.cs index d5279dbdb81c..16c89207e31d 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/Animal.cs @@ -29,7 +29,7 @@ namespace Org.OpenAPITools.Model /// Animal /// [DataContract] - [JsonConverter(typeof(JsonSubtypes), "className")] + [JsonConverter(typeof(JsonSubtypes), "ClassName")] [JsonSubtypes.KnownSubType(typeof(Dog), "Dog")] [JsonSubtypes.KnownSubType(typeof(Cat), "Cat")] public partial class Animal : IEquatable, IValidatableObject diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php index 74db144c025b..f343949dcbf9 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php @@ -42,7 +42,7 @@ */ class Animal implements ModelInterface, ArrayAccess { - const DISCRIMINATOR = 'className'; + const DISCRIMINATOR = 'class_name'; /** * The original name of the model. @@ -186,8 +186,7 @@ public function __construct(array $data = null) $this->container['color'] = isset($data['color']) ? $data['color'] : 'red'; // Initialize discriminator property with the model name. - $discriminator = array_search('className', self::$attributeMap, true); - $this->container[$discriminator] = static::$openAPIModelName; + $this->container['class_name'] = static::$openAPIModelName; } /** diff --git a/samples/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/client/petstore/ruby/lib/petstore/models/animal.rb index 31eaba3f8b39..249b69c656ae 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/animal.rb @@ -36,7 +36,7 @@ def self.openapi_types # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name - :'className' + :'class_name' end # Initializes the object diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php index 74db144c025b..f343949dcbf9 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php @@ -42,7 +42,7 @@ */ class Animal implements ModelInterface, ArrayAccess { - const DISCRIMINATOR = 'className'; + const DISCRIMINATOR = 'class_name'; /** * The original name of the model. @@ -186,8 +186,7 @@ public function __construct(array $data = null) $this->container['color'] = isset($data['color']) ? $data['color'] : 'red'; // Initialize discriminator property with the model name. - $discriminator = array_search('className', self::$attributeMap, true); - $this->container[$discriminator] = static::$openAPIModelName; + $this->container['class_name'] = static::$openAPIModelName; } /** diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb index 31eaba3f8b39..249b69c656ae 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb @@ -36,7 +36,7 @@ def self.openapi_types # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name - :'className' + :'class_name' end # Initializes the object