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 default-normalization rule #131

Closed
funkyfuture opened this issue Jul 20, 2015 · 3 comments
Closed

Proposal: Add default-normalization rule #131

funkyfuture opened this issue Jul 20, 2015 · 3 comments

Comments

@funkyfuture
Copy link
Member

this is a follow-up of this.

A default-rule would substitute any None-values, empty Mapping and Sequence-instances and numbers equal to zero for a given field with the provided constraint's value while a document is normalized. if the field isn't present at all, it will be added to the document with the constraint's value.

the default-constraint should be processed after coercing.

example:

>>> schema = {'amount': {'default': 1}}
>>> document = {'amount': None}
>>> v.validated(document, schema)
{'amount': 1}
>>> document = {'model': 'The Robots'}
>>> v.normalized(document, schema)
{'model': 'The Robots', 'amount': 1}
@nicolaiarocci
Copy link
Member

Now that we also transform the incoming document, I guess that stuff like this is welcome. Actually, we implemented a default rule in Eve so I know it is useful :) 👍

@funkyfuture
Copy link
Member Author

Is there a difference of Eve's rule-design to my proposal?

@nicolaiarocci
Copy link
Member

Yes. Of course Eve does not have or need normalized since input documents are stored to the backend (with defaults added as needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants