connexion.middleware.abstract

Module Contents

Classes

AppMiddleware

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

RoutedOperation

Base class for protocol classes. Protocol classes are defined as:

RoutedAPI

Abstract base class for generic types.

RoutedMiddleware

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

Attributes

logger

ROUTING_CONTEXT

OP

API

connexion.middleware.abstract.logger
connexion.middleware.abstract.ROUTING_CONTEXT = connexion_routing
class connexion.middleware.abstract.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.abstract.RoutedOperation(next_app: starlette.types.ASGIApp, **kwargs)

Bases: typing_extensions.Protocol

Base class for protocol classes. Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing_extensions.runtime act as simple-minded runtime protocol that checks only the presence of given attributes, ignoring their type signatures.

Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
__slots__ = []
async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send) None
classmethod __class_getitem__(cls, params)
classmethod __init_subclass__(cls, *args, **kwargs)
connexion.middleware.abstract.OP
class connexion.middleware.abstract.RoutedAPI(specification: Union[pathlib.Path, str, dict], *args, next_app: starlette.types.ASGIApp, **kwargs)

Bases: connexion.apis.abstract.AbstractSpecAPI, Generic[OP]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default

Base API class with only minimal behavior related to the specification.

Parameters:
  • specification – OpenAPI specification. Can be provided either as dict, or as path to file.

  • base_path – Base path to host the API.

  • resolver – Callable that maps operationID to a function

  • resolver_error_handler – Callable that generates an Operation used for handling ResolveErrors

  • arguments – Jinja arguments to resolve in specification.

  • options – New style options dictionary.

operation_cls :Type[OP]

The operation this middleware uses, which should implement the RoutingOperation protocol.

__slots__ = []
add_paths(self) None
add_operation(self, path: str, method: str) None
abstract make_operation(self, operation: connexion.operations.AbstractOperation) OP

Create an operation of the operation_cls type.

classmethod __class_getitem__(cls, params)
classmethod __init_subclass__(cls, *args, **kwargs)
connexion.middleware.abstract.API
class connexion.middleware.abstract.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)
exception connexion.middleware.abstract.MissingOperation

Bases: Exception

Missing operation

Initialize self. See help(type(self)) for accurate signature.

class __cause__

exception cause

class __context__

exception context

class __suppress_context__
class __traceback__
class args
__delattr__()

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__()

Return self==value.

__format__()

Default object formatter.

__ge__()

Return self>=value.

__getattribute__()

Return getattr(self, name).

__gt__()

Return self>value.

__hash__()

Return hash(self).

__le__()

Return self<=value.

__lt__()

Return self<value.

__ne__()

Return self!=value.

__reduce__()

Helper for pickle.

__reduce_ex__()

Helper for pickle.

__repr__()

Return repr(self).

__setattr__()

Implement setattr(self, name, value).

__setstate__()
__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.