@@ -81,11 +81,16 @@ public function __construct($schema, array $options = [])
81
81
}
82
82
83
83
$ this ->validator = new Validator ();
84
+ $ this ->validator ->setMaxErrors (99 );
84
85
85
86
$ this ->formatResolver = $ this ->validator ->parser ()->getFormatResolver ();
86
87
87
88
// Password validator only checks that it's a string, as format=password only is a hint to the UI
88
89
$ this ->formatResolver ->register ("string " , "password " , new OpenApiValidation \Formats \PasswordValidator ());
90
+
91
+
92
+ // Register our prime number format
93
+ $ formats ->registerCallable ("integer " , "prime " , $ isPrime );
89
94
90
95
}
91
96
@@ -401,7 +406,8 @@ private function validateProperties(array $properties) : ?array
401
406
} catch (Exception $ e ) {
402
407
}
403
408
if (isset ($ result ) && $ result ->hasError ()) {
404
- $ error = $ this ->parseErrors ($ result ->error (), $ property ->name , $ property ->in );
409
+ $ error = $ this ->parseErrors ($ result ->error (), $ property ->name , $ property ->in , $ property );
410
+
405
411
foreach ($ error as $ parsedError ) {
406
412
// As all query param values are strings type errors should be discarded
407
413
$ discard = false ;
@@ -437,7 +443,7 @@ private function validateObject(array $schema, string $value) : array
437
443
try {
438
444
$ value = json_decode ($ value );
439
445
$ schema = json_decode (json_encode ($ schema , JSON_PRESERVE_ZERO_FRACTION ));
440
- $ result = $ this ->validator ->validate ($ value , $ schema );
446
+ $ result = $ this ->validator ->validate ($ value , $ schema, );
441
447
} catch (Exception $ e ) {
442
448
return [[
443
449
'name ' => 'server ' ,
@@ -561,7 +567,7 @@ private function error(int $code, string $message, array $errors = []) : Respons
561
567
return $ response ->withBody ((new StreamFactory ())->createStream (json_encode ($ json , JSON_PRESERVE_ZERO_FRACTION )));
562
568
}
563
569
564
- private function parseErrors (ValidationError $ error , $ name = null , $ in = null ) : array
570
+ private function parseErrors (ValidationError $ error , $ name = null , $ in = null , ? Property $ property = null ) : array
565
571
{
566
572
$ errors = [];
567
573
if ($ error ->subErrors ()) {
@@ -587,12 +593,18 @@ private function parseErrors(ValidationError $error, $name = null, $in = null) :
587
593
$ err ['name ' ] .= ($ err ['name ' ] && mb_strlen ($ err ['name ' ])) ? '. ' .array_shift ($ err ['missing ' ]) : array_shift ($ err ['missing ' ]);
588
594
unset($ err ['missing ' ],$ err ['value ' ]);
589
595
}
596
+ if ('error_enum ' == $ err ['code ' ] && isset ($ property ->schema ->enum )) {
597
+ $ err ['expected ' ] = $ property ->schema ->enum ;
598
+ }
590
599
if ('error_ ' .'$ ' .'schema ' == $ err ['code ' ]) {
591
600
// This is a quickfix as the opis/json-schema wont give any other error message
592
601
// There should not be any other reason this error_$schema occurs
593
602
$ err ['code ' ] = 'error_additional ' ;
594
603
unset($ err ['schema ' ]);
595
604
}
605
+ if (isset ($ err ['expected ' ]) && !isset ($ err ['used ' ]) && isset ($ err ['type ' ])) {
606
+ $ err ['used ' ] = $ err ['type ' ];
607
+ }
596
608
// As the request body is parsed as an array, empty object and empty array will both be []
597
609
// Remove these errors
598
610
if (!$ this ->options ['strictEmptyArrayValidation ' ]) {
0 commit comments