'Validate nested JSON schema with required properties - ES6
I have an example of JSON Schema like:
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"required": [
"extras"
],
"properties": {
"email": {
"type": "string",
"meta": {
"type": "string",
"locked": true
},
"title": "email",
"format": "email"
},
"extras": {
"type": "object",
"required": [],
"properties": {
"firstname": {
"type": "string",
"meta": {
"type": "string",
"locked": true
},
"title": "firstname"
},
"lastname": {
"type": "string",
"meta": {
"type": "string",
"locked": true
},
"title": "lastname"
}
},
"meta": {
"type": "object",
"locked": true
},
"title": "extras"
}
},
"meta": {
"type": "object",
"locked": true
}
}
In this schema, the property extras is a child object and required.
Because the extras property is required, one of the properties under extras needed to be required. And in this case, none of the properties under extras are required.
My question is: How to detect and validate this case in general when there is a nested JSON schema? In other words: Any required object needs one of its properties to be required.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
