© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
38 replies
LifeOfVio

✅ 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
RandomSearchDto
like this ->
var searchBody = new RandomSearchDto();
var searchBody = new RandomSearchDto();
, the
CreatedAfter
CreatedAfter
and
CreatedBefore
CreatedBefore
properties have a default value (because they are not nullable).

How can I generate this so that the DateTimeOffsets are generated as
nullable
nullable
?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

OpenAPI Documents Empty
C#CC# / help
14mo ago
Swagger, openAPI specification
C#CC# / help
3y ago
map generation
C#CC# / help
13mo ago
Normalizing OpenApi Spec File
C#CC# / help
2y ago