feat: adds support for populating OpenAPI discriminator defaultMapping#67493
Merged
Conversation
Contributor
|
Thanks for your PR, @baywet. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OpenAPI 3.2 discriminator defaultMapping generation for polymorphic schemas when the non-abstract base type explicitly includes itself as a derived type (via JsonDerivedType), aligning the emitted schema with OpenAPI 3.2 discriminator semantics.
Changes:
- Emit
discriminatorDefaultMappingduring JSON schema export when the base type is non-abstract and includes a selfJsonDerivedTypewith a discriminator. - Parse
discriminatorDefaultMappingfrom the intermediate JSON schema representation and resolve discriminator references into document components. - Extend the polymorphism OpenAPI schema service test to validate
Discriminator.DefaultMappingis present and resolves to the base schema.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.PolymorphicSchemas.cs | Adds assertions validating Discriminator.DefaultMapping resolves to the base Pet schema. |
| src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | Resolves discriminator mapping/defaultMapping schema references against the OpenAPI document components. |
| src/OpenApi/src/Schemas/OpenApiSchemaKeywords.cs | Introduces a keyword constant for discriminator default mapping metadata. |
| src/OpenApi/src/Schemas/OpenApiJsonSchema.Helpers.cs | Adds deserialization support for discriminatorDefaultMapping into OpenApiDiscriminator.DefaultMapping. |
| src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs | Emits discriminatorDefaultMapping when appropriate for non-abstract base types that self-reference as a derived type with a discriminator. |
c6c0776 to
992052e
Compare
martincostello
approved these changes
Jul 2, 2026
Youssef1313
reviewed
Jul 7, 2026
Youssef1313
approved these changes
Jul 7, 2026
Member
|
@baywet There are test failures here:
|
Youssef1313
reviewed
Jul 8, 2026
3849995 to
f48edb6
Compare
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
f48edb6 to
14f5e02
Compare
Youssef1313
approved these changes
Jul 16, 2026
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.
fixes #65724
CC @martincostello