Skip to content

refactor(jsonapi): single source of truth for the attribute/relationship split#8325

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:feat/jsonapi-jsonschema-single-source
Jun 17, 2026
Merged

refactor(jsonapi): single source of truth for the attribute/relationship split#8325
soyuka merged 1 commit into
api-platform:4.3from
soyuka:feat/jsonapi-jsonschema-single-source

Conversation

@soyuka

@soyuka soyuka commented Jun 17, 2026

Copy link
Copy Markdown
Member
Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fixes #8322
License MIT

Follow-up to #8313 / #8321, surfaced while reviewing #8313.

Single source of truth for the attributes/relationships split

SchemaFactory::getRelationship() recomputed the attributes-vs-relationships partition from getNativeType()/getBuiltinTypes() — a near-verbatim copy of the runtime split in ItemNormalizer::getComponents(). The two implementations could drift on any change (collection handling, union/intersection types, a TypeInfo migration) — the root mechanism behind the whole #8308 class of bugs.

Extracted into a shared ResourceLinkageResolver (@internal, both the legacy getBuiltinTypes and modern getNativeType paths) consumed by both the normalizer (runtime) and the JSON Schema factory (doc-time), so they cannot diverge. ~150 lines of duplicated logic removed.

Reserved attribute names (falls out of the unification)

The schema generator special-cased only id_id, while the runtime ReservedAttributeNameConverter prefixes five names: id, type, links, relationships, included. A scalar property named type/links/relationships/included was documented under the bare key but emitted prefixed (_type, …) — the same doc/response mismatch as #8308, for four of the five names. Attribute and relationship keys are now mapped through ReservedAttributeNameConverter::JSON_API_RESERVED_ATTRIBUTES (single source of truth).

Notes

Tests

  • ResourceLinkageResolverTest — split classification (scalar, to-one, nullable to-one, to-many, non-resource object, no type).
  • ReservedAttributeNameSchemaFactoryTest — all five reserved names documented under the prefixed key.

@soyuka soyuka force-pushed the feat/jsonapi-jsonschema-single-source branch from d62473c to 7868d0d Compare June 17, 2026 13:52
…hip split

`SchemaFactory::getRelationship()` recomputed the attributes-vs-relationships
partition from `getNativeType()`/`getBuiltinTypes()` — a near-verbatim copy of
the runtime split in `ItemNormalizer::getComponents()`. The two implementations
could drift on any change (collection handling, union/intersection types, a
TypeInfo migration), the root mechanism behind the api-platform#8308 class of bugs.

Extract the split into a shared `ResourceLinkageResolver` (both the legacy
`getBuiltinTypes` and modern `getNativeType` paths) consumed by both the
normalizer (runtime) and the JSON Schema factory (doc-time), so they cannot
diverge.

As a result, also map reserved attribute names through
`ReservedAttributeNameConverter::JSON_API_RESERVED_ATTRIBUTES` in the schema
instead of hard-coding `id` -> `_id`: a scalar property named `type`/`links`/
`relationships`/`included` is now documented under the same prefixed key the
response emits (same doc/response mismatch as api-platform#8308, for four of five names).

Refs api-platform#8322, api-platform#8313, api-platform#8308
@soyuka soyuka force-pushed the feat/jsonapi-jsonschema-single-source branch from 7868d0d to b9f6fb9 Compare June 17, 2026 14:32
@soyuka soyuka changed the base branch from main to 4.3 June 17, 2026 14:32
@soyuka soyuka changed the title fix(jsonapi): document reserved attribute names + single source of truth for the attribute/relationship split refactor(jsonapi): single source of truth for the attribute/relationship split Jun 17, 2026
@soyuka soyuka merged commit ea1ede5 into api-platform:4.3 Jun 17, 2026
109 of 112 checks passed
@soyuka soyuka deleted the feat/jsonapi-jsonschema-single-source branch June 17, 2026 18:14
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.

Strengthen JSON:API JSON Schema: full reserved-name handling + single source of truth for the attribute/relationship split

1 participant