def _generate_request_arguments(url, spec, endpoint, headers, args, kwargs):
# Prepare (g)requests arguments
data = None
params = None
custom_url = url
if hasattr(stack.top, 'call_id'):
headers['KlueCallID'] = stack.top.call_id
if hasattr(stack.top, 'call_path'):
headers['KlueCallPath'] = stack.top.call_path
if endpoint.param_in_path:
# Fill url with values from kwargs, and remove those params from kwargs
custom_url = _format_flask_url(url, kwargs)
if endpoint.param_in_query:
# The query parameters are contained in **kwargs
params = kwargs
# TODO: validate params? or let the server do that...
elif endpoint.param_in_body:
# The body parameter is the first elem in *args
if len(args) != 1:
raise ValidationError("%s expects exactly 1 parameter" % endpoint.handler_client)
data = json.dumps(spec.model_to_json(args[0]))
# Prune undefined parameters that would otherwise be turned into '=None'
# query params
if params:
for k in list(params.keys()):
if params[k] is None:
del params[k]
return custom_url, params, data, headers
评论列表
文章目录