Skip to content

Commit

Permalink
Initialize RoutingOperation with operation object
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeSneyders committed Jun 20, 2022
1 parent 3f0a7d9 commit 396ce08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions connexion/apis/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __init__(
specification: t.Union[pathlib.Path, str, dict],
base_path: t.Optional[str] = None,
resolver: t.Optional[Resolver] = None,
resolver_error_handler: t.Optional[t.Callable] = None,
arguments: t.Optional[dict] = None,
options: t.Optional[dict] = None,
*args,
Expand Down Expand Up @@ -75,7 +74,6 @@ def __init__(

self._set_base_path(base_path)

self.resolver_error_handler = resolver_error_handler
self.resolver = resolver or Resolver()

def _set_base_path(self, base_path: t.Optional[str] = None) -> None:
Expand Down Expand Up @@ -129,6 +127,7 @@ class AbstractRoutingAPI(AbstractSpecAPI):
def __init__(
self,
*args,
resolver_error_handler: t.Optional[t.Callable] = None,
debug: bool = False,
pass_context_arg_name: t.Optional[str] = None,
**kwargs
Expand All @@ -141,6 +140,7 @@ def __init__(
"""
super().__init__(*args, **kwargs)
self.debug = debug
self.resolver_error_handler = resolver_error_handler

logger.debug('pass_context_arg_name: %s', pass_context_arg_name)
self.pass_context_arg_name = pass_context_arg_name
Expand Down
7 changes: 6 additions & 1 deletion connexion/middleware/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from connexion.apis import AbstractRoutingAPI
from connexion.exceptions import NotFoundProblem
from connexion.middleware import AppMiddleware
from connexion.operations import AbstractOperation
from connexion.resolver import Resolver

ROUTING_CONTEXT = 'connexion_routing'
Expand Down Expand Up @@ -91,7 +92,7 @@ def __init__(
def add_operation(self, path: str, method: str) -> None:
operation_cls = self.specification.operation_cls
operation = operation_cls.from_spec(self.specification, self, path, method, self.resolver)
routing_operation = RoutingOperation(operation.operation_id, next_app=self.next_app)
routing_operation = RoutingOperation.from_operation(operation, next_app=self.next_app)
self._add_operation_internal(method, path, routing_operation)

def _add_operation_internal(self, method: str, path: str, operation: 'RoutingOperation') -> None:
Expand All @@ -104,6 +105,10 @@ def __init__(self, operation_id: t.Optional[str], next_app: ASGIApp) -> None:
self.operation_id = operation_id
self.next_app = next_app

@classmethod
def from_operation(cls, operation: AbstractOperation, next_app: ASGIApp):
return cls(operation.operation_id, next_app)

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
"""Attach operation to scope and pass it to the next app"""
original_scope = _scope.get()
Expand Down

0 comments on commit 396ce08

Please sign in to comment.