connexion.apis.abstract

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

Module Contents

Classes

AbstractAPIMeta

Metaclass for defining Abstract Base Classes (ABCs).

AbstractSpecAPI

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

AbstractRoutingAPI

Minimal interface of an API, with only functionality related to routing.

AbstractAPI

Defines an abstract interface for a Swagger API

Attributes

MODULE_PATH

SWAGGER_UI_URL

logger

connexion.apis.abstract.MODULE_PATH
connexion.apis.abstract.SWAGGER_UI_URL = ui
connexion.apis.abstract.logger
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.AbstractSpecAPI(specification: Union[pathlib.Path, str, dict], base_path: Optional[str] = None, resolver: Optional[connexion.resolver.Resolver] = None, arguments: Optional[dict] = None, options: Optional[dict] = None, *args, **kwargs)

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.

class connexion.apis.abstract.AbstractRoutingAPI(*args, resolver_error_handler: Optional[Callable] = None, debug: bool = False, **kwargs)

Bases: AbstractSpecAPI

Minimal interface of an API, with only functionality related to routing.

Parameters:

debug – Flag to run in debug mode

add_paths(self, paths: Optional[dict] = None) None

Adds the paths defined in the specification as endpoints

abstract add_operation(self, path: str, method: str) None
class connexion.apis.abstract.AbstractAPI(specification, base_path=None, arguments=None, validate_responses=False, strict_validation=False, resolver=None, debug=False, resolver_error_handler=None, validator_map=None, pythonic_params=False, options=None, **kwargs)

Bases: AbstractRoutingAPI

Defines an abstract interface for a Swagger API

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

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

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:

OperationID

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.

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. :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)
add_paths(self, paths: Optional[dict] = None) None

Adds the paths defined in the specification as endpoints