Reputation: 1621
I know that according to the Cerberus documentation, it is possible to define validation dependencies, according to other keys values, such as:
schema = {'field1': {'required': False},
'field2': {'required': True,
'dependencies': {'field1': ['one', 'two']}}}
Where field2
is valid only if field1
exists and has value one
or two
.
I would like to know if there's a way of having a validation rule that is considered depending on the value of the key itself.
Something like: field2
needs field1
value False
only if field2
value is True
, and vice-versa.
Only one of the fields must be allowed to be True
at a time.
Upvotes: 1
Views: 1818
Reputation: 6576
This could probably be solved by using dependencies
in conjunction with oneof
(docs) rule.
However, there's currently an issue which might prevent this solution from working (ticket). Unfortunately I don't have the time to triage this right now, but you could give it a shot and report back here and, eventually, on the ticket itself. Good luck!
Upvotes: 3