connexion.apis

This module defines Connexion APIs. A connexion API takes in an OpenAPI specification and translates the operations defined in it to a set of Connexion Operations. This set of operations is implemented as a framework blueprint (A Flask blueprint or framework-specific equivalent), which can be registered on the framework application.

For each operation, the API resolves the user view function to link to the operation, wraps it with a Connexion Operation which it configures based on the OpenAPI spec, and finally adds it as a route on the framework blueprint.

When the API is registered on the Connexion APP, the underlying framework blueprint is registered on the framework app.

Submodules

Package Contents

Classes

AbstractAPI

Defines an abstract interface for a Swagger API

AbstractRoutingAPI

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

class connexion.apis.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

class connexion.apis.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