1

I'm using Cerberus version 1.1.

The Cerberus required validation rule appears to default to False, with the result being that an empty document is perfectly valid.

>>> schema = {
    'spam': {'type': 'string'}
}

>>> v = Validator()
>>> v.validate({}, schema)
True

But I have a very lengthy schema document which needs to be strictly enforced. Is there a way to default to 'required': True for the entire schema, such that every defined field is required?

As it stands, I seem to have to paste 'required': True into every field definition, which seems needlessly redundant.

Matt Skone
  • 315
  • 1
  • 4
  • 10

1 Answers1

1

Sure, you can use simple Python idioms to design your schema:

schema = {
    'spam': {'type': 'string'},
    …
}
for field in schema:
    schema[field].update({'required': True})
funky-future
  • 3,716
  • 1
  • 30
  • 43