C# String property generated as Required when NULL is actually allowed
See original GitHub issueI have a simple string property on my Response model that can be allowed NULL. However the NSwagStudio Generator is marking the field as Required which is breaking serializaiton.
How can I prevent the generator from marking Required and Disallow Null?
[Newtonsoft.Json.JsonProperty("ContainerName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string ContainerName { get; set; }
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
c# - How can I make my string property nullable?
String is a reference type and always nullable, you don't need to do anything special. Specifying that a type is nullable is necessary...
Read more >Use empty string, null or remove empty property in API ...
I rather like the idea of using an empty string as an easy way to avoid using null.
Read more >Working with nullable reference types - EF Core
C# 8 introduced a new feature called nullable reference types (NRT), allowing reference types to be annotated, indicating whether it is valid ...
Read more >Attributes interpreted by the C# compiler: Nullable static ...
In a nullable enabled context, the compiler performs static analysis of code to determine the null-state of all reference type variables:.
Read more >Understanding null safety
When it comes to null , it means we can generate smaller code that eliminates unneeded null checks, and faster code that doesn't...
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
Anyone of you experiencing this with Swashbuckle.AspNetCore 5 ? This seems related: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1218
Hi Rico, Here is a swagger definition sample that generate this
Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)
SampleSwaggerDefinition.json.txt