Skip to content

feat: adds support for populating OpenAPI discriminator defaultMapping#67493

Merged
Youssef1313 merged 9 commits into
dotnet:mainfrom
baywet:feat/default-mapping
Jul 16, 2026
Merged

feat: adds support for populating OpenAPI discriminator defaultMapping#67493
Youssef1313 merged 9 commits into
dotnet:mainfrom
baywet:feat/default-mapping

Conversation

@baywet

@baywet baywet commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings June 30, 2026 15:49
@baywet baywet requested a review from a team as a code owner June 30, 2026 15:49
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 30, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @baywet. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 discriminatorDefaultMapping during JSON schema export when the base type is non-abstract and includes a self JsonDerivedType with a discriminator.
  • Parse discriminatorDefaultMapping from the intermediate JSON schema representation and resolve discriminator references into document components.
  • Extend the polymorphism OpenAPI schema service test to validate Discriminator.DefaultMapping is 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.

Comment thread src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@baywet baywet force-pushed the feat/default-mapping branch from c6c0776 to 992052e Compare July 2, 2026 16:41
@baywet baywet requested a review from martincostello July 2, 2026 16:42
Comment thread src/OpenApi/src/Schemas/OpenApiSchemaKeywords.cs
@Youssef1313

Copy link
Copy Markdown
Member

@baywet There are test failures here:

  • OpenApiDocumentLocalizationTests.VerifyOpenApiDocumentIsInvariant [FAIL]
  • OpenApiDocumentIntegrationTests.OpenApiDocumentIsValid(documentName: "schemas-by-ref", version: OpenApi3_1) [FAIL]
  • OpenApiDocumentIntegrationTests.OpenApiDocumentIsValid(documentName: "schemas-by-ref", version: OpenApi3_2) [FAIL]

@baywet baywet requested a review from Youssef1313 July 7, 2026 12:42
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
baywet and others added 6 commits July 15, 2026 14:11
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>
@baywet baywet force-pushed the feat/default-mapping branch from f48edb6 to 14f5e02 Compare July 15, 2026 18:12
@baywet baywet requested a review from wtgodbe as a code owner July 15, 2026 18:12
@baywet baywet requested a review from a team as a code owner July 15, 2026 18:12
@Youssef1313 Youssef1313 merged commit e15a58c into dotnet:main Jul 16, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI: Populate discriminator defaultMapping for non-abstract base types that include self JsonDerivedType

4 participants