diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index 2fd190b5e0e2..56993a8fc5a7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -331,7 +331,11 @@ public void setUnescapedDescription(String unescapedDescription) { this.unescapedDescription = unescapedDescription; } - public String getDiscriminator() { + public Discriminator getDiscriminator() { + return discriminator; + } + + public String getDiscriminatorName() { return discriminator == null ? null : discriminator.getPropertyName(); } 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 c9300084b0f7..375a216b4097 100644 --- a/modules/openapi-generator/src/main/resources/php/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php/model_generic.mustache @@ -1,6 +1,6 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^parentSchema}}implements ModelInterface, ArrayAccess{{/parentSchema}} { - const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}}; + const DISCRIMINATOR = {{#discriminator}}'{{discriminatorName}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}}; /** * The original name of the model. @@ -166,7 +166,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{#discriminator}} // Initialize discriminator property with the model name. - $discriminator = array_search('{{discriminator}}', self::$attributeMap); + $discriminator = array_search('{{discriminatorName}}', self::$attributeMap); $this->container[$discriminator] = static::$swaggerModelName; {{/discriminator}} }