Skip to content

Commit ac64879

Browse files
authored
Merge pull request #429 from jyggen/add-failing-list-test
Add failing test for lists as additional properties
2 parents 0567647 + 9c3e430 commit ac64879

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ class ArrayUnmarshaller(ComplexUnmarshaller):
181181

182182
@property
183183
def items_unmarshaller(self) -> "BaseSchemaUnmarshaller":
184-
return self.unmarshallers_factory.create(self.schema / "items")
184+
# sometimes we don't have any schema i.e. free-form objects
185+
items_schema = self.schema.get("items", Spec.from_dict({}))
186+
return self.unmarshallers_factory.create(items_schema)
185187

186188
def __call__(self, value: Any) -> Optional[List[Any]]:
187189
value = super().__call__(value)

tests/unit/unmarshalling/test_unmarshal.py

+11
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,14 @@ def test_write_only_properties_invalid(self, unmarshaller_factory):
816816
unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(
817817
{"id": 10}
818818
)
819+
820+
def test_additional_properties_list(self, unmarshaller_factory):
821+
schema = {"type": "object"}
822+
spec = Spec.from_dict(schema)
823+
824+
result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(
825+
{"user_ids": [1, 2, 3, 4]}
826+
)
827+
828+
assert is_dataclass(result)
829+
assert result.user_ids == [1, 2, 3, 4]

0 commit comments

Comments
 (0)