Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/openapi_schema_validator/_specifications.py: 64%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

25 statements  

1import json 

2from importlib.resources import files 

3from typing import Any 

4from typing import Iterator 

5 

6from jsonschema_specifications import REGISTRY as JSONSCHEMA_REGISTRY 

7from referencing import Resource 

8 

9__all__ = ["REGISTRY"] 

10 

11 

12def _iter_schema_files() -> Iterator[Any]: 

13 schema_root = files(__package__).joinpath("schemas") 

14 stack = [schema_root] 

15 

16 while stack: 

17 current = stack.pop() 

18 for child in current.iterdir(): 

19 if child.name.startswith("."): 

20 continue 

21 if child.is_dir(): 

22 stack.append(child) 

23 continue 

24 yield child 

25 

26 

27def _load_schemas() -> Iterator[Resource]: 

28 for path in _iter_schema_files(): 

29 contents = json.loads(path.read_text(encoding="utf-8")) 

30 yield Resource.from_contents(contents) 

31 

32 

33#: A `referencing.Registry` containing all official jsonschema resources 

34#: plus openapi resources. 

35REGISTRY = (_load_schemas() @ JSONSCHEMA_REGISTRY).crawl()