Skip to content

Commit

Permalink
Merge pull request #76 from spotify/issue-47
Browse files Browse the repository at this point in the history
Fix for issue 47
  • Loading branch information
econchick committed Dec 25, 2015
2 parents 87a6300 + f492a57 commit 15cae4c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ramlfications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import absolute_import, division, print_function

__author__ = "Lynn Root"
__version__ = "0.1.9.dev1"
__version__ = "0.1.9.dev2"
__license__ = "Apache 2.0"

__email__ = "lynn@spotify.com"
Expand Down
10 changes: 6 additions & 4 deletions ramlfications/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,19 @@ def wrap(key, data, meth, _v):
for meth in list(iterkeys(res_data)):
if meth in accepted_methods:
method_data = _get(res_data, meth, {})
comb_data = dict(list(iteritems(method_data)) +
list(iteritems(res_data)))
resource = ResourceTypeNode(
name=name,
raw=res_data,
root=root,
headers=headers(method_data),
body=body(method_data),
responses=responses(method_data),
uri_params=uri_params(res_data),
base_uri_params=base_uri_params(res_data),
query_params=query_params(res_data),
form_params=form_params(res_data),
uri_params=uri_params(comb_data),
base_uri_params=base_uri_params(comb_data),
query_params=query_params(method_data),
form_params=form_params(method_data),
media_type=_get(v, "mediaType"),
desc=description(),
type=_get(res_data, "type"),
Expand Down
28 changes: 28 additions & 0 deletions tests/data/examples/resource-type-inherited.raml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ resourceTypes:
headers:
X-BaseType-Header:
description: Inherited header from basetype
queryParameters:
inheritedParam:
description: query parameter that should be inherited
formParameters:
inheritedFormParam:
description: form parameter that should be inherited
uriParameters:
inheritedUriParam:
description: uri parameter that should be inherited
baseUriParameters:
inheritedBaseUriParam:
description: base uri parameter that should be inherited
responses:
200:
description: Inherited OK response
Expand All @@ -28,6 +40,22 @@ resourceTypes:
headers:
X-InheritBaseType-Header:
description: A header for inheritbase resource type
queryParameters:
aNewParam:
description: another parameter added from base type
example: a new param
formParameters:
aNewFormParam:
description: another form parameter added from base type
example: a new param
uriParameters:
aNewUriParam:
description: another uri parameter added from base type
example: a new param
baseUriParameters:
aNewBaseUriParam:
description: another base uri parameter added from base type
example: a new param
body:
application/json:
schema: !include includes/inherited.schema.json
Expand Down
16 changes: 16 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,22 @@ def test_resource_inherits_type(inherited_resources):
assert q.required is True


def test_res_type_inheritance(inherited_resources):
res = inherited_resources.resource_types[0]
assert res.name == "basetype"
assert len(res.query_params) == 1
assert len(res.form_params) == 1
assert len(res.uri_params) == 1
assert len(res.base_uri_params) == 1

res = inherited_resources.resource_types[-1]
assert res.name == "inheritbase"
assert len(res.query_params) == 2
assert len(res.form_params) == 2
assert len(res.uri_params) == 2
assert len(res.base_uri_params) == 2


def test_resource_inherits_type_optional_post(inherited_resources):
assert len(inherited_resources.resources) == 7
res = inherited_resources.resources[1]
Expand Down

0 comments on commit 15cae4c

Please sign in to comment.