Skip to content

Commit

Permalink
Docs: Adds maxlength & minlength examples
Browse files Browse the repository at this point in the history
Signed-off-by: Vipul Gupta (@vipulgupta2048) <vipulgupta2048@gmail.com>
  • Loading branch information
vipulgupta2048 authored and funkyfuture committed Nov 8, 2019
1 parent 2f34b90 commit 9a174ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -56,6 +56,7 @@ Contributors
- Sergey Leshchenko
- Tobias Betz
- Trong Hieu HA
- Vipul Gupta
- Waldir Pimenta
- calve
- gilbsgilbs
Expand Down
36 changes: 34 additions & 2 deletions docs/validation-rules.rst
Expand Up @@ -459,7 +459,23 @@ The assigned data can be of any type.
min, max
--------

Minimum and maximum value allowed for any types that implement comparison operators.
Minimum and maximum value allowed for any types that implement comparison operators. See
`\*of-rules`_ for examples.

.. doctest::

>>> schema = {'weight':{'type':'float', 'min': 10.1,'max':10.9}}
>>> document = {'weight': 10.3}

>>> v.validate(document, schema)
True

>>> document = {'weight': 12}
>>> v.validate(document, schema)
False

>>> v.errors
{'weight': ['max value is 10.9']}

.. versionchanged:: 1.0
Allows any type to be compared.
Expand All @@ -470,7 +486,23 @@ Minimum and maximum value allowed for any types that implement comparison operat
minlength, maxlength
--------------------

Minimum and maximum length allowed for iterables.
Minimum and maximum length allowed for any objects that implements __len__. Examples are as follows:

.. doctest::

>>> schema = {'numbers': {'type': 'list', 'minlength': 1, 'maxlength': 3}}
>>> document = {'numbers': [256, 2048, 23]}

>>> v.validate(document, schema)
True

>>> document = {'numbers': [256, 2048, 23, 2]}
>>> v.validate(document, schema)
False

>>> v.errors
{'numbers': ['max length is 3']}


noneof
------
Expand Down

0 comments on commit 9a174ef

Please sign in to comment.