Skip to content

Commit 75643da

Browse files
committed
Free-form objects unmarshal
1 parent a80648e commit 75643da

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from openapi_core.extensions.models.factories import ModelFactory
88
from openapi_core.schema.schemas.enums import SchemaFormat, SchemaType
9+
from openapi_core.schema.schemas.models import Schema
910
from openapi_core.schema.schemas.types import NoValue
1011
from openapi_core.schema_validator._types import (
1112
is_array, is_bool, is_integer,
@@ -194,11 +195,15 @@ def _unmarshal_properties(self, value=NoValue, one_of_schema=None):
194195
extra_props = set(value_props_names) - set(all_props_names)
195196

196197
properties = {}
197-
if self.schema.additional_properties is not True:
198+
if isinstance(self.schema.additional_properties, Schema):
198199
for prop_name in extra_props:
199200
prop_value = value[prop_name]
200201
properties[prop_name] = self.unmarshallers_factory.create(
201202
self.schema.additional_properties)(prop_value)
203+
elif self.schema.additional_properties is True:
204+
for prop_name in extra_props:
205+
prop_value = value[prop_name]
206+
properties[prop_name] = prop_value
202207

203208
for prop_name, prop in iteritems(all_props):
204209
try:

tests/unit/unmarshalling/test_unmarshal.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,16 @@ def test_schema_any_one_of(self, unmarshaller_factory):
416416
def test_schema_any(self, unmarshaller_factory):
417417
schema = Schema()
418418
assert unmarshaller_factory(schema)('string') == 'string'
419+
420+
@pytest.mark.parametrize('value', [
421+
{'additional': 1},
422+
{'foo': 'bar', 'bar': 'foo'},
423+
{'additional': {'bar': 1}},
424+
])
425+
@pytest.mark.parametrize('additional_properties', [True, Schema()])
426+
def test_schema_free_form_object(
427+
self, value, additional_properties, unmarshaller_factory):
428+
schema = Schema('object', additional_properties=additional_properties)
429+
430+
result = unmarshaller_factory(schema)(value)
431+
assert result == value

0 commit comments

Comments
 (0)