4
4
import textwrap
5
5
6
6
import click
7
+ import jsonschema
7
8
8
9
from ..catalog import CUSTOM_SCHEMA_NAMES , SCHEMA_CATALOG
9
10
from ..checker import SchemaChecker
18
19
SchemaLoaderBase ,
19
20
)
20
21
from ..transforms import TRANSFORM_LIBRARY
21
- from .param_types import CommaDelimitedList
22
+ from .param_types import CommaDelimitedList , ValidatorClassName
22
23
from .parse_result import ParseResult , SchemaLoadingMode
23
24
24
25
BUILTIN_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:
169
170
)
170
171
@click .option (
171
172
"--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
+ ),
173
178
is_flag = True ,
174
179
)
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
+ )
175
190
@click .option (
176
191
"-o" ,
177
192
"--output-format" ,
178
- help = "Which output format to use" ,
193
+ help = "Which output format to use. " ,
179
194
type = click .Choice (tuple (REPORTER_BY_NAME .keys ()), case_sensitive = False ),
180
195
default = "text" ,
181
196
)
@@ -217,6 +232,7 @@ def main(
217
232
traceback_mode : str ,
218
233
data_transform : str | None ,
219
234
fill_defaults : bool ,
235
+ validator_class : type [jsonschema .protocols .Validator ] | None ,
220
236
output_format : str ,
221
237
verbose : int ,
222
238
quiet : int ,
@@ -225,6 +241,8 @@ def main(
225
241
args = ParseResult ()
226
242
227
243
args .set_schema (schemafile , builtin_schema , check_metaschema )
244
+ args .set_validator (validator_class )
245
+
228
246
args .base_uri = base_uri
229
247
args .instancefiles = instancefiles
230
248
@@ -272,6 +290,7 @@ def build_schema_loader(args: ParseResult) -> SchemaLoaderBase:
272
290
args .cache_filename ,
273
291
args .disable_cache ,
274
292
base_uri = args .base_uri ,
293
+ validator_class = args .validator_class ,
275
294
)
276
295
else :
277
296
raise NotImplementedError ("no valid schema option provided" )
0 commit comments