Skip to content

feat(doctrine): derive polymorphism from Doctrine - #8886

Closed
soyuka wants to merge 4 commits into
polymorphism/3-jsonschemafrom
polymorphism/4-doctrine
Closed

soyuka wants to merge 4 commits into
polymorphism/3-jsonschemafrom
polymorphism/4-doctrine

Conversation

@soyuka

@soyuka soyuka commented Nov 26, 2026 •

Copy link
Copy Markdown
Member
Q A
Branch? main
Tickets
License MIT
Doc PR

Exposes the Doctrine ORM and MongoDB ODM discriminator maps of a resource as serializer discriminator maps with doctrine.discriminator_map / doctrine_mongodb_odm.discriminator_map. The type property is the discriminator column name, an explicit serializer map takes precedence.

Test: tests/Functional/DoctrineDiscriminatedResourceTest.php

Part 4/6 of the polymorphism stack (#8889), replaces #8874.

Resolve the subtypes of a resource from the serializer discriminator
map. Enabled with `serializer.discriminator_map` (Laravel:
`api-platform.serializer.discriminator_map`), which is off by default
and has no effect on its own yet.
@soyuka
soyuka force-pushed the polymorphism/4-doctrine branch from aff89f0 to f8193a7 Compare November 27, 2026 09:30
@soyuka
soyuka force-pushed the polymorphism/3-jsonschema branch from c7555d1 to 10d5ae2 Compare November 27, 2026 09:30
Read, write and document the subtypes declared in the serializer
`#[DiscriminatorMap]` of a resource, in JSON-LD, Hydra, HAL and JSON:API.
An update never changes the subtype: a `PUT` or `PATCH` with another type
returns a 422 (`UnprocessableValueException`).

Co-authored-by: Dylan van der Hout <dylan@rumble.nl>
Co-authored-by: Maxcastel <maxence.nord@gmail.com>
@soyuka
soyuka force-pushed the polymorphism/4-doctrine branch from f8193a7 to c15836a Compare November 27, 2026 10:25
@soyuka
soyuka force-pushed the polymorphism/3-jsonschema branch from 10d5ae2 to 04ae164 Compare November 27, 2026 10:25
soyuka and others added 2 commits November 27, 2026 11:38
A resource with a serializer discriminator map is documented as a
`oneOf` of its subtypes with a `discriminator` in JSON Schema, JSON:API
and OpenAPI.

Co-authored-by: Kévin Dunglas <kevin@dunglas.dev>
Co-authored-by: Dylan van der Hout <dylan@rumble.nl>
Expose the Doctrine ORM and MongoDB ODM discriminator maps of a resource
as serializer discriminator maps with `doctrine.discriminator_map` and
`doctrine_mongodb_odm.discriminator_map`. An explicit serializer map
takes precedence.

Co-authored-by: Dylan van der Hout <dylan@rumble.nl>
@soyuka
soyuka force-pushed the polymorphism/4-doctrine branch from c15836a to ef6bdd2 Compare November 27, 2026 10:43
@soyuka
soyuka force-pushed the polymorphism/3-jsonschema branch 2 times, most recently from 1947801 to 019dbb0 Compare November 27, 2026 14:55
@soyuka

soyuka commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Closing, we don't want to infer the serializer discriminator map from the Doctrine one. Declare a #[DiscriminatorMap] on the resource instead, it's one attribute and keeps the API contract explicit.

@soyuka soyuka closed this Nov 27, 2026
@soyuka
soyuka removed this pull request from stack #8889 November 27, 2026 14:56
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