Skip to content
Next Next commit
Fixed valuetype parameters and discriminator deserialization
- 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
gbrown-ce committed Apr 24, 2020
commit 35e1e992d1836513479d8fdc91b964c84c07bc7e
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Contributor Author

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

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)) {
Copy link
Contributor Author

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

property.vendorExtensions.put("x-csharp-value-type", true);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// </summary>
[DataContract]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]{{#children}}
[JsonConverter(typeof(JsonSubtypes), "{{#lambda.camelcase_param}}{{{discriminatorName}}}{{/lambda.camelcase_param}}")]{{#children}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}}
Expand Down