有两个字段“field1”和“field2”。条件是“field1”或“field2”可以取“ANY”值,但两个字段都不能有“ANY”值。如何根据上述条件添加dependencies
或添加oneof
?excludes
from cerberus import Validator
v = Validator()
document = {
"field1": "ANY",
"field2": "ANY",
"field3": "ANY" # This field can be ANY
}
schema = {
"field1": {"required": True},
"field2": {"required": True, "dependencies": {"field1": ["ANY"]},}, # I want this condition to be like "field2"shouldn´t be "ANY" if "field1" is "ANY" and vice-versa.
}
v.validate(document, schema)
print(v.errors)