Skip to content

Commit

Permalink
issue httpie#172: spec/buggy Path/Operation handling
Browse files Browse the repository at this point in the history
Current code expect Path object to contain only method/Operation
declaration. Path object may contain $ref, summary, description, servers
and parameters entries.

If available, this entries are default values to apply children
Operation.

This fix drops unused entries ($ref, summary, description, servers) and
merge parameters:
* unicity based on name/in unicity
* Operation value takes precedence

This fix allows to parse spec file attached with httpie#172
  • Loading branch information
lalmeras committed Feb 7, 2021
1 parent 6ce106a commit dca26d6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions http_prompt/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ def __init__(self, url=None, spec=None):
elif path[-1] == '/': # Path ends with a trailing slash
path_tokens[-1] = path_tokens[-1] + '/'
self.root.add_path(*path_tokens)
endpoint = paths[path]
endpoint = dict(paths[path])
# path parameters (apply to all paths if not overriden)
global_parameters = endpoint.pop('parameters', [])
# not used
endpoint.pop('servers', None)
endpoint.pop('$ref', None)
endpoint.pop('summary', None)
endpoint.pop('description', None)
for method, info in endpoint.items():
params = info.get('parameters')
if params:
params = list(global_parameters + params)
# parameter is overriden based on in/name value
# last value (local definition) takes precedence
params_map = dict([((i.get('name'), i.get('in')), i) for i in params])
for param in params:
if param.get("$ref"):
for section in param.get("$ref").split('/'):
param = param.get(section) if not section == "#" else spec

if param.get('in') != 'path':
full_path = path_tokens + [param['name']]
self.root.add_path(*full_path,
Expand Down

0 comments on commit dca26d6

Please sign in to comment.