@@ -354,10 +354,8 @@ def _validate_collection(self, value, custom_formatters=None):
354
354
)
355
355
if len (value ) < self .min_items :
356
356
raise InvalidSchemaValue (
357
- "Value must contain at least {0} item(s),"
358
- " {1} found" .format (
359
- self .min_items , len (value ))
360
- )
357
+ "Value must contain at least {type} item(s),"
358
+ " {value} found" , len (value ), self .min_items )
361
359
if self .max_items is not None :
362
360
if self .max_items < 0 :
363
361
raise OpenAPISchemaError (
@@ -366,47 +364,36 @@ def _validate_collection(self, value, custom_formatters=None):
366
364
)
367
365
if len (value ) > self .max_items :
368
366
raise InvalidSchemaValue (
369
- "Value must contain at most {0} item(s),"
370
- " {1} found" .format (
371
- self .max_items , len (value ))
372
- )
367
+ "Value must contain at most {value} item(s),"
368
+ " {type} found" , len (value ), self .max_items )
373
369
if self .unique_items and len (set (value )) != len (value ):
374
- raise InvalidSchemaValue ("Value may not contain duplicate items" )
370
+ raise OpenAPISchemaError ("Value may not contain duplicate items" )
375
371
376
372
f = functools .partial (self .items .validate ,
377
373
custom_formatters = custom_formatters )
378
374
return list (map (f , value ))
379
375
380
- def _validate_number (self , value ):
376
+ def _validate_number (self , value , custom_formatters = None ):
381
377
if self .minimum is not None :
382
378
if self .exclusive_minimum and value <= self .minimum :
383
379
raise InvalidSchemaValue (
384
- "Value {0} is not less than or equal to {1}" .format (
385
- value , self .minimum )
386
- )
380
+ "Value {value} is not less than or equal to {type}" , value , self .minimum )
387
381
elif value < self .minimum :
388
382
raise InvalidSchemaValue (
389
- "Value {0} is not less than {1}" .format (
390
- value , self .minimum )
391
- )
383
+ "Value {value} is not less than {type}" , value , self .minimum )
392
384
393
385
if self .maximum is not None :
394
386
if self .exclusive_maximum and value >= self .maximum :
395
387
raise InvalidSchemaValue (
396
- "Value {0} is not greater than or equal to {1}" .format (
397
- value , self .maximum )
398
- )
388
+ "Value {value} is not greater than or equal to {type}" , value , self .maximum )
399
389
elif value > self .maximum :
400
390
raise InvalidSchemaValue (
401
- "Value {0} is not greater than {1}" .format (
402
- value , self .maximum )
403
- )
391
+ "Value {value} is not greater than {type}" , value , self .maximum )
404
392
405
393
if self .multiple_of is not None and value % self .multiple_of :
406
394
raise InvalidSchemaValue (
407
- "Value {0 } is not a multiple of {1}" . format (
395
+ "Value {value } is not a multiple of {type}" ,
408
396
value , self .multiple_of )
409
- )
410
397
411
398
def _validate_string (self , value , custom_formatters = None ):
412
399
try :
@@ -435,8 +422,8 @@ def _validate_string(self, value, custom_formatters=None):
435
422
)
436
423
if len (value ) < self .min_length :
437
424
raise InvalidSchemaValue (
438
- "Value is shorter than the minimum length of {0}" . format (
439
- self .min_length )
425
+ "Value is shorter ({value}) than the minimum length of {type}" ,
426
+ len ( value ), self .min_length
440
427
)
441
428
if self .max_length is not None :
442
429
if self .max_length < 0 :
@@ -446,13 +433,13 @@ def _validate_string(self, value, custom_formatters=None):
446
433
)
447
434
if len (value ) > self .max_length :
448
435
raise InvalidSchemaValue (
449
- "Value is longer than the maximum length of {0}" . format (
450
- self .max_length )
436
+ "Value is longer ({value}) than the maximum length of {type}" ,
437
+ len ( value ), self .max_length
451
438
)
452
439
if self .pattern is not None and not self .pattern .search (value ):
453
440
raise InvalidSchemaValue (
454
- "Value {0 } does not match the pattern {1}" . format (
455
- value , self .pattern .pattern )
441
+ "Value {value } does not match the pattern {type}" ,
442
+ value , self .pattern .pattern
456
443
)
457
444
458
445
return True
@@ -490,9 +477,8 @@ def _validate_object(self, value, custom_formatters=None):
490
477
491
478
if len (properties ) < self .min_properties :
492
479
raise InvalidSchemaValue (
493
- "Value must contain at least {0} properties,"
494
- " {1} found" .format (
495
- self .min_properties , len (properties ))
480
+ "Value must contain at least {type} properties,"
481
+ " {value} found" , len (properties ), self .min_properties
496
482
)
497
483
498
484
if self .max_properties is not None :
@@ -503,9 +489,8 @@ def _validate_object(self, value, custom_formatters=None):
503
489
)
504
490
if len (properties ) > self .max_properties :
505
491
raise InvalidSchemaValue (
506
- "Value must contain at most {0} properties,"
507
- " {1} found" .format (
508
- self .max_properties , len (properties ))
492
+ "Value must contain at most {type} properties,"
493
+ " {value} found" , len (properties ), self .max_properties
509
494
)
510
495
511
496
return True
0 commit comments