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

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

Parameters:
  • 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:

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.

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)