Skip to content

Commit 6b7c3d0

Browse files
authored
[php-symfony] fix sequencial escape when validating a class type (#22906)
* [php-symfony] do not interpret sequential escape * chore: update samples * refactor: add missing return type * [php-symfony] make template compatible with Symfony 8
1 parent a7d57ca commit 6b7c3d0

6 files changed

Lines changed: 26 additions & 26 deletions

File tree

modules/openapi-generator/src/main/resources/php-symfony/api_input_validation.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$asserts[] = new Assert\Type("\{{modelPackage}}\{{dataType}}");
4343
{{/isEnumRef}}
4444
{{^isEnumRef}}
45-
$asserts[] = new Assert\Type("{{dataType}}");
45+
$asserts[] = new Assert\Type('{{dataType}}');
4646
{{^isPrimitiveType}}
4747
$asserts[] = new Assert\Valid();
4848
{{/isPrimitiveType}}

modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AppKernel extends Kernel
2222
* @inheritDoc
2323
* @throws \Exception
2424
*/
25-
public function registerContainerConfiguration(LoaderInterface $loader)
25+
public function registerContainerConfiguration(LoaderInterface $loader): void
2626
{
2727
$loader->load(__DIR__.'/test_config.yaml');
2828
}

samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function addPetAction(Request $request)
9797
// Validate the input values
9898
$asserts = [];
9999
$asserts[] = new Assert\NotNull();
100-
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Pet");
100+
$asserts[] = new Assert\Type('OpenAPI\Server\Model\Pet');
101101
$asserts[] = new Assert\Valid();
102102
$response = $this->validate($pet, $asserts);
103103
if ($response instanceof Response) {
@@ -170,13 +170,13 @@ public function deletePetAction(Request $request, $petId)
170170
// Validate the input values
171171
$asserts = [];
172172
$asserts[] = new Assert\NotNull();
173-
$asserts[] = new Assert\Type("int");
173+
$asserts[] = new Assert\Type('int');
174174
$response = $this->validate($petId, $asserts);
175175
if ($response instanceof Response) {
176176
return $response;
177177
}
178178
$asserts = [];
179-
$asserts[] = new Assert\Type("string");
179+
$asserts[] = new Assert\Type('string');
180180
$response = $this->validate($apiKey, $asserts);
181181
if ($response instanceof Response) {
182182
return $response;
@@ -250,7 +250,7 @@ public function downloadFileAction(Request $request, $petId)
250250
// Validate the input values
251251
$asserts = [];
252252
$asserts[] = new Assert\NotNull();
253-
$asserts[] = new Assert\Type("int");
253+
$asserts[] = new Assert\Type('int');
254254
$response = $this->validate($petId, $asserts);
255255
if ($response instanceof Response) {
256256
return $response;
@@ -496,7 +496,7 @@ public function getPetByIdAction(Request $request, $petId)
496496
// Validate the input values
497497
$asserts = [];
498498
$asserts[] = new Assert\NotNull();
499-
$asserts[] = new Assert\Type("int");
499+
$asserts[] = new Assert\Type('int');
500500
$response = $this->validate($petId, $asserts);
501501
if ($response instanceof Response) {
502502
return $response;
@@ -573,7 +573,7 @@ public function petAgeAction(Request $request, $petId)
573573
// Validate the input values
574574
$asserts = [];
575575
$asserts[] = new Assert\NotNull();
576-
$asserts[] = new Assert\Type("int");
576+
$asserts[] = new Assert\Type('int');
577577
$response = $this->validate($petId, $asserts);
578578
if ($response instanceof Response) {
579579
return $response;
@@ -646,7 +646,7 @@ public function petAvailableForSaleAction(Request $request, $petId)
646646
// Validate the input values
647647
$asserts = [];
648648
$asserts[] = new Assert\NotNull();
649-
$asserts[] = new Assert\Type("int");
649+
$asserts[] = new Assert\Type('int');
650650
$response = $this->validate($petId, $asserts);
651651
if ($response instanceof Response) {
652652
return $response;
@@ -731,7 +731,7 @@ public function updatePetAction(Request $request)
731731
// Validate the input values
732732
$asserts = [];
733733
$asserts[] = new Assert\NotNull();
734-
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Pet");
734+
$asserts[] = new Assert\Type('OpenAPI\Server\Model\Pet');
735735
$asserts[] = new Assert\Valid();
736736
$response = $this->validate($pet, $asserts);
737737
if ($response instanceof Response) {
@@ -808,19 +808,19 @@ public function updatePetWithFormAction(Request $request, $petId)
808808
// Validate the input values
809809
$asserts = [];
810810
$asserts[] = new Assert\NotNull();
811-
$asserts[] = new Assert\Type("int");
811+
$asserts[] = new Assert\Type('int');
812812
$response = $this->validate($petId, $asserts);
813813
if ($response instanceof Response) {
814814
return $response;
815815
}
816816
$asserts = [];
817-
$asserts[] = new Assert\Type("string");
817+
$asserts[] = new Assert\Type('string');
818818
$response = $this->validate($name, $asserts);
819819
if ($response instanceof Response) {
820820
return $response;
821821
}
822822
$asserts = [];
823-
$asserts[] = new Assert\Type("string");
823+
$asserts[] = new Assert\Type('string');
824824
$response = $this->validate($status, $asserts);
825825
if ($response instanceof Response) {
826826
return $response;
@@ -900,13 +900,13 @@ public function uploadFileAction(Request $request, $petId)
900900
// Validate the input values
901901
$asserts = [];
902902
$asserts[] = new Assert\NotNull();
903-
$asserts[] = new Assert\Type("int");
903+
$asserts[] = new Assert\Type('int');
904904
$response = $this->validate($petId, $asserts);
905905
if ($response instanceof Response) {
906906
return $response;
907907
}
908908
$asserts = [];
909-
$asserts[] = new Assert\Type("string");
909+
$asserts[] = new Assert\Type('string');
910910
$response = $this->validate($additionalMetadata, $asserts);
911911
if ($response instanceof Response) {
912912
return $response;

samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function deleteOrderAction(Request $request, $orderId)
7575
// Validate the input values
7676
$asserts = [];
7777
$asserts[] = new Assert\NotNull();
78-
$asserts[] = new Assert\Type("string");
78+
$asserts[] = new Assert\Type('string');
7979
$response = $this->validate($orderId, $asserts);
8080
if ($response instanceof Response) {
8181
return $response;
@@ -212,7 +212,7 @@ public function getOrderByIdAction(Request $request, $orderId)
212212
// Validate the input values
213213
$asserts = [];
214214
$asserts[] = new Assert\NotNull();
215-
$asserts[] = new Assert\Type("int");
215+
$asserts[] = new Assert\Type('int');
216216
$asserts[] = new Assert\GreaterThanOrEqual(1);
217217
$asserts[] = new Assert\LessThanOrEqual(5);
218218
$response = $this->validate($orderId, $asserts);
@@ -298,7 +298,7 @@ public function placeOrderAction(Request $request)
298298
// Validate the input values
299299
$asserts = [];
300300
$asserts[] = new Assert\NotNull();
301-
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Order");
301+
$asserts[] = new Assert\Type('OpenAPI\Server\Model\Order');
302302
$asserts[] = new Assert\Valid();
303303
$response = $this->validate($order, $asserts);
304304
if ($response instanceof Response) {

samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function createUserAction(Request $request)
8787
// Validate the input values
8888
$asserts = [];
8989
$asserts[] = new Assert\NotNull();
90-
$asserts[] = new Assert\Type("OpenAPI\Server\Model\User");
90+
$asserts[] = new Assert\Type('OpenAPI\Server\Model\User');
9191
$asserts[] = new Assert\Valid();
9292
$response = $this->validate($user, $asserts);
9393
if ($response instanceof Response) {
@@ -316,7 +316,7 @@ public function deleteUserAction(Request $request, $username)
316316
// Validate the input values
317317
$asserts = [];
318318
$asserts[] = new Assert\NotNull();
319-
$asserts[] = new Assert\Type("string");
319+
$asserts[] = new Assert\Type('string');
320320
$response = $this->validate($username, $asserts);
321321
if ($response instanceof Response) {
322322
return $response;
@@ -391,7 +391,7 @@ public function getUserByNameAction(Request $request, $username)
391391
// Validate the input values
392392
$asserts = [];
393393
$asserts[] = new Assert\NotNull();
394-
$asserts[] = new Assert\Type("string");
394+
$asserts[] = new Assert\Type('string');
395395
$response = $this->validate($username, $asserts);
396396
if ($response instanceof Response) {
397397
return $response;
@@ -469,15 +469,15 @@ public function loginUserAction(Request $request)
469469
// Validate the input values
470470
$asserts = [];
471471
$asserts[] = new Assert\NotNull();
472-
$asserts[] = new Assert\Type("string");
472+
$asserts[] = new Assert\Type('string');
473473
$asserts[] = new Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/");
474474
$response = $this->validate($username, $asserts);
475475
if ($response instanceof Response) {
476476
return $response;
477477
}
478478
$asserts = [];
479479
$asserts[] = new Assert\NotNull();
480-
$asserts[] = new Assert\Type("string");
480+
$asserts[] = new Assert\Type('string');
481481
$response = $this->validate($password, $asserts);
482482
if ($response instanceof Response) {
483483
return $response;
@@ -609,14 +609,14 @@ public function updateUserAction(Request $request, $username)
609609
// Validate the input values
610610
$asserts = [];
611611
$asserts[] = new Assert\NotNull();
612-
$asserts[] = new Assert\Type("string");
612+
$asserts[] = new Assert\Type('string');
613613
$response = $this->validate($username, $asserts);
614614
if ($response instanceof Response) {
615615
return $response;
616616
}
617617
$asserts = [];
618618
$asserts[] = new Assert\NotNull();
619-
$asserts[] = new Assert\Type("OpenAPI\Server\Model\User");
619+
$asserts[] = new Assert\Type('OpenAPI\Server\Model\User');
620620
$asserts[] = new Assert\Valid();
621621
$response = $this->validate($user, $asserts);
622622
if ($response instanceof Response) {

samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function registerBundles(): iterable
2222
* @inheritDoc
2323
* @throws \Exception
2424
*/
25-
public function registerContainerConfiguration(LoaderInterface $loader)
25+
public function registerContainerConfiguration(LoaderInterface $loader): void
2626
{
2727
$loader->load(__DIR__.'/test_config.yaml');
2828
}

0 commit comments

Comments
 (0)