Trying to get this validation as acceptable True
, where any of the fields could be empty: True
(default i know), but when not empty than all the sequential conditionals must apply.
SCHEMA v = Validator()
schm = {'l_addrsch': {'type': 'string', 'empty': True, 'allowed': ['m', 'o', 'e', 'M', 'O', 'E'], 'dependencies': ['l_nrefaddr', 'l_refaddr']},
'l_nrefaddr': {'type': 'integer', 'empty': True, 'dependencies': ['l_addrsch', 'l_refaddr']},
'l_refaddr': {'type': 'integer', 'empty': True, 'dependencies': ['l_addrsch', 'l_nrefaddr']}}
POST val = v.validate(p, schema)
{
"l_addrsch" : "",
"l_nrefaddr" : "",
"l_refaddr" : ""
}
RESPONSE
[
{
"l_addrsch": [
"unallowed value "
],
"l_nrefaddr": [
"must be of integer type"
],
"l_refaddr": [
"must be of integer type"
]
}
]
Hope i was not too confuse.
EDIT 1: tried this as mentioned on normalizing rules 'default' :
schema = {'l_addrsch': {'type': 'string', 'default': '', 'allowed': ['', 'm', 'o', 'e', 'M', 'O', 'E'], 'dependencies': ['l_nrefaddr', 'l_refaddr']},
'l_nrefaddr': {'type': 'integer', 'default': 0, 'dependencies': ['l_addrsch', 'l_refaddr']},
'l_refaddr': {'type': 'integer', 'default': 0, 'dependencies': ['l_addrsch', 'l_nrefaddr']}
POST:
{ "l_addrsch" : "",
"l_nrefaddr" : "",
"l_refaddr" : ""}
But seems that i still missing something to get it working for the integers
[
{
"l_nrefaddr": [
"must be of integer type"
],
"l_refaddr": [
"must be of integer type"
]
}
]
From the doc:
To set default values, use the normalization rule instead. http://docs.python-cerberus.org/en/stable/normalization-rules.html#default-values
Something like this: