api-platform / api-platform/core

IRI of entities with custom controller contain route/path information

未關閉
#8,075 10 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
metadata
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。