flask_openapi.utils

This module contains some utility functions.

flask_openapi.utils.add_optional(data, key, value)

Add a value to the data dict, but only if the value is not None.

Parameters:
  • data (dict) – The dict to add the value to.
  • key (str) – The key to assign the value to in the data dict.
  • value – The value to assign if it’s not None.
flask_openapi.utils.parse_contact_string(string)

Convert a contact string to a matching dict.

The contact string must be in the format:

name <email> (url)

email and url are optional.

Example:

>>> r = parse_contact_string('Me <me@example.com> (http://example.com/me)')
>>> assert r == {
...     'name': 'Me',
...     'email': 'me@example.com',
...     'url': 'http://example.com/me'
... }
Parameters:string (str) – The string to extract the contact information from.
Returns:A dict which holds the extracted contact information.
Return type:dict
flask_openapi.utils.parse_werkzeug_url(url)

Process a werkzeug URL rule.

Parameters:url (str) – The werkzeug URL rule to process.
Returns:
A tuple containing the OpenAPI formatted URL and a list
of path segment descriptions.
Return type:tuple
flask_openapi.utils.ref(*args)

Turn a number of arguments to a JSON reference.

>>> ref('definitions', 'MySchema')
{'$ref': '#/definitions/MySchema'}
Parameters:args (str) – The reference path.
Returns:A JSON reference to the input path.
Return type:dict