This module defines an AbstractAPI, which defines a standardized interface for a Connexion API.

Module Contents



Metaclass for defining Abstract Base Classes (ABCs).


Defines an abstract interface for a Swagger API





connexion.apis.abstract.SWAGGER_UI_URL = ui
class connexion.apis.abstract.AbstractAPIMeta(cls, name, bases, attrs)

Bases: abc.ABCMeta

Metaclass for defining Abstract Base Classes (ABCs).

Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ‘virtual subclasses’ – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).

register(cls, subclass)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

__instancecheck__(cls, instance)

Override for isinstance(instance, cls).

__subclasscheck__(cls, subclass)

Override for issubclass(subclass, cls).

class connexion.apis.abstract.AbstractAPI(specification, base_path=None, arguments=None, validate_responses=False, strict_validation=False, resolver=None, auth_all_paths=False, debug=False, resolver_error_handler=None, validator_map=None, pythonic_params=False, pass_context_arg_name=None, options=None)

Defines an abstract interface for a Swagger API

  • validator_map (dict) – Custom validators for the types “parameter”, “body” and “response”.

  • resolver – Callable that maps operationID to a function

  • resolver_error_handler (callable | None) – If given, a callable that generates an Operation used for handling ResolveErrors

  • pythonic_params (bool) – When True CamelCase parameters are converted to snake_case and an underscore is appended to any shadowed built-ins

  • options (dict | None) – New style options dictionary.

  • pass_context_arg_name (str | None) – If not None URL request handling functions with an argument matching this name will be passed the framework’s request context.

abstract add_openapi_json(self)

Adds openapi spec to {base_path}/openapi.json (or {base_path}/swagger.json for swagger2)

abstract add_swagger_ui(self)

Adds swagger ui to {base_path}/ui/

abstract add_auth_on_not_found(self, security, security_definitions)

Adds a 404 error handler to authenticate and only expose the 404 status if the security validation pass.

abstract static make_security_handler_factory(pass_context_arg_name)

Create SecurityHandlerFactory to create all security check handlers

add_operation(self, path, method)

Adds one operation to the api.

This method uses the OperationID identify the module and function that will handle the operation

From Swagger Specification:


A friendly name for the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operation id to uniquely identify an operation.

add_paths(self, paths=None)

Adds the paths defined in the specification as endpoints

abstract classmethod get_request(self, *args, **kwargs)

This method converts the user framework request to a ConnexionRequest.

abstract classmethod get_response(self, response, mimetype=None, request=None)

This method converts a handler response to a framework response. This method should just retrieve response from handler then call cls._get_response. It is mainly here to handle AioHttp async handler. :param response: A response to cast (tuple, framework response, etc). :param mimetype: The response mimetype. :type mimetype: Union[None, str] :param request: The request associated with this response (the user framework request).

classmethod get_connexion_response(cls, response, mimetype=None)

Cast framework dependent response to ConnexionResponse used for schema validation

json_loads(self, data)