Im using json schema draft-4 and I am trying to conditionally add a requirement for a required label. For any value in env labels 1/2/3 are required but if the value is sit or uat then another label, date must also be required.
"date": {
"type": [
"string"
]
}
},
"anyOf": [
{
"not": {
"properties": { "env": { "enum": ["sit", "uat"] } },
"required": ["label1","label2","label3]
}
},
{ "required": ["date"] }
],
Ive based what I have on Implications documented here: https://json-schema.org/understanding-json-schema/reference/conditionals
2
Answers
This will satisfy your requirements.
if
date
is only allowed withsit
anduat
then you can modify this slightly to constraindate
from therequired
array in the secondoneOf
schema.An alternative way to do this would be to redefine the entire schema in a
oneOf