I am trying to validate JSON Schema using another JSON Schema.
Example of JSON Schema to validate: https://jsonschema.net/home
Reference of Validation schema to validate above schema: https://github.com/ajv-validator/ajv/blob/master/lib/refs/json-schema-draft-07.json
I have a requirement where property can only be of primitive type i.e string, number, integer, boolean.
Since the root of JSON schema should have type as object and all the properties inside it will have type as primitive type, I am not sure how should I define type definition that validates the type at root level as object while type inside properties as primitive type.
Sample JSON:
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"name": "A green door"
}
],
"required": [
"name"
],
"properties": {
"name": {
"$id": "#/properties/name",
"type": "string",
"title": "The name schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"A green door"
]
}
},
"additionalProperties": true
}
Validation JSON that validates the type:
definitions: {
simpleTypes: {
enum: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'],
}
},
properties: {
type: {
anyOf: [
{ $ref: '#/definitions/simpleTypes' },
],
},
}
From the above simpleTypes -> enum if I remove object, my JSON becomes invalid.
Any way I can define enum for root type as different from type present inside properties?