@@ -56,18 +56,22 @@ def get_validator(
56
56
57
57
58
58
class SchemaLoader (SchemaLoaderBase ):
59
+ validator_class : type [jsonschema .protocols .Validator ] | None = None
60
+
59
61
def __init__ (
60
62
self ,
61
63
schemafile : str ,
62
64
cache_filename : str | None = None ,
63
65
disable_cache : bool = False ,
64
66
base_uri : str | None = None ,
67
+ validator_class : type [jsonschema .protocols .Validator ] | None = None ,
65
68
) -> None :
66
69
# record input parameters (these are not to be modified)
67
70
self .schemafile = schemafile
68
71
self .cache_filename = cache_filename
69
72
self .disable_cache = disable_cache
70
73
self .base_uri = base_uri
74
+ self .validator_class = validator_class
71
75
72
76
# if the schema location is a URL, which may include a file:// URL, parse it
73
77
self .url_info = None
@@ -132,9 +136,19 @@ def get_validator(
132
136
self ._parsers , retrieval_uri , schema
133
137
)
134
138
135
- # get the correct validator class and check the schema under its metaschema
136
- validator_cls = jsonschema .validators .validator_for (schema )
137
- validator_cls .check_schema (schema )
139
+ if self .validator_class is None :
140
+ # get the correct validator class and check the schema under its metaschema
141
+ validator_cls = jsonschema .validators .validator_for (schema )
142
+ validator_cls .check_schema (schema )
143
+ else :
144
+ # for a user-provided validator class, don't check_schema
145
+ # on the grounds that it might *not* be valid but the user wants to use
146
+ # their custom validator anyway
147
+ #
148
+ # in fact, there's no real guarantee that a user-provided
149
+ # validator_class properly conforms to the jsonschema.Validator protocol
150
+ # we *hope* that it does, but we can't be fully sure
151
+ validator_cls = self .validator_class
138
152
139
153
# extend the validator class with default-filling behavior if appropriate
140
154
if fill_defaults :
0 commit comments