I have a .Net 8.0 WebAPI project which Im using NSwag to produce a c# SDK APIClient class so that I can interact with it from another project.
NSwag is marking all strings with this attribute
[Newtonsoft.Json.JsonProperty("longUrl", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string LongUrl{ get; set; }
It does this for all strings. The issue I have is that when I call the client and it tries to deserialise the json to an object it fails when the string is not provided.
I’m not sure what Im supposed to do here? If I manually change
Required = Newtonsoft.Json.Required.DisallowNull
to Newtonsoft.Json.Required.Default
then it works but I dont want to have to manually update the whole file after every build.
Do I need to mark up my DTO’s with a nullable string
eg:
string? LongUrl { get; set; }
Or is there a way of getting Nswag to always use Default?