connexion.middleware

Submodules

Package Contents

Classes

AppMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base

RoutedMiddleware

Baseclass for middleware that wants to leverage the RoutingMiddleware to route requests to

ConnexionMiddleware

High level Connexion middleware that manages a list o middlewares wrapped around an

RoutingMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base

SwaggerUIMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base

class connexion.middleware.AppMiddleware

Bases: abc.ABC

Middlewares that need the APIs to be registered on them should inherit from this base class

__slots__ = []
abstract add_api(self, specification: Union[pathlib.Path, str, dict], **kwargs) None
class connexion.middleware.RoutedMiddleware(app: starlette.types.ASGIApp)

Bases: AppMiddleware, Generic[API]

Baseclass for middleware that wants to leverage the RoutingMiddleware to route requests to its operations.

The RoutingMiddleware adds the operation_id to the ASGI scope. This middleware registers its operations by operation_id at startup. At request time, the operation is fetched by an operation_id lookup.

api_cls :Type[API]

The subclass of RoutedAPI this middleware uses.

__slots__ = []
add_api(self, specification: Union[pathlib.Path, str, dict], **kwargs) None
async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None

Fetches the operation related to the request and calls it.

classmethod __class_getitem__(cls, params)
classmethod __init_subclass__(cls, *args, **kwargs)
class connexion.middleware.ConnexionMiddleware(app: starlette.types.ASGIApp, middlewares: Optional[List[Type[starlette.types.ASGIApp]]] = None)

High level Connexion middleware that manages a list o middlewares wrapped around an application.

Parameters:
  • app – App to wrap middleware around.

  • middlewares – List of middlewares to wrap around app. The list should be ordered from outer to inner middleware.

default_middlewares
add_api(self, specification: Union[pathlib.Path, str, dict], base_path: Optional[str] = None, arguments: Optional[dict] = None, **kwargs) None

Add an API to the underlying routing middleware based on a OpenAPI spec.

Parameters:
  • specification – OpenAPI spec as dict or path to file.

  • base_path – Base path where to add this API.

  • arguments – Jinja arguments to replace in the spec.

async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None
class connexion.middleware.RoutingMiddleware(app: starlette.types.ASGIApp)

Bases: connexion.middleware.abstract.AppMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base class

Middleware that resolves the Operation for an incoming request and attaches it to the scope.

Parameters:

app – app to wrap in middleware.

__slots__ = []
add_api(self, specification: Union[pathlib.Path, str, dict], base_path: Optional[str] = None, arguments: Optional[dict] = None, **kwargs) None

Add an API to the router based on a OpenAPI spec.

Parameters:
  • specification – OpenAPI spec as dict or path to file.

  • base_path – Base path where to add this API.

  • arguments – Jinja arguments to replace in the spec.

async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None

Route request to matching operation, and attach it to the scope before calling the next app.

class connexion.middleware.SwaggerUIMiddleware(app: starlette.types.ASGIApp)

Bases: connexion.middleware.AppMiddleware

Middlewares that need the APIs to be registered on them should inherit from this base class

Middleware that hosts a swagger UI.

Parameters:

app – app to wrap in middleware.

__slots__ = []
add_api(self, specification: Union[pathlib.Path, str, dict], base_path: Optional[str] = None, arguments: Optional[dict] = None, **kwargs) None

Add an API to the router based on a OpenAPI spec.

Parameters:
  • specification – OpenAPI spec as dict or path to file.

  • base_path – Base path where to add this API.

  • arguments – Jinja arguments to replace in the spec.

async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None
async default_fn(self, _scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None

Callback to call next app as default when no matching route is found.

Unfortunately we cannot just pass the next app as default, since the router manipulates the scope when descending into mounts, losing information about the base path. Therefore, we use the original scope instead.

This is caused by https://github.com/encode/starlette/issues/1336.