Skip to content

Commit

Permalink
eterey#41 Pyvalid: Updated Example in class docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
nagesh-kumar-abinbev committed Oct 18, 2020
1 parent 126913c commit a58c32c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pyvalid/validators/__schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@


class SchemaValidator(AbstractValidator):
"""
Class the validate the input data agains the given schema.
example:
user_schema = SchemaValidator
({
'name': StringValidator(re_pattern=r'^[A-Za-z]+\s?[A-Za-z]+\s?[A-Za-z]+$'),
'birthyear': NumberValidator(min_val=1890, max_val=2020),
'rating': float
'bio': [StringValidator(max_len=1024), None]
})
# So we can use schemas for `@accepts` and `@returns`
@accepts(new_user=user_schema)
def register_user(new_user):
# some logic here
pass
# Or we can call them directly to validate some data
user_schema({
'name': 'Max',
'birthyear': -42, # will cause a validator error
'bio': None,
# 'rating': 8.0
# the `address` attribute is missing, what will cause another error even if we fix `birthyear`
})
new_user = {
'name': 'Nagesh',
'birthyear': 1994, # will cause a validator error
'bio': None,
'rating': 8.0
# the `address` attribute is missing, what will cause another error even if we fix `birthyear`
}
register_user(new_user)
"""

schema_types = (dict,)

Expand Down

0 comments on commit a58c32c

Please sign in to comment.