Skip to content

Commit

Permalink
[FIX][PHP-NEXTGEN] Missing tagged union discriminator literal (#20343) (
Browse files Browse the repository at this point in the history
#20356)

* fix: #20343

* chore: apply correct formatting
chore: build and package

---------

Co-authored-by: Christian Ascone <[email protected]>

---------

Co-authored-by: Christian Ascone <[email protected]>
  • Loading branch information
brianferri and christianascone authored Dec 22, 2024
1 parent 4ea7f60 commit 401c8d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
return self::$openAPIModelName;
}

{{#discriminator}}
{{#discriminator.mappedModels}}
public const {{#lambda.uppercase}}{{discriminator.propertyName}}_{{#lambda.snakecase}}{{mappingName}}{{/lambda.snakecase}}{{/lambda.uppercase}} = '{{mappingName}}';
{{/discriminator.mappedModels}}
{{/discriminator}}
{{^discriminator}}
{{#vars}}
{{#isEnum}}
{{#allowableValues}}
Expand All @@ -199,6 +205,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
{{/allowableValues}}
{{/isEnum}}
{{/vars}}
{{/discriminator}}

{{#vars}}
{{#isEnum}}
Expand All @@ -210,8 +217,15 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
public function {{getter}}AllowableValues()
{
return [
{{#discriminator}}
{{#discriminator.mappedModels}}
self::{{#lambda.uppercase}}{{discriminator.propertyName}}_{{#lambda.snakecase}}{{mappingName}}{{/lambda.snakecase}}{{/lambda.uppercase}},{{^-last}}
{{/-last}}{{/discriminator.mappedModels}}
{{/discriminator}}
{{^discriminator}}
{{#allowableValues}}{{#enumVars}}self::{{enumName}}_{{{name}}},{{^-last}}
{{/-last}}{{/enumVars}}{{/allowableValues}}
{{/discriminator}}
];
}

Expand All @@ -233,18 +247,18 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
*/
public function __construct(array $data = null)
{
{{#discriminator}}
// Initialize discriminator property with the model name.
$this->container['{{discriminatorName}}'] = static::$openAPIModelName;

{{/discriminator}}
{{#parentSchema}}
parent::__construct($data);

{{/parentSchema}}
{{#vars}}
$this->setIfExists('{{name}}', $data ?? [], {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}});
{{/vars}}
{{#discriminator}}

// Initialize discriminator property with the model name.
$this->container['{{discriminatorName}}'] = static::$openAPIModelName;
{{/discriminator}}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public function getModelName(): string
return self::$openAPIModelName;
}

public const CLASS_NAME_CAT = 'CAT';
public const CLASS_NAME_DOG = 'DOG';

/**
* Associative array for storing property values
Expand All @@ -248,11 +250,11 @@ public function getModelName(): string
*/
public function __construct(array $data = null)
{
$this->setIfExists('class_name', $data ?? [], null);
$this->setIfExists('color', $data ?? [], 'red');

// Initialize discriminator property with the model name.
$this->container['class_name'] = static::$openAPIModelName;

$this->setIfExists('class_name', $data ?? [], null);
$this->setIfExists('color', $data ?? [], 'red');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ public function getTypeAllowableValues()
*/
public function __construct(array $data = null)
{
$this->setIfExists('type', $data ?? [], null);
$this->setIfExists('nullable_property', $data ?? [], null);

// Initialize discriminator property with the model name.
$this->container['type'] = static::$openAPIModelName;

$this->setIfExists('type', $data ?? [], null);
$this->setIfExists('nullable_property', $data ?? [], null);
}

/**
Expand Down

0 comments on commit 401c8d0

Please sign in to comment.