Repository navigation
Conversation
A property with an ApiProperty uriTemplate serializes as the IRI of a sub-resource collection. Expose that collection's POST and GET operations as supportedOperation on the hydra:Link, and stop listing the sub-resource as a phantom #Entrypoint property when they are attached.
soyuka
force-pushed
the
fix/hydra-subresource-link-operations
branch
from
November 26, 2026 08:53
9035c63 to
d1a7256
Compare
Only drop an operation from #Entrypoint when a property links to it and its URI template has variables, keyed by short name, method and template. Skip unreadable properties, keep a jsonldContext @type, and require api-platform/metadata ^5.0.1 for UriTemplateHelper.
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.
A sub-resource collection (
/books/{bookId}/reviews) is documented as#Entrypoint/review, a link the entrypoint never returns (GET /reviewsis a 404), while#Book/reviewsis a barehydra:Link. A Hydra client can't know it may POST a review to a book'sreviewslink.When a readable property declares
ApiProperty(uriTemplate: ...)it serializes as the collection IRI (same lookup asAbstractItemNormalizer, matched on the URI template), so the POST and GET collection operations sharing that uriTemplate are now documented assupportedOperationon thathydra:Link(Hydra Core §4.2, example 12, and §7 "or the target of the Hydra link"). An@typeset throughjsonldContextis kept.An operation is removed from
#Entrypoint/<name>only when it is attached to a property this way and its URI template has variables, i.e. it is not reachable from the entrypoint (same as whatEntrypointNormalizerlists). A top-level collection a property points to (/reviews) stays on the entrypoint and is also attached to the link. A sub-resource no property points to keeps its entrypoint entry, as it is the only place its POST/GET collection is documented. Without a propertyuriTemplatethe output is unchanged. No change toLinkdeclarations is needed.api-platform/hydranow requiresapi-platform/metadata ^5.0.1(UriTemplateHelper).Targets main because the docs output changes.
Tests:
src/Hydra/Tests/Serializer/DocumentationNormalizerTest.php(sub-resource linked, no property uriTemplate, top-level collection linked, operation of another resource on the same template, unreadable property,jsonldContext@type) andPropertyCollectionIriOnlyTest::testDocumentationAttachesUriTemplateOperationsToLinkson the existing fixtures.