connexion.apps

This module defines Connexion applications. A Connexion App wraps a specific framework application and exposes a standardized interface for users to create and configure their Connexion application.

Submodules

Package Contents

Classes

AbstractApp

param import_name:

the name of the application package

class connexion.apps.AbstractApp(import_name, api_cls, port=None, specification_dir='', host=None, server=None, server_args=None, arguments=None, auth_all_paths=False, debug=None, resolver=None, options=None, skip_error_handlers=False, middlewares=None)
Parameters:
  • import_name (str) – the name of the application package

  • host (str) – the host interface to bind on.

  • port (int) – port to listen to

  • specification_dir (pathlib.Path | str) – directory where to look for specifications

  • server (str | None) – which wsgi server to use

  • server_args (dict | None) – dictionary of arguments which are then passed to appropriate http server (Flask or aio_http)

  • arguments (dict | None) – arguments to replace on the specification

  • auth_all_paths (bool) – whether to authenticate not defined paths

  • debug (bool) – include debugging information

  • resolver – Callable that maps operationID to a function

  • middlewares (list | None) – Callable that maps operationID to a function

abstract create_app(self)

Creates the user framework application

abstract get_root_path(self)

Gets the root path of the user framework application

abstract set_errors_handlers(self)

Sets all errors handlers of the user framework application

add_api(self, specification, base_path=None, arguments=None, auth_all_paths=None, validate_responses=False, strict_validation=False, resolver=None, resolver_error=None, pythonic_params=False, options=None, validator_map=None)

Adds an API to the application based on a swagger file or API dict

Parameters:
  • specification (pathlib.Path or str or dict) – swagger file with the specification | specification dict

  • base_path (str | None) – base path where to add this api

  • arguments (dict | None) – api version specific arguments to replace on the specification

  • auth_all_paths (bool) – whether to authenticate not defined paths

  • validate_responses (bool) – True enables validation. Validation errors generate HTTP 500 responses.

  • strict_validation (bool) – True enables validation on invalid request parameters

  • resolver (Resolver | types.FunctionType) – Operation resolver.

  • resolver_error (int | None) – If specified, turns ResolverError into error responses with the given status code.

  • pythonic_params (bool) – When True CamelCase parameters are converted to snake_case

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

  • validator_map (dict) – map of validators

Return type:

AbstractAPI

add_url_rule(self, rule, endpoint=None, view_func=None, **options)

Connects a URL rule. Works exactly like the route decorator. If a view_func is provided it will be registered with the endpoint.

Basically this example:

@app.route('/')
def index():
    pass

Is equivalent to the following:

def index():
    pass
app.add_url_rule('/', 'index', index)

If the view_func is not provided you will need to connect the endpoint to a view function like so:

app.view_functions['index'] = index

Internally`route` invokes add_url_rule so if you want to customize the behavior via subclassing you only need to change this method.

Parameters:
  • rule (str) – the URL rule as string

  • endpoint (str) – the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint

  • view_func (types.FunctionType) – the function to call when serving a request to the provided endpoint

  • options – the options to be forwarded to the underlying werkzeug.routing.Rule object. A change to Werkzeug is handling of method options. methods is a list of methods this rule should be limited to (GET, POST etc.). By default a rule just listens for GET (and implicitly HEAD).

route(self, rule, **options)

A decorator that is used to register a view function for a given URL rule. This does the same thing as add_url_rule but is intended for decorator usage:

@app.route('/')
def index():
    return 'Hello World'
Parameters:
  • rule (str) – the URL rule as string

  • endpoint – the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint

  • options – the options to be forwarded to the underlying werkzeug.routing.Rule object. A change to Werkzeug is handling of method options. methods is a list of methods this rule should be limited to (GET, POST etc.). By default a rule just listens for GET (and implicitly HEAD).

abstract run(self, port=None, server=None, debug=None, host=None, **options)

Runs the application on a local development server. :param host: the host interface to bind on. :type host: str :param port: port to listen to :type port: int :param server: which wsgi server to use :type server: str | None :param debug: include debugging information :type debug: bool :param options: options to be forwarded to the underlying server