-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[C#] Fixed valuetype parameters and discriminator deserialization #5680
Changes from all commits
35e1e99
3afe020
c735e51
2f614f0
5727fab
ecabacf
722342a
cda3886
635d176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now if this discriminator isn't camelCased it causes things to not deserialize properly when receiving them from an API (since the json is expected to come back camelcased) |
||
[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}} | ||
|
@@ -31,7 +31,7 @@ | |
{{#description}} | ||
/// <value>{{description}}</value> | ||
{{/description}} | ||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})] | ||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#required}}true{{/required}}{{^required}}false{{/required}}{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})] | ||
public {{#complexType}}{{{complexType}}}{{/complexType}}{{^complexType}}{{{datatypeWithEnum}}}{{/complexType}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}} {{name}} { get; set; } | ||
{{/isEnum}} | ||
{{/vars}} | ||
|
@@ -108,7 +108,7 @@ this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; | |
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} | ||
/// </summary>{{#description}} | ||
/// <value>{{description}}</value>{{/description}} | ||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]{{#isDate}} | ||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#required}}true{{/required}}{{^required}}false{{/required}}{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]{{#isDate}} | ||
[JsonConverter(typeof(OpenAPIDateConverter))]{{/isDate}} | ||
public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } | ||
{{/isEnum}} | ||
|
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.
Previously this only flagged things in the allVars array which are not actually references to the objecsts in the readWrite or readOnly arrays, so it was missing out on this decoration