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
Copy file name to clipboardExpand all lines: README.md
+38-23Lines changed: 38 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -61,48 +61,63 @@ def error_handler(err):
61
61
"error_message": str(err)
62
62
}, 400
63
63
64
-
@ValidateParameters(error_handler)
65
64
@app.route(...)
65
+
@ValidateParameters(error_handler)
66
66
defapi(...)
67
67
```
68
68
69
69
### Specify Parameter types and constraints with type hints and subclasses of Parameter
70
70
#### Parameter Class
71
71
The `Parameter` class provides a base for validation common among all input types, all location-specific classes extend `Parameter`. These subclasses are:
The above example will accept parameters passed to the route through Route, Query, and JSON Body. Validation options must be specified on each constructor in order to be processed.
80
95
81
96
#### Type Hints and Accepted Input Types
82
97
Type Hints allow for inline specification of the input type of a parameter. Some types are only available to certain `Parameter` subclasses.
83
98
84
-
| Type Hint / Expected Python Type | Notes |`Route`|`Form`|`Json`|`Query`|`File`|
|`typing.List` (must not be `list`) | For `Query` 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 |
91
-
|`typing.Union`|| Y | Y | Y | Y | N |
92
-
|`typing.Optional`|| Y | Y | Y | Y | Y |
93
-
|`datetime.datetime`|received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
94
-
|`datetime.date`|received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
95
-
|`datetime.time`|received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
96
-
|`dict`|| N | N | Y | N | N |
97
-
|`FileStorage`|| N | N | N | N | Y |
99
+
| 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 |
106
+
|`typing.Union`|Cannot be used inside of `typing.List`| Y | Y | Y | Y | N |
107
+
|`typing.Optional`|| Y | Y | Y | Y | Y |
108
+
|`datetime.datetime`|Received as a `str` in ISO-8601 date-time format| Y | Y | Y | Y | N |
109
+
|`datetime.date`|Received as a `str` in ISO-8601 full-date format| Y | Y | Y | Y | N |
110
+
|`datetime.time`|Received as a `str` in ISO-8601 partial-time format| Y | Y | Y | Y | N |
111
+
|`dict`|For `Query` and `Form` inputs, users should pass the stringified JSON| N | N | Y | N | N |
112
+
|`FileStorage`|| N | N | N | N | Y |
98
113
99
114
These can be used in tandem to describe a parameter to validate: `parameter_name: type_hint = ParameterSubclass()`
100
115
-`parameter_name`: The field name itself, such as username
101
116
-`type_hint`: The expected Python data type
102
117
-`ParameterSubclass`: An instance of a subclass of `Parameter`
103
118
104
119
### Validation with arguments to Parameter
105
-
Validation beyond type-checking can be done by passing arguments into the constructor of the `Parameter` subclass. The arguments available for use on each type hint are:
120
+
Validation beyond type-checking can be done by passing arguments into the constructor of the `Parameter` subclass (with the exception of `MultiSource`). The arguments available for use on each type hint are:
106
121
107
122
| Parameter Name | Type of Parameter | Effective On Types | Description |
0 commit comments