So I'm using Cerberus for schema validation, but I'm running into a particular with validating a subdictionary of a dictionary whose key is unknown.
So say I have the following document:
dict = {
'things': {
'0463': {
'foo': 'blah',
'bar': 'bleep'
},
'0464': {
'foo': 'x',
'bar': 'y'
},
'another_random_id': {
'foo': 'blah',
'bar': 'bleep'
}
}
So i want to validate that the subdictionaries have a specific structure (foo
and bar
as keys), but I can't figure out a way to validate this without knowing the keys ahead of time (which in my case are random id's. I figured this was a good use of valueschema but i can't seem to get valueschema to work with something of type 'dict'. I tried to set the following schema in cerberus:
schema = {
'things': {
'type': 'dict',
'valueschema': {
'type': 'dict',
'foo': {'type': 'string'},
'bar': {'type': 'string'}
}
}
}
Am i defining my schema incorrectly or is this not possible with the current implementation of valueschema
. I saw some tests in the repository that used valueschema
, but they were only testing where the type of valueschema
was an int or a string.