mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-21 04:03:28 +00:00
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
This commit is contained in:
@@ -377,8 +377,9 @@ class Operation(Stringify):
|
||||
if self.is_websocket:
|
||||
self.websocket_protocol = op_json.get('websocketProtocol')
|
||||
if self.http_method != 'GET':
|
||||
raise ValueError(
|
||||
"upgrade: websocket is only valid on GET operations")
|
||||
raise SwaggerError(
|
||||
"upgrade: websocket is only valid on GET operations",
|
||||
context)
|
||||
|
||||
params_json = op_json.get('parameters') or []
|
||||
self.parameters = [
|
||||
@@ -394,6 +395,14 @@ class Operation(Stringify):
|
||||
self.has_header_parameters = self.header_parameters and True
|
||||
self.has_parameters = self.has_query_parameters or \
|
||||
self.has_path_parameters or self.has_header_parameters
|
||||
|
||||
# Body param is different, since there's at most one
|
||||
self.body_parameter = [
|
||||
p for p in self.parameters if p.is_type('body')]
|
||||
if len(self.body_parameter) > 1:
|
||||
raise SwaggerError("Cannot have more than one body param", context)
|
||||
self.body_parameter = self.body_parameter and self.body_parameter[0]
|
||||
|
||||
self.summary = op_json.get('summary')
|
||||
self.notes = op_json.get('notes')
|
||||
err_json = op_json.get('errorResponses') or []
|
||||
|
Reference in New Issue
Block a user