Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "errors" field to ValidationError #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions flask_pydantic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,31 @@ def __init__(
self.form_params = form_params
self.path_params = path_params
self.query_params = query_params

# Combine the previous types or errors in the same array,
# so the errors can be used like with the original Pydantic library
self.errors: List[dict] = []
if body_params:
for param in body_params:
new_param = param.copy()
new_param["loc"] = list(param["loc"])
new_param["loc"].insert(0, "body")
self.errors.append(new_param)
if form_params:
for param in form_params:
new_param = param.copy()
new_param["loc"] = list(param["loc"])
new_param["loc"].insert(0, "form")
self.errors.append(new_param)
if path_params:
for param in path_params:
new_param = param.copy()
new_param["loc"] = list(param["loc"])
new_param["loc"].insert(0, "path")
self.errors.append(new_param)
if query_params:
for param in query_params:
new_param = param.copy()
new_param["loc"] = list(param["loc"])
new_param["loc"].insert(0, "query")
self.errors.append(new_param)