-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
175 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
from __future__ import division | ||
|
||
|
||
def get_aslist(param): | ||
"""Checks if parameter is described as list for simpler scenarios""" | ||
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: | ||
if 'schema' not in param_or_header: | ||
return False | ||
|
||
param_schema = param / 'schema' | ||
schema_type = param_schema.getkey('type', 'any') | ||
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): | ||
"""Checks parameter style for simpler scenarios""" | ||
if 'style' in param: | ||
return param['style'] | ||
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 param['in'] in ['path', 'header'] else 'form' | ||
'simple' if location in ['path', 'header'] else 'form' | ||
) | ||
|
||
|
||
def get_explode(param): | ||
"""Checks parameter explode for simpler scenarios""" | ||
if 'explode' in param: | ||
return param['explode'] | ||
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) | ||
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters