API Platform version(s) affected: 4.1.16 and 4.1.17
Description
Hi team,
The recent PR #7184 introduced a change in the ApiPlatform\Symfony\Validator\Metadata\Property\ValidatorPropertyMetadataFactory class, where user-defined validation group callables are now invoked with a null argument.
This is a breaking change for existing projects. Previously, the callback did not need to support a nullable parameter.
There are two concerns here:
- This change seems unnecessary. Since validation groups are meant to be dynamically determined from the input data, it’s inherently impossible to compute them meaningfully when no actual data is available.
- It introduces unsafe behavior. Invoking user code with unexpected arguments, especially null, without an explicit contract is dangerous and error-prone.
How to reproduce
#[ApiResource(
validationContext: [
'groups' => [
SomeResource::class,
'getValidationGroups',
],
]
)]
class SomeResource
{
// Before: worked fine
public static function getValidationGroups(self $someResource): array
{
// ...
}
// After: now $someEntity must support null
public static function getValidationGroups(?self $someResource): array
{
// ...
}
}
Possible Solution
Please consider reverting this change.
Thanks for your work on API Platform!
API Platform version(s) affected: 4.1.16 and 4.1.17
Description
Hi team,
The recent PR #7184 introduced a change in the
ApiPlatform\Symfony\Validator\Metadata\Property\ValidatorPropertyMetadataFactoryclass, where user-defined validation group callables are now invoked with anullargument.This is a breaking change for existing projects. Previously, the callback did not need to support a nullable parameter.
There are two concerns here:
How to reproduce
#[ApiResource( validationContext: [ 'groups' => [ SomeResource::class, 'getValidationGroups', ], ] )] class SomeResource { // Before: worked fine public static function getValidationGroups(self $someResource): array { // ... } // After: now $someEntity must support null public static function getValidationGroups(?self $someResource): array { // ... } }Possible Solution
Please consider reverting this change.
Thanks for your work on API Platform!