You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the php or php-nextgen generator and enabling enumUnknownDefaultCase, the setter for for enum properties throws an exception if the value is not one of the defined ones. Instead, it should return the unknown enum value.
While the following example output is related to the php generator, the same applies to the php-nextgen generator.
Expected output
publicfunctionsetColor($color)
{
if (is_null($color)) {
thrownew \InvalidArgumentException('non-nullable color cannot be null');
}
$allowedValues = $this->getColorAllowableValues();
if (!in_array($color, $allowedValues, true)) {
$color = self::COLOR_UNKNOWN_DEFAULT_OPEN_API;
}
$this->container['color'] = $color;
return$this;
}
Actual output
publicfunctionsetColor($color)
{
if (is_null($color)) {
thrownew \InvalidArgumentException('non-nullable color cannot be null');
}
$allowedValues = $this->getColorAllowableValues();
if (!in_array($color, $allowedValues, true)) {
thrownew \InvalidArgumentException(
sprintf(
"Invalid value '%s' for 'color', must be one of '%s'",
$color,
implode("', '", $allowedValues)
)
);
}
$this->container['color'] = $color;
return$this;
}
Apply the following diff in php/model_generic.mustache and php-nextgen/model_generic.mustache
if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}!in_array(${{{name}}}, $allowedValues, true)) {
+ {{#enumUnknownDefaultCase}}+ {{#allowableValues}}{{#enumVars}}{{#-last}}return self::{{enumName}}_{{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}+ {{/enumUnknownDefaultCase}}+ {{^enumUnknownDefaultCase}}
throw new \InvalidArgumentException(
sprintf(
"Invalid value '%s' for '{{name}}', must be one of '%s'",
${{{name}}},
implode("', '", $allowedValues)
)
);
+ {{/enumUnknownDefaultCase}}
}
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When using the
php
orphp-nextgen
generator and enablingenumUnknownDefaultCase
, the setter for for enum properties throws an exception if the value is not one of the defined ones. Instead, it should return the unknown enum value.While the following example output is related to the
php
generator, the same applies to thephp-nextgen
generator.Expected output
Actual output
openapi-generator version
7.12.0-SNAPSHOT
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
generate code
Related issues/PRs
microprofile
generatorSuggest a fix
Apply the following diff in
php/model_generic.mustache
andphp-nextgen/model_generic.mustache
The text was updated successfully, but these errors were encountered: