api-platform / api-platform/core

IRI of entities with custom controller contain route/path information

Aberta
#8,075 10 comentários 2 reações 0 responsáveis Ver no GitHub
metadata
Linguagem predominante
PHP
Estrelas
2.6k
Forks
980
Merge médio
2d 5h
PRs com merge (30d)
48

Descrição

**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.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.