api-platform / api-platform/core
IRI of entities with custom controller contain route/path information
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 980
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 48
Description
**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 fixed`uriTemplate` 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.
Contributor guide
Assessment
This issue has not been assessed yet.