Repository navigation
[csharp][generichost] Serialize union members that are not merged objects #25486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wing328
merged 9 commits into
OpenAPITools:master
from
SpenserJ:csharp-generichost-union-serialization
Nov 9, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
62451a5
[csharp][generichost] Serialize union members that are not merged obj…
SpenserJ 8a3dfb6
Update csharp generichost samples
SpenserJ 9ba2666
[csharp][generichost] Test that a discriminated anyOf writes its sele…
SpenserJ eeadff8
[csharp][generichost] Read union members only from matching JSON tokens
SpenserJ d3578e5
[csharp][generichost] Read object union members once from the object …
SpenserJ ff6ef2b
[csharp][generichost] Delegate union members that are unions to their…
SpenserJ ec81068
Move union member serialization tests to a manual test project
SpenserJ 3980cb8
Merge remote-tracking branch 'origin/master' into csharp-generichost-…
SpenserJ 64a91e4
Update csharp generichost samples
SpenserJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| generatorName: csharp | ||
| outputDir: samples/client/petstore/csharp/generichost/latest/UnionMembers | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_1/csharp/union-members.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/csharp | ||
| additionalProperties: | ||
| packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}' | ||
| modelPropertySorting: alphabetical | ||
| operationParameterSorting: alphabetical | ||
| treatWarningsAsErrors: true | ||
| warningsNotAsErrors: CS0612 |
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
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
13 changes: 13 additions & 0 deletions
13
...penapi-generator/src/main/resources/csharp/libraries/generichost/ReadUnionMember.mustache
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {{#vendorExtensions.x-is-union}} | ||
| Utf8JsonReader utf8JsonReader{{name}} = utf8JsonReader; | ||
| ClientUtils.TryDeserialize<{{{datatypeWithEnum}}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}>(ref utf8JsonReader{{name}}, jsonSerializerOptions, out {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}); | ||
|
|
||
| {{/vendorExtensions.x-is-union}} | ||
| {{^vendorExtensions.x-is-union}} | ||
| if ({{#isFreeFormObject}}startingTokenType == JsonTokenType.StartObject{{/isFreeFormObject}}{{^isFreeFormObject}}{{#isMap}}startingTokenType == JsonTokenType.StartObject{{/isMap}}{{^isMap}}{{#isArray}}startingTokenType == JsonTokenType.StartArray{{/isArray}}{{^isArray}}{{#isEnumRef}}isScalarToken{{/isEnumRef}}{{^isEnumRef}}{{#isPrimitiveType}}isScalarToken{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isContainer}}isScalarToken{{/isContainer}}{{^isContainer}}startingTokenType == JsonTokenType.StartObject{{/isContainer}}{{/isPrimitiveType}}{{/isEnumRef}}{{/isArray}}{{/isMap}}{{/isFreeFormObject}}) | ||
| { | ||
| Utf8JsonReader utf8JsonReader{{name}} = utf8JsonReader; | ||
| ClientUtils.TryDeserialize<{{{datatypeWithEnum}}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}>(ref utf8JsonReader{{name}}, jsonSerializerOptions, out {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}); | ||
| } | ||
|
|
||
| {{/vendorExtensions.x-is-union}} | ||
6 changes: 6 additions & 0 deletions
6
...-generator/src/main/resources/csharp/libraries/generichost/WriteUnionAnyOfMember.mustache
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| if ({{#lambda.joinWithAmpersand}}{{^required}}{{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet {{/required}}{{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}} != null{{/lambda.joinWithAmpersand}}) | ||
| { | ||
| JsonSerializer.Serialize(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}}, jsonSerializerOptions); | ||
| return; | ||
| } | ||
|
|
6 changes: 6 additions & 0 deletions
6
...-generator/src/main/resources/csharp/libraries/generichost/WriteUnionOneOfMember.mustache
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| if ({{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} != null) | ||
| { | ||
| JsonSerializer.Serialize(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}, jsonSerializerOptions); | ||
| return; | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.