1"""
2Load all the JSON Schema specification's official schemas.
3"""
4
5import json
6
7try:
8 from importlib.resources import files
9except ImportError:
10 from importlib_resources import ( # type: ignore[import-not-found, no-redef]
11 files,
12 )
13
14from referencing import Resource
15
16
17def _schemas():
18 """
19 All schemas we ship.
20 """
21 # importlib.resources.abc.Traversal doesn't have nice ways to do this that
22 # I'm aware of...
23 #
24 # It can't recurse arbitrarily, e.g. no ``.glob()``.
25 #
26 # So this takes some liberties given the real layout of what we ship
27 # (only 2 levels of nesting, no directories within the second level).
28
29 for version in files(__package__).joinpath("schemas").iterdir():
30 if version.name.startswith("."):
31 continue
32 for child in version.iterdir():
33 children = [child] if child.is_file() else child.iterdir()
34 for path in children:
35 if path.name.startswith("."):
36 continue
37 contents = json.loads(path.read_text(encoding="utf-8"))
38 yield Resource.from_contents(contents)