Open slawomir-brzezinski-at-interxion opened 8 years ago
Currently, the workaround I found was to expose a fake Required.DisallowNull
field that changes it to Required.Default
and a moot RequiredAttribute
like:
public static class Required
{
public const Newtonsoft.Json.Required DisallowNull = Newtonsoft.Json.Required.Default;
}
public class RequiredAttribute : Attribute {}
but I think that writing a tolerant reader is sometimes a true necessity, so it's a shame that this library cannot be used with this approach.
Have you tried to set RequiredPropertiesMustBeDefined
to false. Isnt this what you are looking for?
https://github.com/NJsonSchema/NJsonSchema/wiki/CSharpGenerator
Thanks @rsuter . I'll give it a go soon.
@rsuter actually, I already tried it but it didn't give me what I want, because the wire payload has actually sent the property, but it sent it as null
. The setting will not help in such situation.
(it's actually due to a bug in the other endpoint that its generated swagger doesn't say it will send null values).
Btw: type: [array, null] is not allowed in swagger.. (big problem). Is the property not required and still null is not allowed?
Try http://nswag.org :)
Yes, If I could control that requestor :)
In order to choose the way of the TolerantReader.
I have a swagger.json with
It's fine that the author of the service made these properties required and non-nullable and I don't want to change that.
Still, the service is going to be evolving, possibly rearranging the properties I don't care about, therefore I would like there to be an option for me to decide to only fail with
NullReferenceException
when I actually consume, and not when trying to deserialize the JSON.In essence, I'd like an option to altogether disable adding the
[Required]
and[JsonProperty(... Required = Required.DisallowNull)]
in the clients I generate (or always useRequired.Default
, whichever is the right way to do it).