Skip to content

C# oneOf wrappers: preserve payload data when discriminator is absent - #7998

Draft
Gavin Barron (gavinbarron) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-oneof-deserialization-issue
Draft

C# oneOf wrappers: preserve payload data when discriminator is absent#7998
Gavin Barron (gavinbarron) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-oneof-deserialization-issue

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

C# oneOf wrappers without a discriminator could deserialize into an IComposedTypeWrapper with all typed members unset, dropping object payload fields with no fallback access path. This change preserves that data by enabling AdditionalData on composed wrappers.

  • Wrapper fallback for discriminator-less oneOf

    • Updated C# refiner flow to add serialization members with includeAdditionalProperties: true for model classes representing composed wrappers (OriginalComposedType != null).
    • This gives generated wrappers an AdditionalData bag and IAdditionalDataHolder, so unknown/unmapped payload fields remain accessible instead of being discarded.
  • Targeted regression coverage

    • Extended C# refiner union-wrapper test to assert composed wrappers now:
      • contain an AdditionalData property
      • implement IAdditionalDataHolder
  • Behavior impact

    • No discriminator/mapping logic was altered.
    • Change is scoped to C# composed wrapper models and only adds fallback data preservation.
// Before (discriminator-less object oneOf):
effect.Props.AddLoyaltyPointsEffectProps == null;
// payload fields were effectively lost

// After:
effect.Props.AddLoyaltyPointsEffectProps == null; // still possible
var raw = effect.Props.AdditionalData;            // payload preserved here

Copilot AI requested review from Copilot and removed request for Copilot July 27, 2026 21:57
Copilot AI changed the title [WIP] Fix C# oneOf deserialization loss of data without discriminator C# oneOf wrappers: preserve payload data when discriminator is absent Jul 27, 2026
@romanett

Copy link
Copy Markdown
Contributor

Gavin Barron (@gavinbarron) I feel like this is finally a step in the right direction but for a library that still not supports oneOf for nullable reference types which get generated by Asp Net Core, this is a bold claim One of the goals of the project is to provide the best code generator support possible for OpenAPI and JSON Schema features.
Nearly one year after net10 release this is really not a great experience.
I am willing to spend some time to implement a solution to finally support that if you are okay to merge and give me some hints about the direction you want this to take shape.

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.

C# oneOf deserialization silently loses data when no discriminator is defined

3 participants