From 74e5c3ccd3c51e85efbf203b0bf7738dc23b1dbd Mon Sep 17 00:00:00 2001 From: vnq <28255343+vnq@users.noreply.github.com> Date: Wed, 24 Mar 2021 06:30:42 +0100 Subject: [PATCH] [php-symfony] remove nested Valid constraint (#8994) * Fix constraint Valid cannot be nested * Update PetController.php * Update UserController.php --- .../resources/php-symfony/api_input_validation.mustache | 6 +++--- .../SymfonyBundle-php/Controller/PetController.php | 2 ++ .../SymfonyBundle-php/Controller/UserController.php | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) 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 8c3a1d5e361..fca8dcd101b 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 @@ -19,11 +19,11 @@ {{#items}} $asserts[] = new Assert\All([ new Assert\Type("{{dataType}}"), - {{^isPrimitiveType}} - new Assert\Valid(), - {{/isPrimitiveType}} ]); {{/items}} + {{^isPrimitiveType}} + $asserts[] = new Assert\Valid(); + {{/isPrimitiveType}} {{/isContainer}} {{^isContainer}} {{#isDate}} diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php index ba7ecc50c5c..ca07f62678d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php @@ -257,6 +257,7 @@ class PetController extends Controller $asserts[] = new Assert\All([ new Assert\Type("string"), ]); + $asserts[] = new Assert\Valid(); $response = $this->validate($status, $asserts); if ($response instanceof Response) { return $response; @@ -345,6 +346,7 @@ class PetController extends Controller $asserts[] = new Assert\All([ new Assert\Type("string"), ]); + $asserts[] = new Assert\Valid(); $response = $this->validate($tags, $asserts); if ($response instanceof Response) { return $response; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php index 3328426b049..52af362ae34 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php @@ -163,8 +163,8 @@ class UserController extends Controller $asserts[] = new Assert\NotNull(); $asserts[] = new Assert\All([ new Assert\Type("OpenAPI\Server\Model\User"), - new Assert\Valid(), ]); + $asserts[] = new Assert\Valid(); $response = $this->validate($body, $asserts); if ($response instanceof Response) { return $response; @@ -242,8 +242,8 @@ class UserController extends Controller $asserts[] = new Assert\NotNull(); $asserts[] = new Assert\All([ new Assert\Type("OpenAPI\Server\Model\User"), - new Assert\Valid(), ]); + $asserts[] = new Assert\Valid(); $response = $this->validate($body, $asserts); if ($response instanceof Response) { return $response;