From d21b8d302c6d32d89c150f3bd522d5a8de136a85 Mon Sep 17 00:00:00 2001 From: Guillaume Turri Date: Sun, 12 Mar 2023 09:06:19 +0100 Subject: [PATCH] [PHP-Symfony] fixes validation of date-time parameter This fixes parts of #14930. Without this patch a parameter declared as date-time is validated against Symfony's "DateTime" constraint, which always fails. Because this constraint expects a string with format "Y-m-d H:i:s". It fails because the generated code performs the check after the deserialization, so the variable checked is not a string anymore. Besides this, even if we performed that validation on the string, that would not work well because OpenApi specification expects date-time to conform to RFC 3339 and that "Y-m-d H:i:s" would reject RFC 3339 compliant dates. With this change we ensure that the string provided by the web user could be parsed by PHP to DateTime, which solves both issues. (Note however that it means that it now accepts more formats than just RFC 3339 compliant ones for those parameters (it would accept all formats accepted by PHP DateTime). That being said it's compliant with the guideline ""be conservative in what you send, be liberal in what you accept") --- .../main/resources/php-symfony/api_input_validation.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_input_validation.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_input_validation.mustache index 299b64cd764a..3cda7622c716 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_input_validation.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_input_validation.mustache @@ -30,7 +30,7 @@ $asserts[] = new Assert\Date(); {{/isDate}} {{#isDateTime}} - $asserts[] = new Assert\DateTime(); + $asserts[] = new Assert\Type("DateTime"); {{/isDateTime}} {{^isDate}} {{^isDateTime}}