forked from loafle/openapi-generator-original
[PHP] Fix enum validation in container setters
When the setter is taking an array as argument we cannot use `in_array()` to validate if the values are part of the allowed enum values. Instead we use `array_diff()` for containers now.
This commit is contained in:
parent
b74c1b98a2
commit
03c7e3ea0b
@ -238,9 +238,16 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
|||||||
{
|
{
|
||||||
{{#isEnum}}
|
{{#isEnum}}
|
||||||
$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
|
$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
|
||||||
|
{{^isContainer}}
|
||||||
if (!in_array(${{{name}}}, $allowed_values)) {
|
if (!in_array(${{{name}}}, $allowed_values)) {
|
||||||
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
|
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
|
||||||
}
|
}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{#isContainer}}
|
||||||
|
if (array_diff(${{{name}}}, $allowed_values)) {
|
||||||
|
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
|
||||||
|
}
|
||||||
|
{{/isContainer}}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{#hasValidation}}
|
{{#hasValidation}}
|
||||||
{{#maxLength}}
|
{{#maxLength}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user