I would like to specify a regexp pattern for one field based on the data in another. Is this possible? I've tried switch and $data but not sure how to use them. for example, if data looks like:
{
"contacts":[
{
"mode":"Email",
"contact":"john.doe@abc.com"
},
{
"mode":"Phone",
"contact":"111-555-1234"
}
]
}
and schema looks something like:
"$schema":"http://json-schema.org/draft-04/schema#",
"type":"object",
"properties":{
"Contacts":{
"type":"array",
"minItems":1,
"items":{
"type":"object",
"properties":{
"mode":{
"type":"string",
"enum":[
"Email",
"Phone"
]
},
"contact":{
"type":"string",
"pattern":"?????"
}
},
"required":[
"mode",
"contact"
]
}
}
}
}
How can I set the pattern of contact based on data in mode, so that if mode is Email, it validates contact against a regexp for an email format, and if mode is Phone, it validates contact against a regexp for a phone format? I have the regexp for each. I need the logic to choose one or the other.