Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 250 additions & 47 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/usage_example_non_standard_documentation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
378 changes: 352 additions & 26 deletions flask_parameter_validation/docs_blueprint.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions flask_parameter_validation/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ def __init__(self, error_string, input_name, input_type):
)
super().__init__(error_string, input_name, input_type)

def __str__(self):
return self.message

class ConfigurationError(Exception):
"""Called if app configuration is invalid"""

def __init__(self, message):
self.message = message
super().__init__(message)

def __str__(self):
return self.message
1 change: 1 addition & 0 deletions flask_parameter_validation/parameter_types/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def validate(self, value):
except JSONSchemaValidationError as e:
raise ValueError(f"failed JSON Schema validation: {e.args[0]}")
elif type(value) is dict:
# TODO: Make json_schema work for all parameters besides FileStorage and datetime.*? Or maybe even datetime.*?
if self.json_schema is not None:
try:
jsonschema.validate(value, self.json_schema)
Expand Down
4 changes: 3 additions & 1 deletion flask_parameter_validation/parameter_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class ValidateParameters:
def get_fn_list(cls):
return fn_list

def __init__(self, error_handler=None):
def __init__(self, error_handler=None, openapi_responses=None):
self.custom_error_handler = error_handler
self.openapi_responses = openapi_responses

def __call__(self, f):
"""
Expand All @@ -59,6 +60,7 @@ def __call__(self, f):
"argspec": argspec,
"docstring": f.__doc__.strip() if f.__doc__ else None,
"decorators": decorators.copy(),
"openapi_responses": self.openapi_responses,
}
fn_list[fsig] = fdocs

Expand Down
16 changes: 12 additions & 4 deletions flask_parameter_validation/test/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@


class Fruits(str, Enum):
APPLE = "apple"
ORANGE = "orange"
"""
Possible fruits
"""

APPLE = "apple" # An apple a day keeps the doctor away, so they say
ORANGE = "orange" # Oranges contain vitamin C, which might also keep the doctor away


class Binary(int, Enum):
ZERO = 0
ONE = 1
"""
Possible binary values
"""

ZERO = 0 # Logic level low
ONE = 1 # Logic level high
Loading
Loading