JsonSchemaGenerator Custom ContractResolver for strings

I want to create a schema from a custom object. A user object has some string properties; these properties are schematized with a type String|Null. How can I change JSonSchemaGeneratorto convert strings to input Stringinstead String|Null? In other words, if I serialize Jsonschema, I don't want this:

{
  "title":"myObject",
  "type":"object",
  "properties":{
    "ID":{
      "required":true,
      "type":["string","null"]
    }
  }
}

but this:

{
  "title":"myObject",
  "type":"object",
  "properties":{
    "ID":{
      "required":true,
      "type":"string"
    }
  }
}
+3
source share
1 answer

You can do:

[JsonProperty(Required = Required.Always)]
public string ID {get;set;}
0
source

All Articles