From 03c7e3ea0bc1b83d456c4f15f6c26f5a74e04d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Fri, 5 Aug 2016 10:35:11 +0200 Subject: [PATCH] [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. --- .../src/main/resources/php/model_generic.mustache | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache index 27f66e8683b..c0ab1cd47e0 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache @@ -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}}