diff --git a/classyjson.py b/classyjson.py index 03305aa..43f3ec5 100644 --- a/classyjson.py +++ b/classyjson.py @@ -571,6 +571,8 @@ def get_jsonschema(self) -> TJson: schema["items"] = items.get_jsonschema() elif isinstance(items, type) and issubclass(items, ClassyJson): schema["items"] = items.schema.get_jsonschema() + elif isinstance(items, dict): + schema["items"] = items.copy() elif isinstance(items, list): items_schema = [] for item in items: @@ -581,8 +583,8 @@ def get_jsonschema(self) -> TJson: else: items_schema.append(dict(item)) schema["items"] = items_schema - elif items is not None: - schema["items"] = items + else: + raise TypeError(f"Unknown type {type(items)}") return schema def load(self, instance: TJson, validate: bool = True) -> Any: diff --git a/tests/test_schema.py b/tests/test_schema.py index 18e4a3e..39fccb0 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -152,6 +152,15 @@ def test_array_items_list(self): } self.assertEqual(actual, expected) + def test_array_items_get_schema_unknown(self): + schema = ArraySchema( + items=2, + ) + self.assertRaises( + TypeError, + schema.get_jsonschema, + ) + class TestSchemaLoad(unittest.TestCase): def _get_example_1(self):