Skip to content

Commit

Permalink
fix: support empty schemas (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
simosho authored Mar 25, 2024
1 parent 8db0755 commit 21a5037
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jsf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def __parse_definition(
return self.__parse_allOf(name, path, schema, root)
elif "oneOf" in schema:
return self.__parse_oneOf(name, path, schema, root)
elif not any(key in schema for key in ["not", "if", "then", "else"]):
return self.__parse_primitive(name, path, {**schema, "type": list(Primitives.keys())})
else:
raise ValueError(f"Cannot parse schema {repr(schema)}") # pragma: no cover

Expand Down
3 changes: 3 additions & 0 deletions jsf/tests/data/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Any valid JSON"
}
6 changes: 6 additions & 0 deletions jsf/tests/test_default_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,9 @@ def test_fake_complex_recursive(TestData):
assert isinstance(d, str) or isinstance(d, dict)
if isinstance(d, dict):
assert "value" in d


def test_fake_empty(TestData):
with open(TestData / "empty.json") as file:
schema = json.load(file)
[JSF(schema).generate() for _ in range(10)] # Just validating no errors

0 comments on commit 21a5037

Please sign in to comment.