File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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+ )
You can’t perform that action at this time.
0 commit comments