-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathparameters.py
More file actions
54 lines (39 loc) · 1.52 KB
/
parameters.py
File metadata and controls
54 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import division
def get_aslist(param_or_header):
"""Checks if parameter/header is described as list for simpler scenarios"""
# if schema is not defined it's a complex scenario
if 'schema' not in param_or_header:
return False
schema = param_or_header / 'schema'
schema_type = schema.getkey('type', 'any')
# TODO: resolve for 'any' schema type
return schema_type in ['array', 'object']
def get_style(param_or_header):
"""Checks parameter/header style for simpler scenarios"""
if 'style' in param_or_header:
return param_or_header['style']
# if "in" not defined then it's a Header
location = param_or_header.getkey('in', 'header')
# determine default
return (
'simple' if location in ['path', 'header'] else 'form'
)
def get_explode(param_or_header):
"""Checks parameter/header explode for simpler scenarios"""
if 'explode' in param_or_header:
return param_or_header['explode']
# determine default
style = get_style(param_or_header)
return style == 'form'
def get_value(param_or_header, location, name=None):
"""Returns parameter/header value from specific location"""
name = name or param_or_header['name']
if name not in location:
raise KeyError
aslist = get_aslist(param_or_header)
explode = get_explode(param_or_header)
if aslist and explode:
if hasattr(location, 'getall'):
return location.getall(name)
return location.getlist(name)
return location[name]