Skip to content

IRI of entities with custom controller contain route/path information #8075

Description

@joerndyherrn

API Platform version(s) affected: 3.1.9

Description
Operations with a custom controller return entities with iris that match the uriTemplate.

How to reproduce
I got the following api resource:

#[ApiResource(
    operations: [
        new GetCollection(
            uriTemplate: '/substitutes/substituting',
            controller: SubstitutingApiController::class,
            normalizationContext: ['groups' => ['substituting_get']],
            name: 'substitutes_substituting',
        ),
        new Get(
            uriTemplate: '/substitutes/{id}/token',
            controller: SubstitutingTokenApiController::class,
            normalizationContext: ['groups' => ['substituting_get']],
            name: 'substitutes_substituting_token'
        ),
        new GetCollection(),
        new Get(),
    ])]

When caling /api/substitutes/substituting it will return a entity Substitute with @id: "/api/substitutes/0cbd07c8-e4e7-11ed-876f-b4af5186afd8/token" but should return @id: "/api/substitutes/0cbd07c8-e4e7-11ed-876f-b4af5186afd8"

When changing the order of the operations to have the following:

#[ApiResource(
    operations: [
        new GetCollection(),
        new Get(),
        new GetCollection(
            uriTemplate: '/substitutes/substituting',
            controller: SubstitutingApiController::class,
            normalizationContext: ['groups' => ['substituting_get']],
            name: 'substitutes_substituting',
        ),
        new Get(
            uriTemplate: '/substitutes/{id}/token',
            controller: SubstitutingTokenApiController::class,
            normalizationContext: ['groups' => ['substituting_get']],
            name: 'substitutes_substituting_token'
        ),
    ])]

For the default get and get collection operations it will generate correct iri. But now /api/substitutes/substituting is not callable as it tries to find an entity with id substituting

Possible Solution
When having the last tested order of operations - get collections with a fixeduriTemplate should be callable and not refer to the default get operation.
Another possible solution would be to fix iri generation to exclude any route information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions