44import textwrap
55
66import click
7+ import jsonschema
78
89from ..catalog import CUSTOM_SCHEMA_NAMES , SCHEMA_CATALOG
910from ..checker import SchemaChecker
1819 SchemaLoaderBase ,
1920)
2021from ..transforms import TRANSFORM_LIBRARY
21- from .param_types import CommaDelimitedList
22+ from .param_types import CommaDelimitedList , ValidatorClassName
2223from .parse_result import ParseResult , SchemaLoadingMode
2324
2425BUILTIN_SCHEMA_NAMES = [f"vendor.{ k } " for k in SCHEMA_CATALOG .keys ()] + [
@@ -169,13 +170,27 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
169170)
170171@click .option (
171172 "--fill-defaults" ,
172- help = "Autofill 'default' values prior to validation." ,
173+ help = (
174+ "Autofill 'default' values prior to validation. "
175+ "This may conflict with certain third-party validators used with "
176+ "'--validator-class'"
177+ ),
173178 is_flag = True ,
174179)
180+ @click .option (
181+ "--validator-class" ,
182+ help = (
183+ "The fully qualified name of a python validator to use in place of "
184+ "the 'jsonschema' library validators, in the form of '<package>:<class>'. "
185+ "The validator must be importable in the same environment where "
186+ "'check-jsonschema' is run."
187+ ),
188+ type = ValidatorClassName (),
189+ )
175190@click .option (
176191 "-o" ,
177192 "--output-format" ,
178- help = "Which output format to use" ,
193+ help = "Which output format to use. " ,
179194 type = click .Choice (tuple (REPORTER_BY_NAME .keys ()), case_sensitive = False ),
180195 default = "text" ,
181196)
@@ -217,6 +232,7 @@ def main(
217232 traceback_mode : str ,
218233 data_transform : str | None ,
219234 fill_defaults : bool ,
235+ validator_class : type [jsonschema .protocols .Validator ] | None ,
220236 output_format : str ,
221237 verbose : int ,
222238 quiet : int ,
@@ -225,6 +241,8 @@ def main(
225241 args = ParseResult ()
226242
227243 args .set_schema (schemafile , builtin_schema , check_metaschema )
244+ args .set_validator (validator_class )
245+
228246 args .base_uri = base_uri
229247 args .instancefiles = instancefiles
230248
@@ -272,6 +290,7 @@ def build_schema_loader(args: ParseResult) -> SchemaLoaderBase:
272290 args .cache_filename ,
273291 args .disable_cache ,
274292 base_uri = args .base_uri ,
293+ validator_class = args .validator_class ,
275294 )
276295 else :
277296 raise NotImplementedError ("no valid schema option provided" )
0 commit comments