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.

Is there any way how I can disable DisallowNull generation

See original GitHub issue

Hi. 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

27reactions
RicoSutercommented, Aug 10, 2017

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).

3reactions
soroshsabzcommented, Jul 4, 2023

ITNOA

In general I think flexibility in library and tool is important, so I suggest to add this option into NSwag

Read more comments on GitHub >

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

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