Skip to content

Fix documentation for using a service to generate validation groups #1638

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

Merged
merged 1 commit into from
Nov 10, 2022

Conversation

mark-gerarts
Copy link
Contributor

The documentation says the following annotation should be used if you want to dynamically set validation groups using a service:

#[ApiResource(validationContext: ['groups' => [AdminGroupsGenerator::class]])

However, this does not work. The API Platform validator only tries to fetch a service when a string is passed as groups:

if (
    $this->container &&
    \is_string($validationGroups) &&
    $this->container->has($validationGroups) &&
    ($service = $this->container->get($validationGroups)) &&
    \is_callable($service)
) {

The documentation says the following annotation should be used if you want to dynamically set validation groups using a service:

```php
#[ApiResource(validationContext: ['groups' => [AdminGroupsGenerator::class]])
```

However, this does not work. The API Platform validator only tries to fetch a service when a string is passed as `groups`:

```
if (
    $this->container &&
    \is_string($validationGroups) &&
    $this->container->has($validationGroups) &&
    ($service = $this->container->get($validationGroups)) &&
    \is_callable($service)
) {
```
@alanpoulain
Copy link
Member

alanpoulain commented Nov 2, 2022

I think we should change how it is handled by API Platform instead.

Edit: I've misunderstood the change, I think it is fine this way.

@alanpoulain alanpoulain merged commit 3050bed into api-platform:3.0 Nov 10, 2022
@alanpoulain
Copy link
Member

Thank you @mark-gerarts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants