Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/oas/schema/unmarshalers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def _unmarshal(self, instance, schema):
if 'allOf' in schema:
sub_schemas = iter(schema['allOf'])
result = self._unmarshal(instance, next(sub_schemas))
# If the first sub-schema of ``allOf`` specifies an object, also
# unmarshal the remaining sub-schemas and merge the results.
if schema['allOf'][0].get('type', 'object') == 'object':
# If ``result`` is a dict, then the sub-schema specify objects, so
# also unmarshal the remaining sub-schemas and merge the results.
if isinstance(result, dict):
for sub_schema in sub_schemas:
for k, v in iteritems(
self._unmarshal(instance, sub_schema)
Expand Down
30 changes: 30 additions & 0 deletions tests/schema/test_unmarshalers.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,36 @@ def test_unmarshal_all_of_primitive_string_enum():
assert unmarshaled == instance


@pytest.mark.parametrize('schema_type', ['oneOf', 'anyOf'])
def test_unmarshal_all_of_one_of_or_any_of(schema_type):
schema = {
'allOf': [
{schema_type: [{'type': 'string'}, {'type': 'number'}]},
{'type': 'string'},
]
}
instance = 'a'
unmarshaled = SchemaUnmarshaler().unmarshal(instance, schema)
assert unmarshaled == instance


def test_unmarshal_all_of_all_of():
schema = {
'allOf': [
{
'allOf': [
{'type': 'string'},
{'type': 'string', 'enum': ['a', 'b']},
]
},
{'type': 'string', 'enum': ['a']},
]
}
instance = 'a'
unmarshaled = SchemaUnmarshaler().unmarshal(instance, schema)
assert unmarshaled == instance


@pytest.mark.parametrize('schema_type', ['oneOf', 'anyOf'])
def test_unmarshal_one_of_or_any_of(schema_type):
schema = {
Expand Down