Skip to content

Commit 096bd7e

Browse files
get_schemas_dict function
1 parent 36d9974 commit 096bd7e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Standard library imports
2+
import os
3+
import json
4+
5+
# Third party imports
6+
from jsonschema import validate
7+
from jsonschema.exceptions import ValidationError
8+
9+
10+
def get_schemas_dict(path):
11+
json_files = os.listdir(path)
12+
schemas_dict = {}
13+
for json_file in json_files:
14+
filename = json_file.split(".")[0]
15+
with open(os.path.join(path, json_file), "r") as file:
16+
file_content = json.load(file)
17+
schemas_dict[filename] = file_content
18+
return schemas_dict
19+
20+
def validate_schema(params, schema):
21+
try:
22+
validate(instance=params, schema=schema)
23+
except ValidationError as e:
24+
print(f"Validation error: {e.message}", flush=True)
25+
raise Exception(
26+
{
27+
"code": 400,
28+
"route": schema["rpc"],
29+
"name": "Bad request",
30+
"description": e.message,
31+
}
32+
)

0 commit comments

Comments
 (0)