mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-28 19:50:49 +00:00
[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}}
|
||||
$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
|
||||
{{^isContainer}}
|
||||
if (!in_array(${{{name}}}, $allowed_values)) {
|
||||
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}}
|
||||
{{#hasValidation}}
|
||||
{{#maxLength}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user