diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 1a000266..c275a39a 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -6,6 +6,7 @@ from openapi_core.extensions.models.factories import ModelFactory from openapi_core.schema.schemas.enums import SchemaFormat, SchemaType +from openapi_core.schema.schemas.models import Schema from openapi_core.schema.schemas.types import NoValue from openapi_core.schema_validator._types import ( is_array, is_bool, is_integer, @@ -194,11 +195,15 @@ def _unmarshal_properties(self, value=NoValue, one_of_schema=None): extra_props = set(value_props_names) - set(all_props_names) properties = {} - if self.schema.additional_properties is not True: + if isinstance(self.schema.additional_properties, Schema): for prop_name in extra_props: prop_value = value[prop_name] properties[prop_name] = self.unmarshallers_factory.create( self.schema.additional_properties)(prop_value) + elif self.schema.additional_properties is True: + for prop_name in extra_props: + prop_value = value[prop_name] + properties[prop_name] = prop_value for prop_name, prop in iteritems(all_props): try: diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index 7c88c957..ae6c88c2 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -416,3 +416,16 @@ def test_schema_any_one_of(self, unmarshaller_factory): def test_schema_any(self, unmarshaller_factory): schema = Schema() assert unmarshaller_factory(schema)('string') == 'string' + + @pytest.mark.parametrize('value', [ + {'additional': 1}, + {'foo': 'bar', 'bar': 'foo'}, + {'additional': {'bar': 1}}, + ]) + @pytest.mark.parametrize('additional_properties', [True, Schema()]) + def test_schema_free_form_object( + self, value, additional_properties, unmarshaller_factory): + schema = Schema('object', additional_properties=additional_properties) + + result = unmarshaller_factory(schema)(value) + assert result == value