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
+33-15Lines changed: 33 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -68,8 +68,8 @@ def error_handler(err):
68
68
"error_message": str(err)
69
69
}, 400
70
70
71
-
@ValidateParameters(error_handler)
72
71
@app.route(...)
72
+
@ValidateParameters(error_handler)
73
73
defapi(...)
74
74
```
75
75
@@ -84,26 +84,44 @@ The `Parameter` class provides a base for validation common among all input type
84
84
| Json | Parameter in the JSON object in the request body, must have header `Content-Type: application/json`| POST Methods |
85
85
| Query | Parameter in the query of the URL, such as /news_article?id=55 | All HTTP Methods |
86
86
| File | Parameter is a file uploaded in the request body | POST Method |
87
+
| MultiSource | Parameter is in one of the locations provided to the constructor | Dependent on selected locations |
88
+
89
+
Note: "**POST Methods**" refers to the HTTP methods that send data in the request body, such as POST, PUT, PATCH and DELETE. Although sending data via some methods such as DELETE is not standard, it is supported by Flask and this library.
90
+
91
+
##### MultiSource Parameters
92
+
Using the `MultiSource` parameter type, parameters can be accepted from any combination of `Parameter` subclasses. Example usage is as follows:
93
+
94
+
```py
95
+
@app.route("/")
96
+
@app.route("/<v>") # If accepting parameters by Route and another type, a path with and without that Route parameter must be specified
The above example will accept parameters passed to the route through Route, Query, and JSON Body.
104
+
87
105
88
106
Note: "**POST Methods**" refers to the HTTP methods that send data in the request body, such as POST, PUT, PATCH and DELETE. Although sending data via some methods such as DELETE is not standard, it is supported by Flask and this library.
89
107
90
108
#### Type Hints and Accepted Input Types
91
109
Type Hints allow for inline specification of the input type of a parameter. Some types are only available to certain `Parameter` subclasses.
92
110
93
-
| 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 |
100
-
|`typing.Union`|| Y | Y | Y | Y | N |
101
-
|`typing.Optional`|| Y | Y | Y | Y | Y |
102
-
|`datetime.datetime`|received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
103
-
|`datetime.date`|received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
104
-
|`datetime.time`|received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
105
-
|`dict`|| N |N| Y |N| N |
106
-
|`FileStorage`|| N | N | N | N | Y |
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 |
107
125
108
126
These can be used in tandem to describe a parameter to validate: `parameter_name: type_hint = ParameterSubclass()`
109
127
-`parameter_name`: The field name itself, such as username
0 commit comments