Skip to content

Commit

Permalink
Merge af26b59 into 5d9c7ef
Browse files Browse the repository at this point in the history
  • Loading branch information
Zi Li committed Apr 5, 2017
2 parents 5d9c7ef + af26b59 commit 4583cf0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bravado_core/marshal.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)

0 comments on commit 4583cf0

Please sign in to comment.