File: to_schemastore.py

package info (click to toggle)
python-validate-pyproject 0.24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: python: 3,053; makefile: 46; sh: 25
file content (34 lines) | stat: -rwxr-xr-x 970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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))