I have a YAML config file and I want to validate it using Cerberus. The problem is my YAML file is a kind of 3 layered dictionaries and it seems the validation function does not work when we have more than 2 nestings. As an example when I run the following code:
a_config = {'dict1': {'dict11': {'dict111': 'foo111',
'dict112': 'foo112'},
'dict12': {'dict121': 'foo121',
'dict122': 'foo122'}},
'dict2': 'foo2'}
a_simple_config = {'dict1': {'dict11': 'foo11'}, 'dict2': 'foo2'}
print(type(a_config))
print(type(a_simple_config))
simple_schema = {'dict1': {'type': 'dict', 'schema': {'dict11': {'type': 'string'}}}, 'dict2': {'type': 'string'}}
v_simple = Validator(simple_schema)
schema = {
'dict1': {
'type': 'dict',
'schema': {
'dict11': {
'type': 'dict',
'schema': {
'dict111': {'type': 'string'},
'dict112': {'type': 'string'}
}
}
}
},
'dict2': {'type': 'string'}
}
v = Validator(schema)
print(v.validate(a_config, schema))
print(v.errors)
I get this:
True
{}
False
{'dict1': [{'dict12': ['unknown field']}]}
I think validating 3 layered files is not supported. So my only idea is to try to validate it from layer 2 and if all of them are valid then conclude my file is valid. I wish to know am I making some mistake with writing my schema when I have 3 layers? or, is there exists a better idea for validating such files?
Edit: @flyx claimed that the problem is in the definition of dict12, so I decided to replace it. AND NOTHING changed. I again have the same output!