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

New validators creation method #3

Closed
wants to merge 7 commits into from
Closed

New validators creation method #3

wants to merge 7 commits into from

Conversation

Bobronium
Copy link
Contributor

I found current wrappers concept a bit confusing and problematic to follow.

Instead of trying to copy validator class and add vaa api over it, I suggest to completely split them from each other.

So example from doc:

@vaa.marshmallow
class Scheme(marshmallow.Schema):
  id = marshmallow.fields.Int(required=True)
  name = marshmallow.fields.Str(required=True)

validator = Scheme({'id': '1', 'name': 'Oleg'})
validator.is_valid()  # True
validator.cleaned_data
# {'name': 'Oleg', 'id': 1}

Will look like this:

class Scheme(marshmallow.Schema):
  id = marshmallow.fields.Int(required=True)
  name = marshmallow.fields.Str(required=True)

SchemeValidator = vaa.marshmallow(Scheme)  # make custom validator class for current scheme

scheme = SchemeValidator({'id': '1', 'name': 'Oleg'})
scheme.is_valid()  # True
scheme.cleaned_data
# {'name': 'Oleg', 'id': 1}

Also now validation is triggered on init of the validator (so cleaned_data or errors could be accessed right away)
It keeps follow current api (none of tests were changed and all works just fine).
But if there any reasons to be triggered only by is_valid method, I can change it later

Also support for pydantic added

@Bobronium Bobronium added the enhancement New feature or request label Oct 2, 2019
@Bobronium Bobronium mentioned this pull request Oct 4, 2019
@Bobronium Bobronium closed this Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

1 participant