-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[C#] Fixed valuetype parameters and discriminator deserialization #5680
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
Changes from 1 commit
35e1e99
3afe020
c735e51
2f614f0
5727fab
ecabacf
722342a
cda3886
635d176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Made non-required valuetypes nullable, and flagged required valuetypes as "x-csharp-value-type" - Made sure to camelCase discriminator property names in Subtype converter
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -661,13 +661,25 @@ public void postProcessParameter(CodegenParameter parameter) { | |
| postProcessPattern(parameter.pattern, parameter.vendorExtensions); | ||
| postProcessEmitDefaultValue(parameter.vendorExtensions); | ||
| super.postProcessParameter(parameter); | ||
|
|
||
| if (nullableType.contains(parameter.dataType)) { | ||
| if (!parameter.required) { //optional | ||
| parameter.dataType = parameter.dataType + "?"; | ||
| } else { | ||
| parameter.vendorExtensions.put("x-csharp-value-type", true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { | ||
| postProcessPattern(property.pattern, property.vendorExtensions); | ||
| postProcessEmitDefaultValue(property.vendorExtensions); | ||
| super.postProcessModelProperty(model, property); | ||
|
|
||
| if (!property.isContainer && (nullableType.contains(property.dataType) || property.isEnum)) { | ||
|
||
| property.vendorExtensions.put("x-csharp-value-type", true); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| /// </summary> | ||
| [DataContract] | ||
| {{#discriminator}} | ||
| [JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]{{#children}} | ||
| [JsonConverter(typeof(JsonSubtypes), "{{#lambda.camelcase_param}}{{{discriminatorName}}}{{/lambda.camelcase_param}}")]{{#children}} | ||
|
||
| [JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}} | ||
| {{/discriminator}} | ||
| {{#generatePropertyChanged}} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be noted that this code is just copied from the csharp-netcore generator and works properly there