Validation Middleware.

Module Contents




Validation API.


Middleware for validating requests according to the API contract.



class connexion.middleware.request_validation.RequestValidationOperation(next_app: starlette.types.ASGIApp, *, operation: connexion.operations.AbstractOperation, strict_validation: bool = False, validator_map: Optional[dict] = None)
extract_content_type(self, headers: List[Tuple[bytes, bytes]]) Tuple[str, str]

Extract the mime type and encoding from the content type headers.


headers – Headers from ASGI scope


A tuple of mime type, encoding

validate_mime_type(self, mime_type: str) None

Validate the mime type against the spec.


mime_type – mime type from content type header

async __call__(self, scope: starlette.types.Scope, receive: starlette.types.Receive, send: starlette.types.Send)
class connexion.middleware.request_validation.RequestValidationAPI(*args, strict_validation=False, validator_map=None, uri_parser_class=None, **kwargs)

Bases: connexion.middleware.abstract.RoutedAPI[RequestValidationOperation]

Validation API.

__slots__ = []
make_operation(self, operation: connexion.operations.AbstractOperation) RequestValidationOperation

Create an operation of the operation_cls type.

add_paths(self) None
add_operation(self, path: str, method: str) None
classmethod __class_getitem__(cls, params)
classmethod __init_subclass__(cls, *args, **kwargs)
class connexion.middleware.request_validation.RequestValidationMiddleware(app: starlette.types.ASGIApp)

Bases: connexion.middleware.abstract.RoutedMiddleware[RequestValidationAPI]

Middleware for validating requests according to the API contract.

__slots__ = []
add_api(self, specification: Union[pathlib.Path, str, dict], **kwargs) API

Register an API represented by a single OpenAPI specification on this middleware. Multiple APIs can be registered on a single middleware.

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.request_validation.MissingValidationOperation

Bases: Exception

Missing validation 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

Implement delattr(self, name).


Default dir() implementation.


Return self==value.


Default object formatter.


Return self>=value.


Return getattr(self, name).


Return self>value.


Return hash(self).


Return self<=value.


Return self<value.


Return self!=value.


Helper for pickle.


Helper for pickle.


Return repr(self).


Implement setattr(self, name, value).


Size of object in memory, in bytes.


Return str(self).


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).


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