Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix marshall and validation of allOf #167

Merged
merged 1 commit into from Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions bravado_core/marshal.py
Expand Up @@ -5,6 +5,7 @@
from bravado_core import schema
from bravado_core.exception import SwaggerMappingError
from bravado_core.model import is_model
from bravado_core.model import is_object
from bravado_core.model import MODEL_MARKER
from bravado_core.schema import get_spec_for_prop
from bravado_core.schema import handle_null_value
Expand All @@ -30,7 +31,7 @@ def marshal_schema_object(swagger_spec, schema_object_spec, value):
"""
deref = swagger_spec.deref
schema_object_spec = deref(schema_object_spec)
obj_type = schema_object_spec['type']
obj_type = schema_object_spec.get('type')

if obj_type in SWAGGER_PRIMITIVES:
return marshal_primitive(swagger_spec, schema_object_spec, value)
Expand All @@ -49,7 +50,7 @@ def marshal_schema_object(swagger_spec, schema_object_spec, value):
# key for identification.
return marshal_model(swagger_spec, schema_object_spec, value)

if obj_type == 'object':
if is_object(swagger_spec, schema_object_spec):
return marshal_object(swagger_spec, schema_object_spec, value)

if obj_type == 'file':
Expand Down
3 changes: 2 additions & 1 deletion bravado_core/validate.py
Expand Up @@ -8,6 +8,7 @@

from bravado_core.exception import SwaggerMappingError
from bravado_core.exception import SwaggerSecurityValidationError
from bravado_core.model import is_object
from bravado_core.schema import SWAGGER_PRIMITIVES
from bravado_core.swagger20_validator import get_validator_type

Expand All @@ -28,7 +29,7 @@ def validate_schema_object(swagger_spec, schema_object_spec, value):
elif obj_type == 'array':
validate_array(swagger_spec, schema_object_spec, value)

elif obj_type == 'object':
elif is_object(swagger_spec, schema_object_spec):
validate_object(swagger_spec, schema_object_spec, value)

elif obj_type == 'file':
Expand Down
12 changes: 12 additions & 0 deletions tests/marshal/marshal_schema_object_test.py
Expand Up @@ -66,3 +66,15 @@ def test_ref(minimal_swagger_dict):
minimal_swagger_dict['refs'] = {'Foo': foo_spec}
swagger_spec = Spec(minimal_swagger_dict)
assert 'foo' == marshal_schema_object(swagger_spec, ref_spec, 'foo')


def test_allOf_with_ref(composition_spec):
pongclone_spec = composition_spec.spec_dict['definitions']['pongClone']
value = {
'additionalFeature': 'Badges',
'gameSystem': 'NES',
'pang': 'value',
'releaseDate': 'October',
}
expected = copy.deepcopy(value)
assert expected == marshal_schema_object(composition_spec, pongclone_spec, value)
11 changes: 11 additions & 0 deletions tests/validate/validate_schema_object_test.py
Expand Up @@ -9,3 +9,14 @@ def test_unknown_type(minimal_swagger_spec):
with pytest.raises(SwaggerMappingError) as excinfo:
validate_schema_object(minimal_swagger_spec, {'type': 'unknown'}, 'foo')
assert 'Unknown type' in str(excinfo.value)


def test_allOf_with_ref(composition_spec):
pongclone_spec = composition_spec.spec_dict['definitions']['pongClone']
value = {
'additionalFeature': 'Badges',
'gameSystem': 'NES',
'pang': 'value',
'releaseDate': 'October',
}
validate_schema_object(composition_spec, pongclone_spec, value)