1
1
import json
2
2
import logging
3
3
4
- import jsonschema
5
4
import pkg_resources
6
5
import yaml
6
+ from jsonschema import Draft6Validator
7
+ from jsonschema .exceptions import ValidationError
7
8
8
9
LOG = logging .getLogger (__name__ )
9
10
@@ -22,10 +23,10 @@ def load_resource_spec(resource_spec_file):
22
23
) as f :
23
24
resource_spec_schema = json .load (f )
24
25
26
+ validator = Draft6Validator (resource_spec_schema )
25
27
try :
26
- jsonschema .validate (resource_spec , resource_spec_schema )
27
- # the unit tests should catch `SchemaError`/if the schema is invalid
28
- except jsonschema .exceptions .ValidationError as e :
28
+ validator .validate (resource_spec )
29
+ except ValidationError as e :
29
30
LOG .error (
30
31
"The resource provider definition is invalid: %s" , e .message # noqa: B306
31
32
)
@@ -57,10 +58,10 @@ def load_project_settings(plugin, project_settings_file):
57
58
"to further customize code generation."
58
59
)
59
60
61
+ validator = Draft6Validator (plugin .project_settings_schema ())
60
62
try :
61
- jsonschema .validate (project_settings , plugin .project_settings_schema ())
62
- # the unit tests should catch `SchemaError`/if the schema is invalid
63
- except jsonschema .exceptions .ValidationError as e :
63
+ validator .validate (project_settings )
64
+ except ValidationError as e :
64
65
LOG .error ("The project settings are invalid: %s" , e .message ) # noqa: B306
65
66
raise # TODO: error handling
66
67
0 commit comments