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

Draft : Adding provision to pass inputs to custom error handler class #919

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
9 changes: 8 additions & 1 deletion openapi_core/contrib/flask/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ def __init__(
errors_handler_cls: Type[
FlaskOpenAPIErrorsHandler
] = FlaskOpenAPIErrorsHandler,
error_handler_params: dict = None
):
super().__init__(openapi)
self.request_cls = request_cls
self.response_cls = response_cls
self.request_provider = request_provider
self.errors_handler_cls = errors_handler_cls
self.error_handler_params = error_handler_params

def __call__(self, view: Callable[..., Any]) -> Callable[..., Any]:
@wraps(view)
Expand All @@ -48,7 +50,10 @@ def decorated(*args: Any, **kwargs: Any) -> Response:
valid_request_handler = self.valid_request_handler_cls(
request, view, *args, **kwargs
)
errors_handler = self.errors_handler_cls()
if self.error_handler_params is None:
errors_handler = self.errors_handler_cls()
else:
errors_handler = self.errors_handler_cls(self.error_handler_params)
response = self.handle_request(
request, valid_request_handler, errors_handler
)
Expand All @@ -69,6 +74,7 @@ def from_spec(
errors_handler_cls: Type[
FlaskOpenAPIErrorsHandler
] = FlaskOpenAPIErrorsHandler,
error_handler_params: dict = None
) -> "FlaskOpenAPIViewDecorator":
openapi = OpenAPI(spec)
return cls(
Expand All @@ -77,4 +83,5 @@ def from_spec(
response_cls=response_cls,
request_provider=request_provider,
errors_handler_cls=errors_handler_cls,
error_handler_params=error_handler_params
)
Loading