@@ -56,18 +56,22 @@ def get_validator(
5656
5757
5858class SchemaLoader (SchemaLoaderBase ):
59+ validator_class : type [jsonschema .protocols .Validator ] | None = None
60+
5961 def __init__ (
6062 self ,
6163 schemafile : str ,
6264 cache_filename : str | None = None ,
6365 disable_cache : bool = False ,
6466 base_uri : str | None = None ,
67+ validator_class : type [jsonschema .protocols .Validator ] | None = None ,
6568 ) -> None :
6669 # record input parameters (these are not to be modified)
6770 self .schemafile = schemafile
6871 self .cache_filename = cache_filename
6972 self .disable_cache = disable_cache
7073 self .base_uri = base_uri
74+ self .validator_class = validator_class
7175
7276 # if the schema location is a URL, which may include a file:// URL, parse it
7377 self .url_info = None
@@ -132,9 +136,19 @@ def get_validator(
132136 self ._parsers , retrieval_uri , schema
133137 )
134138
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
138152
139153 # extend the validator class with default-filling behavior if appropriate
140154 if fill_defaults :
0 commit comments