summaryrefslogtreecommitdiff
path: root/rest-api-templates/asterisk_processor.py
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-11-27 15:48:39 +0000
committerDavid M. Lee <dlee@digium.com>2013-11-27 15:48:39 +0000
commitfccb427c88e6b6e0ae8627ffcdc06f4ae5077d34 (patch)
treef3aa4bd4148bd818be174ee8648c3d50300ceec7 /rest-api-templates/asterisk_processor.py
parentfd33969240111a9ad2fdd305461265b315ce13dd (diff)
ari:Add application/json parameter support
The patch allows ARI to parse request parameters from an incoming JSON request body, instead of requiring the request to come in as query parameters (which is just weird for POST and DELETE) or form parameters (which is okay, but a bit asymmetric given that all of our responses are JSON). For any operation that does _not_ have a parameter defined of type body (i.e. "paramType": "body" in the API declaration), if a request provides a request body with a Content type of "application/json", the provided JSON document is parsed and searched for parameters. The expected fields in the provided JSON document should match the query parameters defined for the operation. If the parameter has 'allowMultiple' set, then the field in the JSON document may optionally be an array of values. (closes issue ASTERISK-22685) Review: https://reviewboard.asterisk.org/r/2994/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403177 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'rest-api-templates/asterisk_processor.py')
-rw-r--r--rest-api-templates/asterisk_processor.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/rest-api-templates/asterisk_processor.py b/rest-api-templates/asterisk_processor.py
index 18044f57e..7eb5bff6f 100644
--- a/rest-api-templates/asterisk_processor.py
+++ b/rest-api-templates/asterisk_processor.py
@@ -146,6 +146,15 @@ class AsteriskProcessor(SwaggerPostProcessor):
'boolean': 'ast_true',
}
+ #: JSON conversion functions
+ json_convert_mapping = {
+ 'string': 'ast_json_string_get',
+ 'int': 'ast_json_integer_get',
+ 'long': 'ast_json_integer_get',
+ 'double': 'ast_json_real_get',
+ 'boolean': 'ast_json_is_true',
+ }
+
def __init__(self, wiki_prefix):
self.wiki_prefix = wiki_prefix
@@ -190,15 +199,22 @@ class AsteriskProcessor(SwaggerPostProcessor):
raise SwaggerError("Summary should end with .", context)
operation.wiki_summary = wikify(operation.summary or "")
operation.wiki_notes = wikify(operation.notes or "")
+ operation.parse_body = (operation.body_parameter or operation.has_query_parameters) and True
def process_parameter(self, parameter, context):
- if not parameter.data_type in self.type_mapping:
- raise SwaggerError(
- "Invalid parameter type %s" % parameter.data_type, context)
+ if parameter.param_type == 'body':
+ parameter.c_data_type = 'struct ast_json *'
+ else:
+ if not parameter.data_type in self.type_mapping:
+ raise SwaggerError(
+ "Invalid parameter type %s" % parameter.data_type, context)
+ # Type conversions
+ parameter.c_data_type = self.type_mapping[parameter.data_type]
+ parameter.c_convert = self.convert_mapping[parameter.data_type]
+ parameter.json_convert = self.json_convert_mapping[parameter.data_type]
+
# Parameter names are camelcase, Asterisk convention is snake case
parameter.c_name = snakify(parameter.name)
- parameter.c_data_type = self.type_mapping[parameter.data_type]
- parameter.c_convert = self.convert_mapping[parameter.data_type]
# You shouldn't put a space between 'char *' and the variable
if parameter.c_data_type.endswith('*'):
parameter.c_space = ''