Utils reference¶
Note
This section of the documentation is a reference of the
cloudkitty.api.v2.utils
module. It is generated from the docstrings
of the functions. Please report any documentation bug you encounter on this
page
-
class
cloudkitty.api.v2.utils.
SingleQueryParam
(param_type)[source]¶ Voluptuous validator allowing to validate unique query parameters.
This validator checks that a URL query parameter is provided only once, verifies its type and returns it directly, instead of returning a list containing a single element.
Note that this validator uses
voluptuous.Coerce
internally and thus should not be used together withcloudkitty.utils.validation.get_string_type
in python2.- Parameters
param_type – Type of the query parameter
-
cloudkitty.api.v2.utils.
add_input_schema
(location, schema)[source]¶ Add a voluptuous schema validation on a method’s input
Takes a dict which can be converted to a voluptuous schema as parameter, and validates the parameters with this schema. The “location” parameter is used to specify the parameters’ location. Note that for query parameters, a
MultiDict
is returned by Flask. Thus, each dict key will contain a list. In order to ease interaction with unique query parameters, theSingleQueryParam
voluptuous validator can be used:from cloudkitty.api.v2 import utils as api_utils @api_utils.add_input_schema('query', { voluptuous.Required('fruit'): api_utils.SingleQueryParam(str), }) def put(self, fruit=None): return fruit
To accept a list of query parameters, a
MultiQueryParam
can be used:from cloudkitty.api.v2 import utils as api_utils @api_utils.add_input_schema('query', { voluptuous.Required('fruit'): api_utils.MultiQueryParam(str), }) def put(self, fruit=[]): for f in fruit: # Do something with the fruit
- Parameters
location (str) – Location of the args. Must be one of [‘body’, ‘query’]
schema (dict) – Schema to apply to the method’s kwargs
-
cloudkitty.api.v2.utils.
add_output_schema
(schema)[source]¶ Add a voluptuous schema validation on a method’s output
Example usage:
class Example(base.BaseResource): @api_utils.add_output_schema({ voluptuous.Required( 'message', default='This is an example endpoint', ): validation_utils.get_string_type(), }) def get(self): return {}
- Parameters
schema (dict) – Schema to apply to the method’s output
-
cloudkitty.api.v2.utils.
do_init
(app, blueprint_name, resources)[source]¶ Registers a new Blueprint containing one or several resources to app.
- Parameters
app (flask.Flask) – Flask app in which the Blueprint should be registered
blueprint_name (str) – Name of the blueprint to create
resources (list of dicts matching
cloudkitty.api.v2.RESOURCE_SCHEMA
) – Resources to add to the Blueprint’s Api
-
cloudkitty.api.v2.utils.
paginated
(func)[source]¶ Helper function for pagination.
Adds two parameters to the decorated function: *
offset
: int >=0. Defaults to 0. *limit
: int >=1. Defaults to 100.Example usage:
class Example(base.BaseResource): @api_utils.paginated @api_utils.add_output_schema({ voluptuous.Required( 'message', default='This is an example endpoint', ): validation_utils.get_string_type(), }) def get(self, offset=0, limit=100): # [...]