pyeve / cerberus

Lightweight, extensible data validation library for Python
http://python-cerberus.org
ISC License
3.17k stars 240 forks source link

Proposal: Add an option to require all defined fields of a schema #417

Closed pohmelie closed 6 years ago

pohmelie commented 6 years ago

There are four cases which I think should be covered with validator instance arguments:

Cerberus have allow_unknown option for validator, but have no allow_known_missed / forbid_known_missed or something like this. As stackoverflow question said, it is pretty annoying to set required: True for all fields, cause they can be nested and schema looks noisy and dirty.

pohmelie commented 6 years ago

It looks like this can be achieved, by changing couple of places, where 'required' checked to something like:

self.schema[field].get('required', self.forbid_known_missed)
pohmelie commented 6 years ago

Ok, I have successfully patched cerberus validator.py with technic like above, tests are still ok and looks like added argument works fine. The only problem is since 'required' became orphan there is an error here, but I hope this can be resolved.

funkyfuture commented 6 years ago

if this gets added, i'd prefer the option name require_all. some form of required is needed in the name to clearly relate it to the required rule.

should there also be a same-named flag for (sub-)schemas like allow_unknown?

nicolaiarocci commented 6 years ago

I think this would make for a nice addition. Feel free to submit a PR so, we can review it.

funkyfuture commented 6 years ago

@pohmelie a feedback on the progress would be great to have rather soonish as we're getting closer to the next minor release after which new features can't be merged for a while due to planned, larger code changes.