connexion.utils

This module provides general utility functions used within Connexion.

Module Contents

Functions

boolean(s)

Convert JSON/Swagger boolean value to Python, raise ValueError otherwise

make_type(value, _type)

deep_merge(a, b)

merges b into a

deep_getattr(obj, attr)

Recurses through an attribute chain to get the ultimate value.

deep_get(obj, keys)

Recurses through a nested object get a leaf value.

get_function_from_name(function_name)

Tries to get function by fully qualified name (e.g. “mymodule.myobj.myfunc”)

is_json_mimetype(mimetype)

type mimetype

str

all_json(mimetypes)

Returns True if all mimetypes are serialized with json

is_nullable(param_def)

is_null(value)

has_coroutine(function, api=None)

Checks if function is a coroutine.

yamldumper(openapi)

Returns a nicely-formatted yaml spec.

not_installed_error(exc)

Raises the ImportError when the module/object is actually called.

Attributes

TYPE_MAP

connexion.utils.boolean(s)

Convert JSON/Swagger boolean value to Python, raise ValueError otherwise

>>> boolean('true')
True
>>> boolean('false')
False
connexion.utils.TYPE_MAP
connexion.utils.make_type(value, _type)
connexion.utils.deep_merge(a, b)

merges b into a in case of conflict the value from b is used

connexion.utils.deep_getattr(obj, attr)

Recurses through an attribute chain to get the ultimate value.

connexion.utils.deep_get(obj, keys)

Recurses through a nested object get a leaf value.

There are cases where the use of inheritance or polymorphism– the use of allOf or oneOf keywords– will cause the obj to be a list. In this case the keys will contain one or more strings containing integers.

connexion.utils.get_function_from_name(function_name)

Tries to get function by fully qualified name (e.g. “mymodule.myobj.myfunc”)

connexion.utils.is_json_mimetype(mimetype)
Return type

bool

connexion.utils.all_json(mimetypes)

Returns True if all mimetypes are serialized with json

Return type

bool

>>> all_json(['application/json'])
True
>>> all_json(['application/x.custom+json'])
True
>>> all_json([])
True
>>> all_json(['application/xml'])
False
>>> all_json(['text/json'])
False
>>> all_json(['application/json', 'other/type'])
False
>>> all_json(['application/json', 'application/x.custom+json'])
True
connexion.utils.is_nullable(param_def)
connexion.utils.is_null(value)
connexion.utils.has_coroutine(function, api=None)

Checks if function is a coroutine. If function is a decorator (has a __wrapped__ attribute) this function will also look at the wrapped function.

connexion.utils.yamldumper(openapi)

Returns a nicely-formatted yaml spec. :param openapi: a spec dictionary. :return: a nicely-formatted, serialized yaml spec.

connexion.utils.not_installed_error(exc)

Raises the ImportError when the module/object is actually called.