I have a JSON Schema
{
'description': 'TPNode',
'type': 'object',
'id': 'tp_node',
'properties': {
'selector': {
'type': 'string',
'required': true
},
'attributes': {
'type': 'array',
'items': {
'name': 'string',
'value': 'string'
}
},
'children': {
'type': 'array',
'items': {
'type': 'object',
'$ref': '#'
}
},
'events': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'type': {
'type': 'string'
},
'handler': {
'type': 'object'
},
'dependencies': {
'type': 'array',
'items': {
'type': 'string'
}
}
}
}
}
}
}
What I'm trying to express in the children property is that it's an array of objects with the same exact schema. Is this the correct way to describe it?
JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema provides a contract for what JSON data is required for a given application and how to interact with it. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.
JSON Schema is a lightweight data interchange format that generates clear, easy-to-understand documentation, making validation and testing easier. JSON Schema is used to describe the structure and validation constraints of JSON documents.
The additionalProperties keyword is used to control the handling of extra stuff, that is, properties whose names are not listed in the properties keyword or match any of the regular expressions in the patternProperties keyword. By default any additional properties are allowed.
In a JSON schema, a $ref keyword is a JSON Pointer to a schema, or a type or property in a schema. A JSON pointer takes the form of A # B in which: A is the relative path from the current schema to a target schema. If A is empty, the reference is to a type or property in the same schema, an in-schema reference.
Yes, your schema will work. The "$ref": "#"
points back to the root of the schema document.
However, the "type": "object"
is useless:
{
'type': 'object',
'$ref': '#'
}
If $ref
is present, then all other keywords are ignored. It would be better to remove type
from the #/properties/children/items
schema.
Use the id
of the schema you need to reference
'$ref': 'tp_node'
See here: http://json-schema.org/latest/json-schema-core.html#anchor30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With