From 8c49cb2e55b23c06dfc2a82fb0c5eb147f2c7263 Mon Sep 17 00:00:00 2001 From: Rohan Date: Mon, 16 Sep 2024 18:08:33 +0530 Subject: [PATCH] Adding provision to pass inputs to custom error handler class --- openapi_core/contrib/flask/decorators.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openapi_core/contrib/flask/decorators.py b/openapi_core/contrib/flask/decorators.py index 4dc949e9..92d7d0d2 100644 --- a/openapi_core/contrib/flask/decorators.py +++ b/openapi_core/contrib/flask/decorators.py @@ -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) @@ -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 ) @@ -69,6 +74,7 @@ def from_spec( errors_handler_cls: Type[ FlaskOpenAPIErrorsHandler ] = FlaskOpenAPIErrorsHandler, + error_handler_params: dict = None ) -> "FlaskOpenAPIViewDecorator": openapi = OpenAPI(spec) return cls( @@ -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 )