Repository navigation
[csharp][generichost] Write the selected member of an anyOf with a discriminator - #25260
Open
Arthur031221 wants to merge 1 commit into
Open
Arthur031221 wants to merge 1 commit into
Arthur031221 wants to merge 1 commit into
Conversation
…scriminator The anyOf writer in JsonConverter was skipped for every model with a discriminator and the discriminator branch only handled oneOf, so such a model was serialized as an empty object. Signed-off-by: Arthur031221 <levi74108520963@gmail.com>
Member
|
Thanks for the PR cc @devhl-labs |
SpenserJ
added a commit
to SpenserJ/openapi-generator
that referenced
this pull request
Oct 30, 2026
…cted member Brings over the codegen test from OpenAPITools#25260. Co-authored-by: Arthur031221 <levi74108520963@gmail.com>
3 tasks done
Author
|
Is there anything else you need from me to move this forward? |
Contributor
|
There are two other competing PRs. Id like to merge this one first and see if the problem this fixes is addressed. I really appreciate all the help trying to improve composed schemas. |
This branch has not been deployed
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.
With the C# generichost library, a model with
anyOfand adiscriminatoris read into the right member but written as{}, so request bodies built from it go out empty. InJsonConverter.mustachetheanyOfwriter was skipped for every model with a discriminator, and the discriminator branch ofWriteonly handledoneOf.I removed the
^model.discriminatorguard around theanyOfwriter.Readfills only the member the discriminator picks, soWritenow emits that member's properties, same asoneOf.Tested with the schema from the issue in a .NET 9 container, both subtypes serialize back to the original JSON. Added
testAnyOfDiscriminatorWritesSelectedSubtypetoCSharpClientCodegenTest. Regenerating the generichost sample configs changes no files.Fixes #25154
cc @devhl-labs @mandrean @shibayan @Blackclaws @lucamazzanti
Assisted by Claude/Codex.
Summary by cubic
Fixes C# generichost serialization so
anyOfmodels with a discriminator write the selected member instead of an empty object.The
anyOfwriter inJsonConverter.mustachewas skipped for every model with a discriminator, and the discriminator branch ofWriteonly handledoneOf. Removing the guard letsWriteemit the properties of the member the discriminator picks, matchingoneOfbehavior.testAnyOfDiscriminatorWritesSelectedSubtypetoCSharpClientCodegenTestto verify serialization of the selected subtype.Written for commit 9863837. Summary will update on new commits.