Repository navigation
feat(serializer): embed relation labels in collection responses - #15
Merged
Merged
Conversation
Lists showed to-one relations as shortened IRIs: the schema names the
label property (x-label-property), but the response only carries the IRI.
- relation_labels (opt-in): RelationLabelNormalizer embeds
{"@id", <label>} for to-one relations in JSON-LD collection responses;
item responses keep plain IRIs, so forms and writes are unaffected
- x-label-property also on the resource's own definition, so clients can
title a record like a relation to it
- RelationLabelPropertyResolver shared by schema decorator and normalizer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Lists showed to-one relations as shortened IRIs: the schema names the label property (
x-label-property), but the response only carries the IRI.relation_labels(opt-in, default off):RelationLabelNormalizerdecoratesapi_platform.jsonld.normalizer.itemand embeds{"@id": <iri>, <label>: <value>}for to-one relations in JSON-LD collection responses. Item responses keep plain IRIs, so forms (iri-referencestrings) and writes are unaffected; API Platform rejects nested documents on write anyway.x-label-propertyon the resource's own definition, so clients can title a record the same way a relation to it is labelled.RelationLabelPropertyResolverholds the label inference, shared byRelationFieldSchemaDecoratorand the normalizer, so schema hint and embedded value always name the same property.Relations already embedded via serialization groups are left alone; a related row that cannot be loaded (e.g. hidden by row-level security) keeps its IRI. Each embedded label initialises the related entity (one query per distinct related row and page unless fetch-joined).
Tried in a downstream project (API Platform 4.4, Doctrine ORM 3, PostgreSQL with row-level security): list and detail views show labels, OpenAPI export carries the root hint. No new unit tests yet.
Release: 0.6.0 (CHANGELOG section included).
🤖 Generated with Claude Code