Skip to content

Commit

Permalink
Merge pull request neovim#52 from core-api/spec-validation-change
Browse files Browse the repository at this point in the history
using->location
  • Loading branch information
tomchristie committed Jan 13, 2016
2 parents c1e96b3 + ce403e0 commit f677274
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions coreapi/codecs/corejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def _document_to_primative(node, base_url=None):
ret = OrderedDict({'name': node.name})
if node.required:
ret['required'] = True
if node.type:
ret['type'] = node.type
if node.location:
ret['location'] = node.location
return ret

elif isinstance(node, Object):
Expand Down Expand Up @@ -168,7 +168,7 @@ def _primative_to_document(data, base_url=None):
# Transform the strings or dicts into strings or Field instances.
fields = [
item if isinstance(item, string_types) else
Field(item['name'], required=bool(item.get('required', False)), type=str(item.get('type', '')))
Field(item['name'], required=bool(item.get('required', False)), location=str(item.get('type', '')))
for item in fields
]

Expand Down
6 changes: 3 additions & 3 deletions coreapi/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def _key_sorting(item):

# The field class, as used by Link objects:

Field = namedtuple('Field', ['name', 'required', 'type'])
Field = namedtuple('Field', ['name', 'required', 'location'])
Field.__new__.__defaults__ = (False, '')


def required(name):
return Field(name, required=True, type='')
return Field(name, required=True, location='')


# The Core API primatives:
Expand Down Expand Up @@ -195,7 +195,7 @@ def __init__(self, url=None, action=None, inplace=None, fields=None):
self._action = '' if (action is None) else action
self._inplace = inplace
self._fields = () if (fields is None) else tuple([
item if isinstance(item, Field) else Field(item, required=False, type='')
item if isinstance(item, Field) else Field(item, required=False, location='')
for item in fields
])

Expand Down
10 changes: 5 additions & 5 deletions coreapi/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def get_params(self, method, link, params=None):
query_params = {}
form_params = {}
for key, value in params.items():
if key not in fields or not fields[key].type:
if key not in fields or not fields[key].location:
# Default is 'query' for 'GET'/'DELETE', and 'form' others.
param_type = 'query' if method in ('GET', 'DELETE') else 'form'
location = 'query' if method in ('GET', 'DELETE') else 'form'
else:
param_type = fields[key].type
location = fields[key].location

if param_type == 'path':
if location == 'path':
path_params[key] = value
elif param_type == 'query':
elif location == 'query':
query_params[key] = value
else:
form_params[key] = value
Expand Down
4 changes: 2 additions & 2 deletions tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_link_encodings(json_codec):
'link': Link(
action='post',
inplace=True,
fields=['optional', Field('required', required=True, type='path')]
fields=['optional', Field('required', required=True, location='path')]
)
})
bytes = json_codec.dump(doc, indent=True)
Expand All @@ -169,7 +169,7 @@ def test_link_encodings(json_codec):
{
"name": "required",
"required": true,
"type": "path"
"location": "path"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def mockreturn(method, url, **opts):
link = Link(
url='http://example.org/{user_id}/',
action='get',
fields=[Field(name='user_id', type='path')]
fields=[Field(name='user_id', location='path')]
)
doc = http.transition(link, params={'user_id': 123})
assert doc == {'example': 'http://example.org/123/'}
Expand Down

0 comments on commit f677274

Please sign in to comment.