Skip to content

feat(serializer): embed relation labels in collection responses - #15

Merged
schmunk42 merged 2 commits into
masterfrom
feature/relation-labels
Oct 15, 2026
Merged

schmunk42 merged 2 commits into
masterfrom
feature/relation-labels

Conversation

@schmunk42

@schmunk42 schmunk42 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

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): RelationLabelNormalizer decorates api_platform.jsonld.normalizer.item and embeds {"@id": <iri>, <label>: <value>} for to-one relations in JSON-LD collection responses. Item responses keep plain IRIs, so forms (iri-reference strings) and writes are unaffected; API Platform rejects nested documents on write anyway.
  • x-label-property on the resource's own definition, so clients can title a record the same way a relation to it is labelled.
  • RelationLabelPropertyResolver holds the label inference, shared by RelationFieldSchemaDecorator and 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

schmunk42 and others added 2 commits October 14, 2026 23:16
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>
@schmunk42
schmunk42 merged commit c2782ed into master Oct 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant