From 21a50378323b6e38cd94f189c090d6279bd0affb Mon Sep 17 00:00:00 2001 From: Simon Schoonjans Date: Mon, 25 Mar 2024 22:11:02 +0100 Subject: [PATCH 1/2] fix: support empty schemas (#106) --- jsf/parser.py | 2 ++ jsf/tests/data/empty.json | 3 +++ jsf/tests/test_default_fake.py | 6 ++++++ 3 files changed, 11 insertions(+) create mode 100644 jsf/tests/data/empty.json diff --git a/jsf/parser.py b/jsf/parser.py index fcd4ff8..0c83613 100644 --- a/jsf/parser.py +++ b/jsf/parser.py @@ -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 diff --git a/jsf/tests/data/empty.json b/jsf/tests/data/empty.json new file mode 100644 index 0000000..125da58 --- /dev/null +++ b/jsf/tests/data/empty.json @@ -0,0 +1,3 @@ +{ + "title": "Any valid JSON" +} \ No newline at end of file diff --git a/jsf/tests/test_default_fake.py b/jsf/tests/test_default_fake.py index fcfd6d5..3a9c69c 100644 --- a/jsf/tests/test_default_fake.py +++ b/jsf/tests/test_default_fake.py @@ -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 From b620229ef918734d957710aa807ae450a85d69ed Mon Sep 17 00:00:00 2001 From: Andy Challis Date: Tue, 26 Mar 2024 08:21:34 +1100 Subject: [PATCH 2/2] release v0.11.1 --- jsf/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsf/BUILD b/jsf/BUILD index e8707b0..de4f522 100644 --- a/jsf/BUILD +++ b/jsf/BUILD @@ -18,7 +18,7 @@ python_distribution( long_description_path="README.md", provides=python_artifact( name="jsf", - version="0.11.0", + version="0.11.1", author="ghandic", description="Creates fake JSON files from a JSON schema", url="https://github.com/ghandic/jsf",