Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support empty schemas #106

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading