I have a case where i am validating the required properties conditionally.
"not required" is not working as expected.
If 'profile' as profile1 then 'rate', 'trick' and 'tag' fields are required and 'code', 'name' and 'type' should not be present.
If 'profile' as profile2 then 'code' is required, and 'rate', 'tag', and 'trick' are not required.
if 'profile' is profile3 then 'rate', 'tag', 'trick', 'code', 'name' and 'type' are not required.
I am using schema draft version 4
Schema
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"url": { "type": "string" },
"profile": { "type": "string" },
"rate": { "type": "string" },
"trick": { "type": "boolean" },
"tag": { "type": "string" },
"type": { "type": "string" },
"name": { "type": "string" },
"code": { "type": "string" }
},
"additionalProperties": false,
"required": [ "url", "profile" ],
"oneOf": [
{
"properties": { "profile": { "enum": [ "profile1" ] } },
"not": { "required": ["type", "name", "code"] }
},
{
"properties": { "profile": { "enum": [ "profile2" ] } },
"allOf": [
{ "required": [ "code" ] },
{ "not": { "required": ["rate", "tag", "trick"] } }
]
},
{
"properties": { "profile": { "enum": ["profile3"] } },
"not": { "required": ["rate", "trick", "tag", "type", "name", "code"] }
}
]
}
Valid Inputs
{
"id": 1,
"url": "url",
"profile": "profile2",
"type": "",
"name": "",
"code": ""
}
{
"id": 1,
"url": "url",
"profile": "profile3"
}
{
"id": 1,
"url": "url",
"profile": "profile1",
"rate": "",
"trick": false,
"tag": ""
}
Invalid Inputs
{
"url": "url",
"profile": "profile3",
"code": ""
}