From 1539b930c2a94cac403aa4999701d0815302f3e9 Mon Sep 17 00:00:00 2001 From: Florian Le Goff Date: Mon, 28 Oct 2024 15:12:52 +0100 Subject: [PATCH 1/5] chore(symfony): conflict with symfony/framework-bundle 7.1.6 (#6759) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1d092590e1..2f6b725b38 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "doctrine/orm": "<2.14.0", "doctrine/mongodb-odm": "<2.4", "doctrine/persistence": "<1.3", - "symfony/framework-bundle": "6.4.6 || 7.1.6", + "symfony/framework-bundle": "6.4.6 || 7.0.6", "symfony/var-exporter": "<6.1.1", "phpunit/phpunit": "<9.5", "phpspec/prophecy": "<1.15", From 9ba1ae102523f03f0821c41f8b7fea8abe71d879 Mon Sep 17 00:00:00 2001 From: Antoine Bluchet Date: Mon, 28 Oct 2024 15:14:16 +0100 Subject: [PATCH 2/5] chore(symfony): phpstan baseline for name converter interface (#6760) --- phpstan.neon.dist | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 09c73664f3..2dfec535ad 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -89,6 +89,17 @@ parameters: path: src/JsonApi/Tests/Serializer/ItemNormalizerTest.php - '#Method GraphQL\\Type\\Definition\\WrappingType::getWrappedType\(\) invoked with 1 parameter, 0 required\.#' - '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#' + - + message: '#Instanceof between Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface and Symfony\\Component\\Serializer\\NameConverter\\MetadataAwareNameConverter will always evaluate to false\.#' + paths: + - src/GraphQl/Serializer/SerializerContextBuilder.php + - src/GraphQl/Type/FieldsBuilder.php + - + message: '#Instanceof between Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface\|null and Symfony\\Component\\Serializer\\NameConverter\\MetadataAwareNameConverter will always evaluate to false\.#' + paths: + - src/Serializer/AbstractConstraintViolationListNormalizer.php + - src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.php + # See https://github.com/phpstan/phpstan-symfony/issues/27 - message: '#^Service "[^"]+" is private.$#' From 216d9ccaacf7845daaaeab30f3a58bb5567430fe Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Wed, 30 Oct 2024 10:50:39 +0100 Subject: [PATCH 3/5] fix(serializer): fetch type on normalization error when possible (#6761) --- features/main/validation.feature | 6 +++--- src/Serializer/AbstractItemNormalizer.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/features/main/validation.feature b/features/main/validation.feature index 8c6db85dcb..209d4fe2bc 100644 --- a/features/main/validation.feature +++ b/features/main/validation.feature @@ -114,11 +114,11 @@ Feature: Using validations groups "@context": "/contexts/ConstraintViolationList", "@type": "ConstraintViolationList", "hydra:title": "An error occurred", - "hydra:description": "This value should be of type unknown.\nqux: This value should be of type string.\nfoo: This value should be of type bool.\nbar: This value should be of type int.\nuuid: This value should be of type uuid.\nrelatedDummy: This value should be of type array|string.\nrelatedDummies: This value should be of type array.", + "hydra:description": "baz: This value should be of type string.\nqux: This value should be of type string.\nfoo: This value should be of type bool.\nbar: This value should be of type int.\nuuid: This value should be of type uuid.\nrelatedDummy: This value should be of type array|string.\nrelatedDummies: This value should be of type array.", "violations": [ { - "propertyPath": "", - "message": "This value should be of type unknown.", + "propertyPath": "baz", + "message": "This value should be of type string.", "code": "ba785a8c-82cb-4283-967c-3cf342181b40", "hint": "Failed to create object because the class misses the \"baz\" property." }, diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index e7ea362f98..09c16ce548 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -351,7 +351,20 @@ protected function instantiateObject(array &$data, string $class, array &$contex $missingConstructorArguments[] = $constructorParameter->name; } - $exception = NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name), $data, ['unknown'], $context['deserialization_path'] ?? null, true); + $attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context); + $constructorParameterType = 'unknown'; + $reflectionType = $constructorParameter->getType(); + if ($reflectionType instanceof \ReflectionNamedType) { + $constructorParameterType = $reflectionType->getName(); + } + + $exception = NotNormalizableValueException::createForUnexpectedDataType( + \sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name), + null, + [$constructorParameterType], + $attributeContext['deserialization_path'] ?? null, + true + ); $context['not_normalizable_value_exceptions'][] = $exception; } } From 736ca045e6832f04aaa002ddd7b85c55df4696bb Mon Sep 17 00:00:00 2001 From: Xavier Lacot Date: Wed, 30 Oct 2024 10:51:13 +0100 Subject: [PATCH 4/5] fix(validator): allow to pass both a ConstraintViolationList and a previous exception (#6762) --- src/Validator/Exception/ValidationException.php | 2 +- .../Tests/Exception/ValidationExceptionTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Validator/Exception/ValidationException.php b/src/Validator/Exception/ValidationException.php index 98117463ff..720f1f26ca 100644 --- a/src/Validator/Exception/ValidationException.php +++ b/src/Validator/Exception/ValidationException.php @@ -75,7 +75,7 @@ public function __construct(string|ConstraintViolationListInterface $message = ' if ($message instanceof ConstraintViolationListInterface) { $this->constraintViolationList = $message; - parent::__construct($code ?? $this->__toString(), $previous ?? 0, $errorTitle instanceof \Throwable ? $errorTitle : null); + parent::__construct($this->__toString(), $code ?? 0, $previous); return; } diff --git a/src/Validator/Tests/Exception/ValidationExceptionTest.php b/src/Validator/Tests/Exception/ValidationExceptionTest.php index 35afcd05cf..09c77a198f 100644 --- a/src/Validator/Tests/Exception/ValidationExceptionTest.php +++ b/src/Validator/Tests/Exception/ValidationExceptionTest.php @@ -39,4 +39,19 @@ public function testToString(): void TXT ), $e->__toString()); } + + public function testWithPrevious(): void + { + $previous = new \Exception(); + $e = new ValidationException(new ConstraintViolationList([ + new ConstraintViolation('message 1', '', [], '', '', 'invalid'), + ]), null, $previous); + $this->assertInstanceOf(\RuntimeException::class, $e); + + $this->assertSame(str_replace(\PHP_EOL, "\n", <<__toString()); + $this->assertSame($previous, $e->getPrevious()); + } } From 2f967d9345004779f409b9ce1b5d0cbba84c7132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 4 Nov 2024 15:19:45 +0100 Subject: [PATCH 5/5] fix(doctrine): throw an exception when a filter is not found in a parameter (#6767) --- src/Doctrine/Orm/Extension/ParameterExtension.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Doctrine/Orm/Extension/ParameterExtension.php b/src/Doctrine/Orm/Extension/ParameterExtension.php index aa65efbe57..6ae3a00100 100644 --- a/src/Doctrine/Orm/Extension/ParameterExtension.php +++ b/src/Doctrine/Orm/Extension/ParameterExtension.php @@ -16,6 +16,7 @@ use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait; use ApiPlatform\Doctrine\Orm\Filter\FilterInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; +use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ParameterNotFound; use Doctrine\ORM\QueryBuilder; @@ -50,9 +51,11 @@ private function applyFilter(QueryBuilder $queryBuilder, QueryNameGeneratorInter } $filter = $this->filterLocator->has($filterId) ? $this->filterLocator->get($filterId) : null; - if ($filter instanceof FilterInterface) { - $filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operation, ['filters' => $values, 'parameter' => $parameter] + $context); + if (!$filter instanceof FilterInterface) { + throw new InvalidArgumentException(\sprintf('Could not find filter "%s" for parameter "%s" in operation "%s" for resource "%s".', $filterId, $parameter->getKey(), $operation?->getShortName(), $resourceClass)); } + + $filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operation, ['filters' => $values, 'parameter' => $parameter] + $context); } }