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
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 with api_utils.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 volptuous 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,
the SingleQueryParam 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, the following syntax can be used:
from cloudkitty.api.v2 import utils as api_utils
@api_utils.add_input_schema('query', {
voluptuous.Required('fruit'): [str],
})
def put(self, fruit=[]):
for f in fruit:
# Do something with the fruit
| Parameters: |
|
|---|
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(flask_restful.Resource):
@api_utils.paginated
@api_utils.add_output_schema({
voluptuous.Required(
'message',
default='This is an example endpoint',
): api_utils.get_string_type(),
})
def get(self, offset=0, limit=100):
# [...]
cloudkitty.api.v2.utils.add_output_schema(schema)[source]¶Add a voluptuous schema validation on a method’s output
Example usage:
class Example(flask_restful.Resource):
@api_utils.add_output_schema({
voluptuous.Required(
'message',
default='This is an example endpoint',
): api_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: |
|
|---|
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.