Skip to content

feat(jsonld): expand IRIs in @type discriminators - #8878

Merged
soyuka merged 2 commits into
mainfrom
feat/jsonld-type-discriminator
Nov 26, 2026
Merged

soyuka merged 2 commits into
mainfrom
feat/jsonld-type-discriminator

Conversation

@dunglas

@dunglas dunglas commented Nov 26, 2026

Copy link
Copy Markdown
Member
Q A
Branch? main
Tickets
License MIT
Doc PR api-platform/docs#...

When a #[DiscriminatorMap] uses @type as its type property, the JSON-LD denormalizer expands the payload @type and the mapping keys against the request's inline @context (@vocab, prefixes, term definitions) before matching them. LikeAction with a matching @vocab, schema:LikeAction and https://schema.org/LikeAction all resolve to the same class. An array @type resolves to its first mapped value. Remote contexts are not dereferenced.

#[DiscriminatorMap(typeProperty: '@type', mapping: [
    'https://schema.org/LikeAction' => LikeAction::class,
    'https://schema.org/ShareAction' => ShareAction::class,
])]
abstract class ReviewAction {}

Non-resource outputs keep the @type set by the discriminator instead of the class short name.

A separate commit turns the 500 raised by a non-string type property value (array, object, integer) into a 400.

Tests: tests/Functional/JsonLd/TypeDiscriminatorTest.php, DiscriminatedInputDtoTest::testNonStringTypePropertyIsRejected

A non-string type property value reached ClassDiscriminatorMapping::getClassForType()
and raised a TypeError, turning a malformed payload into a 500.
When a #[DiscriminatorMap] uses @type as its type property, the JSON-LD
denormalizer expands the payload types and the mapping keys against the
request's inline @context (@vocab, prefixes and term definitions) before
matching them. An array @type resolves to its first mapped value. Remote
contexts are not dereferenced.

Non-resource outputs now keep the @type written by the discriminator
instead of the class short name.
@soyuka
soyuka marked this pull request as ready for review November 26, 2026 16:10
@soyuka
soyuka merged commit 68d3133 into main Nov 26, 2026
94 of 118 checks passed
@soyuka
soyuka deleted the feat/jsonld-type-discriminator branch November 26, 2026 16:11
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.

2 participants