fix(jsonapi): correct relationship schemas in generated json schema#8321
Merged
soyuka merged 1 commit intoJun 17, 2026
Merged
Conversation
- relationship linkage is a resource identifier object: require type and id, per https://jsonapi.org/format/#document-resource-identifier-objects - list every target of a polymorphic (union-typed) relation in included.anyOf instead of collapsing to the last via array_flip, which also dedupes refs shared across relationships
80bb21f to
0fe94ff
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.
Problem
Two pre-existing defects in the JSON:API JSON Schema generation, surfaced while reviewing #8313 (both live in
buildDefinitionPropertiesSchema, untouched by that PR):Relationship linkage is under-specified. The resource identifier object reused for every relationship
data(RELATION_PROPS) declarestypeandidbut marks neither required. The JSON:API spec says a resource identifier object MUST contain both — see Resource Identifier Objects.Polymorphic relations lose targets in
included.$relatedDefinitions[$propertyName] = array_flip($refs)collapses the ref map to a single entry because every value is the literal string'$ref'—array_flipkeeps only the last key. A relation typed as a union of several resource classes therefore advertises only one of them underincluded.anyOf; the others vanish.Fix
'required' => ['type', 'id']toRELATION_PROPS.$relatedDefinitionsas a flat map keyed by ref URI, so every target of a polymorphic relation is listed inincluded.anyOf. This also dedupes refs shared across multiple relationships.Tests
testRelationshipLinkageRequiresTypeAndId: to-one linkage requirestype+id.testIncludedListsAllPolymorphicRelationTargets: a union-typed relation lists every target inincluded.anyOf(newOtherRelatedDummyfixture).Single-class
includedbehaviour is unchanged (existing functional tests still green).