Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pohmelie opened this issue Jul 2, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@pohmelie
Copy link
Contributor

commented Jul 2, 2018

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

  • Allow known missed, forbid unknown present (default behavior right now)
  • Allow known missed, allow unknown present (allow_unknown=True)
  • Forbid known missed, forbid unknown present (no way at validator creation time)
  • Forbid known missed, allow unkown present (no way at validator creation time)

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2018

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2018

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

This comment has been minimized.

Copy link
Member

commented Jul 5, 2018

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

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

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

@funkyfuture funkyfuture changed the title Strict schema validation Proposal: Add an option to require all defined fields of a schema Jul 6, 2018

@funkyfuture

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

@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.

pohmelie pushed a commit to pohmelie/cerberus that referenced this issue Aug 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.