Skip to content

Commit 4ac61bf

Browse files
committed
Update docs: validator page
1 parent d1c62d7 commit 4ac61bf

37 files changed

+1908
-105
lines changed

docs/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ Available functions:
2626
.. tip::
2727

2828
Thank you for using `flask-inputfilter`!
29+
2930
If you have any questions or suggestions, please feel free to open an issue on `GitHub <https://github.com/LeanderCS/flask-inputfilter>`_.
3031
If you don't want to miss any updates, please star the repository.
3132
This will help me to understand how many people are interested in this project.
3233

34+
.. note::
35+
36+
If you like the project, please consider giving it a star on GitHub.
37+
3338
Installation
3439
------------
3540

docs/options/condition.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Overview
88

99
The `addCondition` method is used to add a condition between fields.
1010

11-
Examples
12-
--------
11+
Example
12+
-------
1313

1414
.. code-block:: python
1515

docs/options/copy.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Copy functionality
22
==================
33

4-
54
Overview
65
--------
76

@@ -13,8 +12,8 @@ This parameter accepts a string with the name the value should be copied from.
1312
The copy functionality runs **before** all filters and validators have been executed.
1413
This means the copied data can be validated and/or filtered.
1514

16-
Examples
17-
--------
15+
Example
16+
-------
1817

1918
Basic Copy Integration
2019

docs/options/filter.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Filters can be added into the ``add`` method for a specific field or as a global
1010

1111
The global filters will be executed before the specific field filtering.
1212

13-
Examples
14-
--------
13+
Example
14+
-------
1515

1616
.. code:: python
1717
@@ -39,7 +39,7 @@ Examples
3939
Available Filters
4040
-----------------
4141

42-
The following filters are available in the ``Filter`` module:
42+
The following filters are available:
4343

4444
- `ArrayExplodeFilter`_
4545
- `Base64ImageDownscaleFilter`_
@@ -69,6 +69,9 @@ The following filters are available in the ``Filter`` module:
6969
- `WhitelistFilter`_
7070
- `WhitespaceCollapseFilter`_
7171

72+
Detailed Description
73+
--------------------
74+
7275
ArrayExplodeFilter
7376
~~~~~~~~~~~~~~~~~~
7477
**Description:**

docs/options/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Options
66

77
inputfilter
88
validator
9+
special_validator
910
filter
1011
condition
1112
copy

docs/options/special_validator.rst

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
Special Validator
22
=================
33

4-
Special validators are validators that are used to combine or mutate the normal validators.
5-
They are used to create complex validation logic by combining multiple validators or inverting the result of a validator.
6-
74
Overview
85
--------
96

7+
Special validators are validators that are used to combine or mutate the normal validators.
8+
They are used to create complex validation logic by combining multiple validators or inverting the result of a validator.
109

1110
Example
12-
11+
-------
1312

1413
.. code-block:: python
1514
@@ -29,14 +28,43 @@ Available Special Validators
2928
The following special validators are available:
3029

3130
- `AndValidator`_
32-
- `IfValidator`_
3331
- `NotValidator`_
3432
- `OrValidator`_
3533
- `XorValidator`_
3634

3735
Detailed Description
3836
--------------------
3937

38+
AndValidator
39+
~~~~~~~~~~~~
40+
41+
**Description:**
42+
43+
Validates that the input passes all of the provided validators. This composite validator performs a logical AND over its constituent validators.
44+
45+
**Parameters:**
46+
47+
- **validators** (*List[BaseValidator]*): A list of validators that must all pass.
48+
- **error_message** (*Optional[str]*): Custom error message if any of the validators fail.
49+
50+
**Expected Behavior:**
51+
52+
The validator sequentially applies each validator in the provided list to the input value. If any validator raises a ``ValidationError``, the AndValidator immediately raises a ``ValidationError``. If all validators pass, the input is considered valid.
53+
54+
**Example Usage:**
55+
56+
.. code-block:: python
57+
58+
from flask_inputfilter import InputFilter
59+
from flask_inputfilter.Validator import AndValidator, IsIntegerValidator, RangeValidator
60+
61+
class AndInputFilter(InputFilter):
62+
def __init__(self):
63+
super().__init__()
64+
self.add('value', validators=[
65+
AndValidator([IsIntegerValidator(), RangeValidator(min_value=0, max_value=100)])
66+
])
67+
4068
NotValidator
4169
~~~~~~~~~~~~
4270
**Description:**
@@ -65,3 +93,64 @@ Executes the inner validator on the input. If the inner validator does not raise
6593
self.add('value', validators=[
6694
NotValidator(validator=IsIntegerValidator())
6795
])
96+
97+
OrValidator
98+
~~~~~~~~~~~
99+
100+
**Description:**
101+
102+
Validates that the input passes at least one of the provided validators. This composite validator performs a logical OR over its constituent validators.
103+
104+
**Parameters:**
105+
106+
- **validators** (*List[BaseValidator]*): A list of validators to apply.
107+
- **error_message** (*Optional[str]*): Custom error message if none of the validators pass.
108+
109+
**Expected Behavior:**
110+
111+
The validator applies each validator in the provided list to the input value. If any one validator passes without raising a ``ValidationError``, the validation is considered successful. If all validators fail, it raises a ``ValidationError`` with the provided error message or a default message.
112+
113+
**Example Usage:**
114+
115+
.. code-block:: python
116+
117+
from flask_inputfilter import InputFilter
118+
from flask_inputfilter.Validator import OrValidator, IsIntegerValidator, IsStringValidator
119+
120+
class OrInputFilter(InputFilter):
121+
def __init__(self):
122+
super().__init__()
123+
self.add('value', validators=[
124+
OrValidator([IsIntegerValidator(), IsStringValidator()])
125+
])
126+
127+
XorValidator
128+
~~~~~~~~~~~~
129+
130+
**Description:**
131+
132+
Validates that the input passes exactly one of the provided validators. This composite validator ensures that the input does not pass zero or more than one of the specified validators.
133+
134+
**Parameters:**
135+
136+
- **validators** (*List[BaseValidator]*): A list of validators, of which exactly one must pass.
137+
- **error_message** (*Optional[str]*): Custom error message if the input does not satisfy exactly one validator.
138+
139+
**Expected Behavior:**
140+
141+
The validator applies each validator in the provided list to the input value and counts the number of validators that pass without raising a ``ValidationError``. If exactly one validator passes, the input is considered valid; otherwise, a ``ValidationError`` is raised with the provided or default error message.
142+
143+
**Example Usage:**
144+
145+
.. code-block:: python
146+
147+
from flask_inputfilter import InputFilter
148+
from flask_inputfilter.Validator import XorValidator, IsIntegerValidator, IsStringValidator
149+
150+
class XorInputFilter(InputFilter):
151+
def __init__(self):
152+
super().__init__()
153+
154+
self.add('value', validators=[
155+
XorValidator([IsIntegerValidator(), IsStringValidator()])
156+
])

0 commit comments

Comments
 (0)