Skip to content

Commit

Permalink
test unknown items type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan committed Aug 20, 2021
1 parent 5562bcd commit 024e8f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions classyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 024e8f4

Please sign in to comment.