0

Using NJsonSchema.CodeGeneration, I'm able to output the properties as-defined in JSON schema. However, I noticed that in the generated, code, a couple of things are going on:

  1. all of the properties have the Required = Newtonsoft...DisallowNull property defined.

  2. each property is set to a new instance of a class.

Example:

[Newtonsoft.Json.JsonProperty("myProperty", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public MyProperty MyProperty { get; set; } = new MyProperty();

Question:

How do I make it so that the generated code allows nulls? These are not required properties in the JSON schema, and it doesn't make sense to initialize them. On the other hand, it is handy to have the collection classes initialized by default, so they can be iterated without throwing an exception (this is the current behavior for collections as well).

theMayer
  • 15,456
  • 7
  • 58
  • 90
  • Maybe this solves the new instances problem: https://github.com/RSuter/NJsonSchema/pull/882 – Rico Suter Jan 27 '19 at 01:34
  • 1
    @RicoSuter - thanks, I'll give it a look. Good work on this as a whole - if I ever get a chance to contribute, I would love to! – theMayer Jan 27 '19 at 03:05

0 Answers0