LifeOfVio
LifeOfVio
CC#
Created by LifeOfVio on 9/24/2024 in #help
✅ OpenApi generation
I have following class generated from swagger
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")]
public partial class RandomSearchDto
{
[Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string City { get; set; }

[Newtonsoft.Json.JsonProperty("country", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Country { get; set; }

[Newtonsoft.Json.JsonProperty("createdAfter", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.DateTimeOffset CreatedAfter { get; set; }

[Newtonsoft.Json.JsonProperty("createdBefore", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.DateTimeOffset CreatedBefore { get; set; }
...
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")]
public partial class RandomSearchDto
{
[Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string City { get; set; }

[Newtonsoft.Json.JsonProperty("country", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Country { get; set; }

[Newtonsoft.Json.JsonProperty("createdAfter", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.DateTimeOffset CreatedAfter { get; set; }

[Newtonsoft.Json.JsonProperty("createdBefore", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.DateTimeOffset CreatedBefore { get; set; }
...
}
My issue is that when I create an instance of RandomSearchDto like this -> var searchBody = new RandomSearchDto();, the CreatedAfter and CreatedBefore properties have a default value (because they are not nullable). How can I generate this so that the DateTimeOffsets are generated as nullable?
39 replies