Skip to content

feat(jsonschema): discriminator maps as oneOf - #8879

Closed
dunglas wants to merge 1 commit into
mainfrom
feat/jsonschema-discriminator-oneof
Closed

dunglas wants to merge 1 commit into
mainfrom
feat/jsonschema-discriminator-oneof

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#...

Classes carrying a Symfony #[DiscriminatorMap] are now documented as a oneOf of their mapped subclasses, with an OpenAPI discriminator object. Each subclass schema declares the type property as a required single-value enum. A single POST operation can then accept several payload shapes and document each of them:

#[DiscriminatorMap(typeProperty: 'action', mapping: ['archive' => ArchiveBookAction::class, 'merge' => MergeBookAction::class])]
abstract class BookAction {}

#[Post(uriTemplate: '/discriminated_book_actions', input: BookAction::class)]

The discriminator keyword is only emitted for OpenAPI; plain JSON Schema gets the oneOf alone.

Test: tests/Functional/DiscriminatorMapOpenApiTest.php

A class carrying a #[DiscriminatorMap] is now described as a oneOf of its
mapped subclasses, with an OpenAPI discriminator object. Each subclass
schema declares the type property as a required single-value enum.
@soyuka

soyuka commented Nov 26, 2026

Copy link
Copy Markdown
Member

Thanks! I picked this into #8874 (co-authored), our polymorphism work now builds on your buildDiscriminatorDefinition, closing in favor of it.

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