Skip to content

fix(symfony): fix property restrictions for root resource with dynamic validation groups #7184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/Resources/config/metadata/validator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<argument type="service" id="validator" />
<argument type="service" id="api_platform.metadata.property.metadata_factory.validator.inner" />
<argument type="tagged_iterator" tag="api_platform.metadata.property_schema_restriction" />
<argument type="tagged_locator" tag="api_platform.validation_groups_generator" />
</service>

<service id="api_platform.metadata.property_schema.choice_restriction" class="ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaChoiceRestriction" public="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Bic;
use Symfony\Component\Validator\Constraints\CardScheme;
Expand Down Expand Up @@ -72,7 +73,7 @@ final class ValidatorPropertyMetadataFactory implements PropertyMetadataFactoryI
/**
* @param PropertySchemaRestrictionMetadataInterface[] $restrictionsMetadata
*/
public function __construct(private readonly ValidatorMetadataFactoryInterface $validatorMetadataFactory, private readonly PropertyMetadataFactoryInterface $decorated, private readonly iterable $restrictionsMetadata = [])
public function __construct(private readonly ValidatorMetadataFactoryInterface $validatorMetadataFactory, private readonly PropertyMetadataFactoryInterface $decorated, private readonly iterable $restrictionsMetadata = [], private readonly ?ContainerInterface $container = null)
{
}

Expand Down Expand Up @@ -153,7 +154,18 @@ private function getValidationGroups(ValidatorClassMetadataInterface $classMetad
{
if (
isset($options['validation_groups'])
&& !\is_callable($options['validation_groups'])
&& (
!\is_callable($options['validation_groups'])
&& !(
1 === \count($options['validation_groups'])
&& null !== ($validationGroups = $options['validation_groups'][0] ?? null)
&& $this->container
&& \is_string($validationGroups)
&& $this->container->has($validationGroups)
&& ($service = $this->container->get($validationGroups))
&& \is_callable($service)
)
)
) {
return $options['validation_groups'];
}
Expand Down
Loading