@@ -255,55 +255,50 @@ def find_evaluated_item_indexes_by_schema(validator, instance, schema):
255
255
Get all indexes of items that get evaluated under the current schema
256
256
257
257
Covers all keywords related to unevaluatedItems: items, prefixItems, if,
258
- then, else, ' contains', ' unevaluatedItems', ' allOf', ' oneOf', ' anyOf'
258
+ then, else, contains, unevaluatedItems, allOf, oneOf, anyOf
259
259
"""
260
- if not validator .is_type (schema , "object " ):
260
+ if validator .is_type (schema , "boolean " ):
261
261
return []
262
262
evaluated_indexes = []
263
263
264
- if ' items' in schema :
264
+ if " items" in schema :
265
265
return list (range (0 , len (instance )))
266
266
267
- if '$ref' in schema :
268
- resolve = getattr (validator .resolver , "resolve" , None )
269
- if resolve :
270
- scope , resolved = validator .resolver .resolve (schema ['$ref' ])
271
- validator .resolver .push_scope (scope )
267
+ if "$ref" in schema :
268
+ scope , resolved = validator .resolver .resolve (schema ["$ref" ])
269
+ validator .resolver .push_scope (scope )
272
270
273
- try :
274
- evaluated_indexes += find_evaluated_item_indexes_by_schema (
275
- validator , instance , resolved )
276
- finally :
277
- validator .resolver .pop_scope ()
278
-
279
- if 'prefixItems' in schema :
280
- if validator .is_valid (
281
- instance , {'prefixItems' : schema ['prefixItems' ]}
282
- ):
283
- evaluated_indexes += list (range (0 , len (schema ['prefixItems' ])))
284
-
285
- if 'if' in schema :
286
- if validator .is_valid (instance , schema ['if' ]):
271
+ try :
272
+ evaluated_indexes += find_evaluated_item_indexes_by_schema (
273
+ validator , instance , resolved )
274
+ finally :
275
+ validator .resolver .pop_scope ()
276
+
277
+ if "prefixItems" in schema :
278
+ evaluated_indexes += list (range (0 , len (schema ["prefixItems" ])))
279
+
280
+ if "if" in schema :
281
+ if validator .is_valid (instance , schema ["if" ]):
287
282
evaluated_indexes += find_evaluated_item_indexes_by_schema (
288
- validator , instance , schema ['if' ]
283
+ validator , instance , schema ["if" ]
289
284
)
290
- if ' then' in schema :
285
+ if " then" in schema :
291
286
evaluated_indexes += find_evaluated_item_indexes_by_schema (
292
- validator , instance , schema [' then' ]
287
+ validator , instance , schema [" then" ]
293
288
)
294
289
else :
295
- if ' else' in schema :
290
+ if " else" in schema :
296
291
evaluated_indexes += find_evaluated_item_indexes_by_schema (
297
- validator , instance , schema [' else' ]
292
+ validator , instance , schema [" else" ]
298
293
)
299
294
300
- for keyword in [' contains' , ' unevaluatedItems' ]:
295
+ for keyword in [" contains" , " unevaluatedItems" ]:
301
296
if keyword in schema :
302
297
for k , v in enumerate (instance ):
303
298
if validator .is_valid (v , schema [keyword ]):
304
299
evaluated_indexes .append (k )
305
300
306
- for keyword in [' allOf' , ' oneOf' , ' anyOf' ]:
301
+ for keyword in [" allOf" , " oneOf" , " anyOf" ]:
307
302
if keyword in schema :
308
303
for subschema in schema [keyword ]:
309
304
errs = list (validator .descend (instance , subschema ))
@@ -320,28 +315,26 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
320
315
Get all keys of items that get evaluated under the current schema
321
316
322
317
Covers all keywords related to unevaluatedProperties: properties,
323
- ' additionalProperties', ' unevaluatedProperties' , patternProperties,
324
- dependentSchemas, ' allOf', ' oneOf', ' anyOf' , if, then, else
318
+ additionalProperties, unevaluatedProperties, patternProperties,
319
+ dependentSchemas, allOf, oneOf, anyOf, if, then, else
325
320
"""
326
- if not validator .is_type (schema , "object " ):
321
+ if validator .is_type (schema , "boolean " ):
327
322
return []
328
323
evaluated_keys = []
329
324
330
- if '$ref' in schema :
331
- resolve = getattr (validator .resolver , "resolve" , None )
332
- if resolve :
333
- scope , resolved = validator .resolver .resolve (schema ['$ref' ])
334
- validator .resolver .push_scope (scope )
325
+ if "$ref" in schema :
326
+ scope , resolved = validator .resolver .resolve (schema ["$ref" ])
327
+ validator .resolver .push_scope (scope )
335
328
336
- try :
337
- evaluated_keys += find_evaluated_property_keys_by_schema (
338
- validator , instance , resolved
339
- )
340
- finally :
341
- validator .resolver .pop_scope ()
329
+ try :
330
+ evaluated_keys += find_evaluated_property_keys_by_schema (
331
+ validator , instance , resolved
332
+ )
333
+ finally :
334
+ validator .resolver .pop_scope ()
342
335
343
336
for keyword in [
344
- ' properties' , ' additionalProperties' , ' unevaluatedProperties'
337
+ " properties" , " additionalProperties" , " unevaluatedProperties"
345
338
]:
346
339
if keyword in schema :
347
340
if validator .is_type (schema [keyword ], "boolean" ):
@@ -356,27 +349,23 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
356
349
):
357
350
evaluated_keys .append (property )
358
351
359
- if ' patternProperties' in schema :
352
+ if " patternProperties" in schema :
360
353
for property , value in instance .items ():
361
- for pattern , subschema in schema ['patternProperties' ].items ():
362
- if re .search (pattern , property ):
363
- if validator .is_valid (
364
- {property : value }, schema ['patternProperties' ]
365
- ):
366
- evaluated_keys .append (property )
367
-
368
- if 'dependentSchemas' in schema :
369
- for property , subschema in schema ['dependentSchemas' ].items ():
354
+ for pattern , subschema in schema ["patternProperties" ].items ():
355
+ if re .search (pattern , property ) and validator .is_valid (
356
+ {property : value }, schema ["patternProperties" ]
357
+ ):
358
+ evaluated_keys .append (property )
359
+
360
+ if "dependentSchemas" in schema :
361
+ for property , subschema in schema ["dependentSchemas" ].items ():
370
362
if property not in instance :
371
363
continue
364
+ evaluated_keys += find_evaluated_property_keys_by_schema (
365
+ validator , instance , subschema
366
+ )
372
367
373
- errs = list (validator .descend (instance , subschema ))
374
- if not errs :
375
- evaluated_keys += find_evaluated_property_keys_by_schema (
376
- validator , instance , subschema
377
- )
378
-
379
- for keyword in ['allOf' , 'oneOf' , 'anyOf' ]:
368
+ for keyword in ["allOf" , "oneOf" , "anyOf" ]:
380
369
if keyword in schema :
381
370
for subschema in schema [keyword ]:
382
371
errs = list (validator .descend (instance , subschema ))
@@ -385,19 +374,19 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
385
374
validator , instance , subschema
386
375
)
387
376
388
- if 'if' in schema :
389
- if validator .is_valid (instance , schema ['if' ]):
377
+ if "if" in schema :
378
+ if validator .is_valid (instance , schema ["if" ]):
390
379
evaluated_keys += find_evaluated_property_keys_by_schema (
391
- validator , instance , schema ['if' ]
380
+ validator , instance , schema ["if" ]
392
381
)
393
- if ' then' in schema :
382
+ if " then" in schema :
394
383
evaluated_keys += find_evaluated_property_keys_by_schema (
395
- validator , instance , schema [' then' ]
384
+ validator , instance , schema [" then" ]
396
385
)
397
386
else :
398
- if ' else' in schema :
387
+ if " else" in schema :
399
388
evaluated_keys += find_evaluated_property_keys_by_schema (
400
- validator , instance , schema [' else' ]
389
+ validator , instance , schema [" else" ]
401
390
)
402
391
403
392
return evaluated_keys
0 commit comments