Is there any way how I can disable DisallowNull generation
See original GitHub issueHi. For specific reason I have an API that has method with parameter and returned value with the same type.
class HelloObject{
[Required]
string SomeProp {get;set;}
}
----
HelloObject Index(HelloObject) {
}
In this DTO one property is marked with DataAnnotation [Required] for validation of incoming parameter. But output model can have null value there.
But. If I generate definition with NSwag i will get
[Newtonsoft.Json.JsonProperty("SomeProp", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string SomeProp { get; set; }
And will get an exception while invoking this method in generated Client.
Required property ‘SomeProp’ expects a non-null value. Path ‘[0].HelloObject’, line 1, position 354.
I’ve tried:
RequiredPropertiesMustBeDefined = false,
GenerateDataAnnotations = false,
same as both states of NullHandling
So is there any way how to disable DisallowNull generation?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Make Swashbuckle describe a reference type property as ...
Make Swashbuckle describe a reference type property as nullable, or make NSwag decorate the client side as Default rather than DisallowNull.
Read more >Disallow Null Value field in existing data
Is there a way to disallow null values in field setting since it has existing data? Need to have one field that is...
Read more >Nullable Reference types in C# – Best practices
It can be used to enable or disable the nullable reference types feature ... there's no way to require it to be a...
Read more >Solved: how to disallow null attribute values in data entr...
Solved: Is there a way to force users to enter an attribute value for a field or fields on a featureclass in SDE...
Read more >ArcSDE how to Change Allow null values to "NO"
My idea was to disallow null and apply a domain to the field so the user can simply choose the value. Faster than...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The best option is to transform the generated swagger spec before generating client code (ie with an own cmd line tool which uses the nswag.core lib).
ITNOA
In general I think flexibility in library and tool is important, so I suggest to add this option into NSwag