Skip to content

Commit 8af04b7

Browse files
committed
Dev note removal
1 parent d8f5d7d commit 8af04b7

File tree

2 files changed

+12
-42
lines changed

2 files changed

+12
-42
lines changed

README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ app = Flask(__name__)
2121
@ValidateParameters()
2222
def hello(
2323
id: int = Route(),
24-
username: str = Json(min_length=5, blacklist="<>"),
24+
username: str = Json(min_str_length=5, blacklist="<>"),
2525
age: int = Json(min_int=18, max_int=99),
2626
nicknames: List[str] = Json(),
2727
password_expiry: Optional[int] = Json(5),
@@ -79,10 +79,16 @@ These validators are passed into the classes in the route function, such as:
7979
### Overwriting default errors
8080
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:
8181
```py
82-
def my_error_func(error_message):
83-
return f"This is the error! Please sort it out! {error_message}", 400
84-
85-
86-
@ValidateParameters(my_error_func)
82+
def error_handler(err):
83+
error_name = type(err)
84+
error_parameters = err.args
85+
error_message = str(err)
86+
return {
87+
"error_name": type(err).__name__,
88+
"error_parameters": err.args,
89+
"error_message": str(err)
90+
}, 400
91+
92+
@ValidateParameters(error_handler)
8793
def api(...)
8894
```

flask_parameter_validation/parameter_validation.py

-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Class
3-
"""
4-
import typing
51
from parameter_types import Route, Json, Query, Form, File
62
from exceptions import MissingInputError, InvalidParameterTypeError, ValidationError
73
from flask import request
@@ -138,35 +134,3 @@ def validate(self, expected_input, all_request_inputs):
138134

139135
# Return input back to parent function
140136
return user_input
141-
142-
"""
143-
Test
144-
"""
145-
from flask import Flask
146-
from typing import List, Union, Optional
147-
app = Flask(__name__)
148-
149-
def handler(err):
150-
error_name = type(err)
151-
error_parameters = err.args
152-
error_message = str(err)
153-
return {
154-
"error_name": type(err).__name__,
155-
"error_parameters": err.args,
156-
"error_message": str(err)
157-
}, 400
158-
159-
@app.route("/update/<int:id>", methods=["POST"])
160-
@ValidateParameters(handler)
161-
def hello(
162-
id: int = Route(),
163-
username: str = Json(min_str_length=5, blacklist="<>"),
164-
age: int = Json(min_int=18, max_int=99),
165-
nicknames: List[str] = Json(),
166-
password_expiry: Union[int, float] = Json(),
167-
is_admin: bool = Query(False)
168-
):
169-
return "Hello World!"
170-
171-
if __name__ == "__main__":
172-
app.run()

0 commit comments

Comments
 (0)