From 94197ff8053a4f3a433cd8d5fbd3481fe7de66ef Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 13 Oct 2023 14:48:19 -0400 Subject: [PATCH] chore: schemastore conversion script Signed-off-by: Henry Schreiner --- tools/to_schemastore.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tools/to_schemastore.py diff --git a/tools/to_schemastore.py b/tools/to_schemastore.py new file mode 100755 index 0000000..f893285 --- /dev/null +++ b/tools/to_schemastore.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import argparse +import json + + +def convert_tree(tree: dict[str, object]) -> None: + for key, value in list(tree.items()): + match key, value: + case "$$description", list(): + tree["description"] = " ".join(value) + del tree["$$description"] + case "$id", str(): + del tree["$id"] + case _, dict(): + convert_tree(value) + case _, list(): + for item in value: + if isinstance(item, dict): + convert_tree(item) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("schema", help="JSONSchema to convert") + args = parser.parse_args() + + with open(args.schema, encoding="utf-8") as f: + schema = json.load(f) + + convert_tree(schema) + schema["$id"] = "https://json.schemastore.org/setuptools.json" + + print(json.dumps(schema, indent=2))