I am trying to validate a JSON schema using jsonschema lib.
scenario: I need to make sure if a specific value in a property is sent in the parent object, the child(sub-schema) should also get the same value in the same property.
JSON:->
{
"type": "object",
"properties": {
"action": {
"enum": [
"get",
"post"
]
},
"order": {
"properties": {
"id": "string",
"action": {
"enum": [
"get",
"post"
]
}
}
}},"dependentSchemas": {
"if": {
"action": {
"const": "get"
}
},
"then": {
"properties": {
"order": {
"properties": {
"action": {
"const": "get"
}
}
}
}
}
}
}
Sample test cases: Positive:
{
"action": "get",
"order": {
"id" : "1"
"action": "get"
}
}
Negative:
{
"action": "get",
"order": {
"id" : "2"
"action": "post"
}
}
I am using dependentSchemas to validate the sub-schema:-click here