@@ -141,6 +141,25 @@ def check_schema(cls, schema):
141
141
for error in cls (cls .META_SCHEMA ).iter_errors (schema ):
142
142
raise exceptions .SchemaError .create_from (error )
143
143
144
+ def schema_validators (self , schema ):
145
+ """
146
+ Returns a list of validators that should apply for the given schema
147
+ """
148
+ legacy_cls = [Draft3Validator , Draft4Validator , Draft6Validator , Draft7Validator ]
149
+
150
+ ref = schema .get (u"$ref" )
151
+ if ref is not None :
152
+ # We make sure $ref is evaluated first if available in schema
153
+ validators = [(u"$ref" , ref )]
154
+
155
+ # Apply all remaining validators for newer drafts
156
+ if not any (isinstance (self , x ) for x in legacy_cls ):
157
+ validators += [(x , schema [x ]) for x in schema if x not in ["$ref" ]]
158
+ else :
159
+ validators = schema .items ()
160
+
161
+ return validators
162
+
144
163
def iter_errors (self , instance , _schema = None ):
145
164
if _schema is None :
146
165
_schema = self .schema
@@ -161,23 +180,7 @@ def iter_errors(self, instance, _schema=None):
161
180
if scope :
162
181
self .resolver .push_scope (scope )
163
182
try :
164
- if isinstance (self , Draft202012Validator ):
165
- validators = []
166
- # We make sure $ref is evaluated first if available in schema
167
- ref = _schema .get (u"$ref" )
168
- if ref is not None :
169
- validators = [(u"$ref" , ref )]
170
-
171
- # Add all remaining validators
172
- validators += [(x , _schema [x ]) for x in _schema if x not in ["$ref" ]]
173
- else :
174
- # Compatibility to Draft7 and older
175
- ref = _schema .get (u"$ref" )
176
- if ref is not None :
177
- validators = [(u"$ref" , ref )]
178
- else :
179
- validators = _schema .items ()
180
-
183
+ validators = self .schema_validators (_schema )
181
184
for k , v in validators :
182
185
validator = self .VALIDATORS .get (k )
183
186
if validator is None :
0 commit comments