26
26
27
27
validators = {}
28
28
meta_schemas = _utils .URIDict ()
29
- vocabulary_schemas = _utils .URIDict ()
29
+ _VOCABULARIES = _utils .URIDict ()
30
30
31
31
32
32
def validates (version ):
@@ -56,7 +56,7 @@ def _validates(cls):
56
56
57
57
for vocabulary in cls .VOCABULARY_SCHEMAS :
58
58
vocabulary_id = cls .ID_OF (vocabulary )
59
- vocabulary_schemas [vocabulary_id ] = vocabulary
59
+ _VOCABULARIES [vocabulary_id ] = vocabulary
60
60
61
61
return cls
62
62
return _validates
@@ -70,11 +70,10 @@ def _id_of(schema):
70
70
71
71
def _store_schema_list ():
72
72
return [
73
- (id , validator .META_SCHEMA )
74
- for id , validator in meta_schemas .items ()
75
- ] + [
76
- (id , schema ) for id , schema in vocabulary_schemas .items ()
77
- ]
73
+ (id , validator .META_SCHEMA ) for id , validator in meta_schemas .items ()
74
+ ] + [
75
+ (id , schema ) for id , schema in _VOCABULARIES .items ()
76
+ ]
78
77
79
78
80
79
def create (
@@ -84,6 +83,7 @@ def create(
84
83
version = None ,
85
84
type_checker = _types .draft7_type_checker ,
86
85
id_of = _id_of ,
86
+ applicable_validators = lambda schema : schema .items (),
87
87
):
88
88
"""
89
89
Create a new validator class.
@@ -126,6 +126,11 @@ def create(
126
126
127
127
A function that given a schema, returns its ID.
128
128
129
+ applicable_validators (collections.abc.Callable):
130
+
131
+ A function that returns a list of validators that should apply
132
+ to a given schema
133
+
129
134
Returns:
130
135
131
136
a new `jsonschema.IValidator` class
@@ -177,16 +182,7 @@ def iter_errors(self, instance, _schema=None):
177
182
if scope :
178
183
self .resolver .push_scope (scope )
179
184
try :
180
- validators = []
181
-
182
- # We make sure $ref is evaluated first if available in schema
183
- ref = _schema .get (u"$ref" )
184
- if ref is not None :
185
- validators = [(u"$ref" , ref )]
186
-
187
- # Add all remaining validators
188
- validators += [(x , _schema [x ]) for x in _schema if x not in ["$ref" ]]
189
-
185
+ validators = applicable_validators (_schema )
190
186
for k , v in validators :
191
187
validator = self .VALIDATORS .get (k )
192
188
if validator is None :
@@ -332,6 +328,7 @@ def extend(validator, validators=(), version=None, type_checker=None):
332
328
type_checker = _types .draft3_type_checker ,
333
329
version = "draft3" ,
334
330
id_of = lambda schema : schema .get (u"id" , "" ),
331
+ applicable_validators = _legacy_validators .ignore_ref_siblings ,
335
332
)
336
333
337
334
Draft4Validator = create (
@@ -367,6 +364,7 @@ def extend(validator, validators=(), version=None, type_checker=None):
367
364
type_checker = _types .draft4_type_checker ,
368
365
version = "draft4" ,
369
366
id_of = lambda schema : schema .get (u"id" , "" ),
367
+ applicable_validators = _legacy_validators .ignore_ref_siblings ,
370
368
)
371
369
372
370
Draft6Validator = create (
@@ -406,6 +404,7 @@ def extend(validator, validators=(), version=None, type_checker=None):
406
404
},
407
405
type_checker = _types .draft6_type_checker ,
408
406
version = "draft6" ,
407
+ applicable_validators = _legacy_validators .ignore_ref_siblings ,
409
408
)
410
409
411
410
Draft7Validator = create (
@@ -446,6 +445,7 @@ def extend(validator, validators=(), version=None, type_checker=None):
446
445
},
447
446
type_checker = _types .draft7_type_checker ,
448
447
version = "draft7" ,
448
+ applicable_validators = _legacy_validators .ignore_ref_siblings ,
449
449
)
450
450
451
451
Draft202012Validator = create (
0 commit comments