You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To validate parameters with flask-parameter-validation, two conditions must be met.
40
40
1. The `@ValidateParameters()` decorator must be applied to the function
41
-
2. Type hints ([supported types](#type-hints-and-accepted-input-types)) and a default of a subclass of `Parameter` must be supplied per parameter flask-parameter-validation parameter
41
+
2. Type hints ([supported types](#type-hints-and-accepted-input-types)) and a default of a subclass of `Parameter` must be supplied per parameter
42
42
43
43
44
44
### Enable and customize Validation for a Route with the @ValidateParameters decorator
@@ -108,20 +108,20 @@ Note: "**POST Methods**" refers to the HTTP methods that send data in the reques
108
108
#### Type Hints and Accepted Input Types
109
109
Type Hints allow for inline specification of the input type of a parameter. Some types are only available to certain `Parameter` subclasses.
110
110
111
-
| Type Hint / Expected Python Type | Notes |`Route`|`Form`|`Json`|`Query`|`File`|
|`typing.List` (must not be `list`)| For `Query` and `Form` inputs, users can pass via either `value=1&value=2&value=3`, or `value=1,2,3`, both will be transformed to a `list`.| N | Y | Y | Y | N |
118
-
|`typing.Union`| Cannot be used inside of `typing.List`| Y | Y | Y | Y | N |
119
-
|`typing.Optional`|| Y | Y | Y | Y | Y |
120
-
|`datetime.datetime`| Received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
121
-
|`datetime.date`| Received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
122
-
|`datetime.time`| Received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
123
-
|`dict`| For `Query` and `Form` inputs, users should pass the stringified JSON | N | Y | Y | Y | N |
124
-
|`FileStorage`|| N | N | N | N | Y |
111
+
| Type Hint / Expected Python Type | Notes |`Route`|`Form`|`Json`|`Query`|`File`|
|`list`/`typing.List` (`typing.List` is [deprecated](https://docs.python.org/3/library/typing.html#typing.List))| For `Query` and `Form` inputs, users can pass via either `value=1&value=2&value=3`, or `value=1,2,3`, both will be transformed to a `list`| N | Y | Y | Y | N |
118
+
|`typing.Union`| Cannot be used inside of `typing.List`| Y | Y | Y | Y | N |
119
+
|`typing.Optional`|| Y | Y | Y | Y | Y |
120
+
|`datetime.datetime`| Received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
121
+
|`datetime.date`| Received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
122
+
|`datetime.time`| Received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
123
+
|`dict`| For `Query` and `Form` inputs, users should pass the stringified JSON | N | Y | Y | Y | N |
124
+
|`FileStorage`|| N | N | N | N | Y |
125
125
126
126
These can be used in tandem to describe a parameter to validate: `parameter_name: type_hint = ParameterSubclass()`
127
127
-`parameter_name`: The field name itself, such as username
@@ -136,8 +136,8 @@ Validation beyond type-checking can be done by passing arguments into the constr
136
136
|`default`| any | All | Specifies the default value for the field, makes non-Optional fields not required |
137
137
|`min_str_length`|`int`|`str`| Specifies the minimum character length for a string input |
138
138
|`max_str_length`|`int`|`str`| Specifies the maximum character length for a string input |
139
-
|`min_list_length`|`int`|`typing.List`| Specifies the minimum number of elements in a list |
140
-
|`max_list_length`|`int`|`typing.List`| Specifies the maximum number of elements in a list |
139
+
|`min_list_length`|`int`|`list`| Specifies the minimum number of elements in a list |
140
+
|`max_list_length`|`int`|`list`| Specifies the maximum number of elements in a list |
141
141
|`min_int`|`int`|`int`| Specifies the minimum number for an integer input |
142
142
|`max_int`|`int`|`int`| Specifies the maximum number for an integer input |
143
143
|`whitelist`|`str`|`str`| A string containing allowed characters for the value |
0 commit comments