Reputation: 6852
I am using the following Json Schema validation package:
https://github.com/hasbridge/php-json-schema
Using that validation package, I want to validate in the following scenario:
Fields -
A
,B
Validation Condition - If
A
value is sent thenB
is not required. IfB
value is sent, thenA
is not required. But we need at least one of both field values in the form.
Can anyone help me on this?
Upvotes: 2
Views: 3032
Reputation: 97140
This is a JSON Schema that tests for the presence of property A
and/or B
:
{
"properties": {
"A": {},
"B": {}
},
"anyOf": [{
"required" : ["A"]
}, {
"required" : ["B"]
}]
}
Whether or not your PHP library supports this syntax is a different matter since the github page states that [...] it is not yet feature complete.
Here's a screenshot of testing it against Newtonsoft's online JSON schema validator:
Upvotes: 7