-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy path_specifications.py
More file actions
35 lines (26 loc) · 993 Bytes
/
_specifications.py
File metadata and controls
35 lines (26 loc) · 993 Bytes
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
35
import json
from collections.abc import Iterator
from importlib.resources import files
from typing import Any
from jsonschema_specifications import REGISTRY as JSONSCHEMA_REGISTRY
from referencing import Resource
__all__ = ["REGISTRY"]
def _iter_schema_files() -> Iterator[Any]:
schema_root = files(__package__).joinpath("schemas")
stack = [schema_root]
while stack:
current = stack.pop()
for child in current.iterdir():
if child.name.startswith("."):
continue
if child.is_dir():
stack.append(child)
continue
yield child
def _load_schemas() -> Iterator[Resource]:
for path in _iter_schema_files():
contents = json.loads(path.read_text(encoding="utf-8"))
yield Resource.from_contents(contents)
#: A `referencing.Registry` containing all official jsonschema resources
#: plus openapi resources.
REGISTRY = (_load_schemas() @ JSONSCHEMA_REGISTRY).crawl()