-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathutils.py
29 lines (23 loc) · 924 Bytes
/
utils.py
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
"""OpenAIP spec validator schemas utils module."""
import sys
from os import path
from typing import Any
from typing import Hashable
from typing import Mapping
from typing import Tuple
if sys.version_info >= (3, 9):
from importlib.resources import as_file
from importlib.resources import files
else:
from importlib_resources import as_file
from importlib_resources import files
from jsonschema_path.readers import FilePathReader
def get_schema(version: str) -> Tuple[Mapping[Hashable, Any], str]:
schema_path = f"resources/schemas/v{version}/schema.json"
ref = files("openapi_spec_validator") / schema_path
with as_file(ref) as resource_path:
schema_path_full = path.join(path.dirname(__file__), resource_path)
return FilePathReader(schema_path_full).read()
def get_schema_content(version: str) -> Mapping[Hashable, Any]:
content, _ = get_schema(version)
return content