Skip to content

Commit 59535a4

Browse files
committed
Free-form objects unmarshal
1 parent a80648e commit 59535a4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,20 @@ 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':
424+
{
425+
'bar': 1,
426+
},
427+
},
428+
])
429+
@pytest.mark.parametrize('additional_properties', [True, Schema()])
430+
def test_schema_free_form_object(
431+
self, value, additional_properties, unmarshaller_factory):
432+
schema = Schema('object', additional_properties=additional_properties)
433+
434+
result = unmarshaller_factory(schema)(value)
435+
assert result == value

0 commit comments

Comments
 (0)