question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C# String property generated as Required when NULL is actually allowed

See original GitHub issue

I 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; }

9-5-2019 12-35-11 PM

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mkontulacommented, Sep 16, 2019

Anyone of you experiencing this with Swashbuckle.AspNetCore 5 ? This seems related: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1218

0reactions
Jerome-Ligercommented, Sep 13, 2019

Hi Rico, Here is a swagger definition sample that generate this Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)

SampleSwaggerDefinition.json.txt

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found