Skip to content

Update yaml operations #1611

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

Closed

Conversation

jorissae
Copy link
Contributor

Hello team, I need to create the same operation with different uriTemplate for the same resource.

In the doc I see:

#[GetCollection] // auto-generated path will be /users
#[Get] // auto-generated path will be /users/{id}
#[GetCollection(uriTemplate: '/companies/{companyId}/users', itemUriTemplate: '/companies/{companyId}/users/{id}'/*, ... */)]
#[Post(uriTemplate: '/companies/{companyId}/users', itemUriTemplate: '/companies/{companyId}/users/{id}'/*, ... */)]
#[Get(uriTemplate: '/companies/{companyId}/users/{id}'/*, ... */)]
class User
{
    //...
}

But I use yaml and the doc show:


resources:
    App\Entity\Book:
        - operations:
            ApiPlatform\Metadata\GetCollection: ~
            ApiPlatform\Metadata\Get: ~
        - operations:
            ApiPlatform\Metadata\GetCollection:
                uriTemplate: /companies/{companyId}/users
                itemUriTemplate: /companies/{companyId}/users/{id}
                # ...
            ApiPlatform\Metadata\Post:
                uriTemplate: /companies/{companyId}/users
                itemUriTemplate: /companies/{companyId}/users/{id}
                # ...
            ApiPlatform\Metadata\Get:
                uriTemplate: /companies/{companyId}/users/{id}

I try it but I have the error:

ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory::create(): Argument #2 ($property) must be of type string, int given, called in /var/www/html/vendor/api-platform/core/src/Core/Operation/Factory/SubresourceOperationFactory.php on line 79

I finally succeeded with the code that I propose

Thanks

@vincentchalamon
Copy link
Contributor

Hi @jorissae,
I cannot reproduce your bug, can you create a sample project which reproduces this bug please?

@alanpoulain alanpoulain closed this Nov 2, 2022
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.

3 participants