I've just upgraded my NSwag libraries & client to the latest version v14.0.3 (from v13.19.0):
NSwag.AspNetCore 14.0.3,
NSwag.CodeGeneration.CSharp 14.0.3,
NSwag.Generation.WebApi 14.0.3,
NJsonSchema 11.0.0,
Newtonsoft.Json 13.0.3.
My C# dto class:
public class TestClass
{
public IEnumerable<decimal?> Values { get; set; } = Enumerable.Empty<decimal?>();
}
Before the upgrade, generated code looked like:
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class GeneratedTestClass
{
[Newtonsoft.Json.JsonProperty("values", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<decimal?> Values { get; set; }
}
which is fine. As we can see in the output file our list is of type ICollection<decimal?>, exactly as expected.
But, after the upgrate to the versions listed at the top of this issue, generated code looks like that:
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class GeneratedTestClass
{
[Newtonsoft.Json.JsonProperty("values", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<decimal> Values { get; set; }
}
As you can see, there is a discrepancy between what we have as our base class and the output from the generated class. We want to have nullable decimals in output list but NSwag generated ICollection<decimal> instead of ICollection<decimal?>. I haven't change anything but the libraries' versions. nswag.json and all the configuration stuff remained untouched.
Am I correct that this is misbehaving? Looks like a bug to me. I'm expecting that generated class will keep the underlying nullable primitive types?
Hello all!
Issue description:
I've just upgraded my NSwag libraries & client to the latest version v14.0.3 (from v13.19.0):
My C# dto class:
Before the upgrade, generated code looked like:
which is fine. As we can see in the output file our list is of type
ICollection<decimal?>
, exactly as expected.But, after the upgrate to the versions listed at the top of this issue, generated code looks like that:
As you can see, there is a discrepancy between what we have as our base class and the output from the generated class. We want to have nullable decimals in output list but NSwag generated
ICollection<decimal>
instead ofICollection<decimal?>
. I haven't change anything but the libraries' versions.nswag.json
and all the configuration stuff remained untouched.Am I correct that this is misbehaving? Looks like a bug to me. I'm expecting that generated class will keep the underlying nullable primitive types?
I would highly appreciate every answer!