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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ dist/
__pycache__/
*.egg-info
*.pyc
test.py
test.py

venv/
.venv/
env/
.env
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def hello(
password_expiry: Optional[int] = Json(5),
is_admin: bool = Query(False),
user_type: UserType = Json(alias="type"),
status: AccountStatus = Json()
status: AccountStatus = Json(),
permissions: dict[str, str] = Query(list_disable_query_csv=True)
):
return "Hello World!"

Expand Down Expand Up @@ -130,7 +131,7 @@ Type Hints allow for inline specification of the input type of a parameter. Some
| `datetime.datetime` | Received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
| `datetime.date` | Received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
| `datetime.time` | Received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
| `dict` | For `Query` and `Form` inputs, users should pass the stringified JSON | N | Y | Y | Y | N |
| `dict` | For `Query` and `Form` inputs, users should pass the stringified JSON. For `Query`, you likely will need to use `list_disable_query_csv=True`. | N | Y | Y | Y | N |
| `FileStorage` | | N | N | N | N | Y |
| A subclass of `StrEnum` or `IntEnum`, or a subclass of `Enum` with `str` or `int` mixins prior to Python 3.11 | | Y | Y | Y | Y | N |
| `uuid.UUID` | Received as a `str` with or without hyphens, case-insensitive | Y | Y | Y | Y | N |
Expand Down
10 changes: 8 additions & 2 deletions flask_parameter_validation/docs_blueprint.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys
from enum import Enum
import flask
from flask import Blueprint, current_app, jsonify

from flask_parameter_validation import ValidateParameters

if sys.version_info >= (3, 10):
from types import UnionType

docs_blueprint = Blueprint(
"docs", __name__, url_prefix="/docs", template_folder="./templates"
)
Expand Down Expand Up @@ -76,7 +79,10 @@ def get_arg_type_hint(fdocs, arg_name):
"""
arg_type = fdocs["argspec"].annotations[arg_name]
def recursively_resolve_type_hint(type_to_resolve):
if hasattr(type_to_resolve, "__name__"): # In Python 3.9, Optional and Union do not have __name__
if sys.version_info >= (3, 10) and isinstance(type_to_resolve, UnionType):
# support 3.10 style unions (e.g. str | int)
type_base_name = "Union"
elif hasattr(type_to_resolve, "__name__"): # In Python 3.9, Optional and Union do not have __name__
type_base_name = type_to_resolve.__name__
elif hasattr(type_to_resolve, "_name") and type_to_resolve._name is not None:
# In Python 3.9, _name exists on list[whatever] and has a non-None value
Expand Down
3 changes: 2 additions & 1 deletion flask_parameter_validation/parameter_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from .query import Query
from .route import Route
from .multi_source import MultiSource
from .parameter import Parameter

__all__ = [
"File", "Form", "Json", "Query", "Route", "MultiSource"
"File", "Form", "Json", "Query", "Route", "MultiSource", "Parameter"
]
Loading