Skip to content

Commit 2fc5524

Browse files
committed
Fix merge conflicts in readme
1 parent cae2a9a commit 2fc5524

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if __name__ == "__main__":
3838
## Usage
3939
To validate parameters with flask-parameter-validation, two conditions must be met.
4040
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` for the parameters you want to use flask-parameter-validation on
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
4242

4343

4444
### Enable and customize Validation for a Route with the @ValidateParameters decorator
@@ -49,7 +49,14 @@ The `@ValidateParameters()` decorator takes parameters that alter route validati
4949
| error_handler | `Optional[Response]` | `None` | Overwrite the output format of generated errors, see [Overwriting Default Errors](#overwriting-default-errors) for more |
5050

5151
#### Overwriting Default Errors
52-
By default, the error messages are returned as a JSON response, with the detailed error in the "error" field. However, this can be edited by passing a custom error function into the `ValidateParameters()` decorator. For example:
52+
By default, the error messages are returned as a JSON response, with the detailed error in the "error" field, eg:
53+
```json
54+
{
55+
"error": "Parameter 'age' must be type 'int'"
56+
}
57+
```
58+
59+
However, this can be edited by passing a custom error function into the `ValidateParameters()` decorator. For example:
5360
```py
5461
def error_handler(err):
5562
error_name = type(err)
@@ -70,15 +77,17 @@ def api(...)
7077
#### Parameter Class
7178
The `Parameter` class provides a base for validation common among all input types, all location-specific classes extend `Parameter`. These subclasses are:
7279

73-
| Subclass Name | Input Source | Available For |
74-
|---------------|------------------------------------------------------------------------------------------------------------------------|---------------------------------|
75-
| Route | Parameter passed in the pathname of the URL, such as `/users/<int:id>` | All HTTP Methods |
76-
| Form | Parameter in an HTML form or a `FormData` object in the request body, often with `Content-Type: x-www-form-urlencoded` | POST Methods |
77-
| Json | Parameter in the JSON object in the request body, must have header `Content-Type: application/json` | POST Method |
78-
| Query | Parameter in the query of the URL, such as /news_article?id=55 | All HTTP Methods |
79-
| File | Parameter is a file uploaded in the request body | POST Method |
80+
| Subclass Name | Input Source | Available For |
81+
|---------------|------------------------------------------------------------------------------------------------------------------------|------------------|
82+
| Route | Parameter passed in the pathname of the URL, such as `/users/<int:id>` | All HTTP Methods |
83+
| Form | Parameter in an HTML form or a `FormData` object in the request body, often with `Content-Type: x-www-form-urlencoded` | POST Methods |
84+
| Json | Parameter in the JSON object in the request body, must have header `Content-Type: application/json` | POST Methods |
85+
| Query | Parameter in the query of the URL, such as /news_article?id=55 | All HTTP Methods |
86+
| File | Parameter is a file uploaded in the request body | POST Method |
8087
| MultiSource | Parameter is in one of the locations provided to the constructor | Dependent on selected locations |
8188

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+
8291
##### MultiSource Parameters
8392
Using the `MultiSource` parameter type, parameters can be accepted from any combination of `Parameter` subclasses. Example usage is as follows:
8493

@@ -93,6 +102,7 @@ def multi_source_example(
93102

94103
The above example will accept parameters passed to the route through Route, Query, and JSON Body.
95104

105+
96106
#### Type Hints and Accepted Input Types
97107
Type Hints allow for inline specification of the input type of a parameter. Some types are only available to certain `Parameter` subclasses.
98108

flask_parameter_validation/parameter_types/parameter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import re
66
from datetime import date, datetime, time
7+
78
import dateutil.parser as parser
89
import jsonschema
910
from jsonschema.exceptions import ValidationError as JSONSchemaValidationError
@@ -150,8 +151,6 @@ def validate(self, value):
150151
if self.func is not None and not original_value_type_list:
151152
self.func_helper(value)
152153

153-
154-
155154
return True
156155

157156
def convert(self, value, allowed_types):

0 commit comments

Comments
 (0)