Conversation
`itemUriTemplate` and `ApiProperty::uriTemplate` were compared to
`Operation::getUriTemplate()` with a strict `===`. Auto-generated
operations store the format suffix, so `itemUriTemplate: '/books/{id}'`
never matched `/books/{id}{._format}`. `OperationMetadataFactory::create()`
returned null and the IriConverter silently fell back to the resource's
default item operation, emitting a wrong IRI instead of an error.
`OperationMetadataFactory::create()` and
`ResourceMetadataCollection::getOperation()` now keep the first candidate
that matches once the `{._format}`/`.{_format}` suffix is stripped from
both sides, and return it only after the full scan finds no exact match,
so two operations differing only by the suffix keep their identities
whatever their declaration order.
soyuka
force-pushed
the
fix/item-uri-template-format-suffix
branch
from
September 18, 2026 09:23
50f74d4 to
b0e9e43
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
itemUriTemplateandApiProperty::uriTemplateare resolved to anOperationby comparing the configured string toOperation::getUriTemplate()with a strict===. Auto-generated operations store the format suffix, so this never matches:#[ApiResource(operations: [ new GetCollection(itemUriTemplate: '/books/{id}'), // stored target is '/books/{id}{._format}' new Get(), ])]OperationMetadataFactory::create()then returnsnull, andIriConverter::getIriFromResource()silently falls back to the resource's default item operation. The result is a wrong@id, not an error — which is why this is easy to miss. The same strict comparison inResourceMetadataCollection::getOperation()affectsApiProperty::uriTemplatein the JSON-LD and JSON:API normalizers.Both call sites now keep the first candidate that matches once the
{._format}or.{_format}suffix is stripped from both sides, and return it only after the full scan has found no exact match. Exact matching therefore still wins globally, so two operations differing only by the suffix keep their identities whatever their declaration order. The suffix stripping lives in a new@internalApiPlatform\Metadata\Util\UriTemplateHelper, whichUriTemplateResourceMetadataCollectionFactorynow shares instead of carrying its own copy.Functional coverage is
tests/Functional/ItemUriTemplateWithoutFormatSuffixTest.php. Its fixture declares a collection whoseitemUriTemplateomits the suffix, plus two itemGETs so the fallback is observable. Before the fix:Unit tests cover the lenient hit, the
.{_format}spelling, exact-wins-over-lenient in both declaration orders, and the unchanged null/OperationNotFoundExceptionbehaviour for an unrelated template.