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