Repository navigation
NET11 csharp unions schema support - #4103
Merged
martincostello merged 2 commits intoAug 5, 2026
Merged
martincostello merged 2 commits into
martincostello merged 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dotnet-vnext #4103 +/- ##
================================================
+ Coverage 95.17% 95.20% +0.02%
================================================
Files 111 111
Lines 4127 4149 +22
Branches 844 847 +3
================================================
+ Hits 3928 3950 +22
Misses 199 199
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1 of 10 tasks
Collaborator
|
@DeagleGross If you update the merge base to |
Mirror System.Text.Json by emitting union types as an OpenAPI anyOf of their case-type schemas. Detection via JsonTypeInfoKind.Union / UnionCases in JsonSerializerDataContractResolver (internal, #if NET11_0_OR_GREATER); emission via TryGenerateUnionSchema hooked at the SchemaGenerator entry point, producing $refs to the reusable component schemas (shared case types deduplicate naturally). No public API changes, no new dependencies; net10 unaffected (union code compiled out). Rebased onto dotnet-vnext, which provides the net11 TFM; test project sets LangVersion=preview on net11 only so union test types compile. Includes schema-level and document-level (anyOf->$ref + single-representation dedup) tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7722de8a-3ea5-40fd-999a-4f647ce8f4f7
DeagleGross
force-pushed
the
deaglegross-csharp-unions-schema-support
branch
from
August 5, 2026 10:48
95c3f7b to
230ed5d
Compare
Contributor
Author
|
rebased on |
DeagleGross
marked this pull request as ready for review
August 5, 2026 10:51
Parameterize the document-level union test over OpenApiSpecVersion (3.0 and 3.1) to verify the anyOf-of-$refs and single-representation dedup hold for both spec versions. Addresses PR review feedback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7722de8a-3ea5-40fd-999a-4f647ce8f4f7
martincostello
approved these changes
Aug 5, 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.
.NET 11 introduces C#
uniontypes, which System.Text.Json represents transparently as an anyOf of the union's case types. This PR adds mirroring behavior compared to STJ and the in-box Microsoft.AspNetCore.OpenApi.All union code and tests are guarded by
#if NET11_0_OR_GREATERand the net11 TFM is added additively and gated on SDK support; no public API changes and no new dependencies. net8/9/10 behavior is unchanged.Is a follow-up of #4100.
Related dotnet/aspnetcore#66544, #2743.