I am using JSON.NET JSchema Generator to create schemas based on classes decorated with Data Annotation Attributes. I'm using the generator like this:
var generator = new JSchemaGenerator();
generator.ContractResolver = new CamelCasePropertyNamesContractResolver();
generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.TypeName;
var schema = generator.Generate(typeof(myType));
string jsonSchema = schema.ToString();
This generates an example schema like:
{
"$id": "myType",
"definitions": {
"mySubType" : {
"$id": "mySubType",
"type": [
"object",
"null"
],
"properties": {
"name": {
"type: "string"
}
},
"required": [
"name"
]
}
},
"type": "object",
"properties": {
"name": {
"type": "string"
},
"details": {
"$ref": "mySubType"
}
},
"required": [
"name",
"details"
]
}
I want to be able to generate a schema that includes the additional properties attribute for both myType
and mySubType
, like this:
{
"$id": "myType",
"definitions": {
"mySubType" : {
"$id": "mySubType",
"type": [
"object",
"null"
],
"properties": {
"name": {
"type: "string"
}
},
"required": [
"name"
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"name": {
"type": "string"
},
"details": {
"$ref": "mySubClass"
}
},
"required": [
"name",
"details"
],
"additionalProperties": false
}
How can I generate a schema like this using a JSchema generator?
Is there a class level data annotation attribute that does this?