@@ -167,6 +167,10 @@ public function process($data, Context $options, $path = '#', $result = null)
167
167
$ result = $ data ;
168
168
}
169
169
170
+ if ($ options ->skipValidation ) {
171
+ goto skipValidation;
172
+ }
173
+
170
174
if ($ this ->type !== null ) {
171
175
if (!Type::isValid ($ this ->type , $ data )) {
172
176
$ this ->fail (new TypeException (ucfirst (
@@ -311,9 +315,10 @@ public function process($data, Context $options, $path = '#', $result = null)
311
315
}
312
316
}
313
317
318
+ skipValidation:
314
319
315
320
if ($ data instanceof \stdClass) {
316
- if ($ this ->required !== null ) {
321
+ if (! $ options -> skipValidation && $ this ->required !== null ) {
317
322
foreach ($ this ->required as $ item ) {
318
323
if (!property_exists ($ data , $ item )) {
319
324
$ this ->fail (new ObjectException ('Required property missing: ' . $ item , ObjectException::REQUIRED ), $ path );
@@ -416,20 +421,23 @@ public function process($data, Context $options, $path = '#', $result = null)
416
421
$ array = (array )$ data ;
417
422
}
418
423
419
- if ($ this ->minProperties !== null && count ($ array ) < $ this ->minProperties ) {
420
- $ this ->fail (new ObjectException ("Not enough properties " , ObjectException::TOO_FEW ), $ path );
421
- }
422
- if ($ this ->maxProperties !== null && count ($ array ) > $ this ->maxProperties ) {
423
- $ this ->fail (new ObjectException ("Too many properties " , ObjectException::TOO_MANY ), $ path );
424
+ if (!$ options ->skipValidation ) {
425
+ if ($ this ->minProperties !== null && count ($ array ) < $ this ->minProperties ) {
426
+ $ this ->fail (new ObjectException ("Not enough properties " , ObjectException::TOO_FEW ), $ path );
427
+ }
428
+ if ($ this ->maxProperties !== null && count ($ array ) > $ this ->maxProperties ) {
429
+ $ this ->fail (new ObjectException ("Too many properties " , ObjectException::TOO_MANY ), $ path );
430
+ }
424
431
}
432
+
425
433
foreach ($ array as $ key => $ value ) {
426
434
if ($ key === '' && PHP_VERSION_ID < 71000 ) {
427
435
$ this ->fail (new InvalidValue ('Empty property name ' ), $ path );
428
436
}
429
437
430
438
$ found = false ;
431
439
432
- if (!empty ($ this ->dependencies )) {
440
+ if (!$ options -> skipValidation && ! empty ($ this ->dependencies )) {
433
441
$ deps = $ this ->dependencies ;
434
442
if (isset ($ deps ->$ key )) {
435
443
$ dependencies = $ deps ->$ key ;
@@ -477,11 +485,14 @@ public function process($data, Context $options, $path = '#', $result = null)
477
485
}
478
486
}
479
487
if (!$ found && $ this ->additionalProperties !== null ) {
480
- if ($ this ->additionalProperties === false ) {
488
+ if (! $ options -> skipValidation && $ this ->additionalProperties === false ) {
481
489
$ this ->fail (new ObjectException ('Additional properties not allowed ' ), $ path . ': ' . $ key );
482
490
}
483
491
484
- $ value = $ this ->additionalProperties ->process ($ value , $ options , $ path . '->additionalProperties: ' . $ key );
492
+ if ($ this ->additionalProperties !== false ) {
493
+ $ value = $ this ->additionalProperties ->process ($ value , $ options , $ path . '->additionalProperties: ' . $ key );
494
+ }
495
+
485
496
if ($ import && !$ this ->useObjectAsArray ) {
486
497
$ result ->addAdditionalPropertyName ($ key );
487
498
}
@@ -511,12 +522,14 @@ public function process($data, Context $options, $path = '#', $result = null)
511
522
512
523
if (is_array ($ data )) {
513
524
514
- if ($ this ->minItems !== null && count ($ data ) < $ this ->minItems ) {
515
- $ this ->fail (new ArrayException ("Not enough items in array " ), $ path );
516
- }
525
+ if (!$ options ->skipValidation ) {
526
+ if ($ this ->minItems !== null && count ($ data ) < $ this ->minItems ) {
527
+ $ this ->fail (new ArrayException ("Not enough items in array " ), $ path );
528
+ }
517
529
518
- if ($ this ->maxItems !== null && count ($ data ) > $ this ->maxItems ) {
519
- $ this ->fail (new ArrayException ("Too many items in array " ), $ path );
530
+ if ($ this ->maxItems !== null && count ($ data ) > $ this ->maxItems ) {
531
+ $ this ->fail (new ArrayException ("Too many items in array " ), $ path );
532
+ }
520
533
}
521
534
522
535
$ pathItems = 'items ' ;
@@ -542,15 +555,15 @@ public function process($data, Context $options, $path = '#', $result = null)
542
555
if ($ additionalItems instanceof Schema) {
543
556
$ result [$ key ] = $ additionalItems ->process ($ value , $ options , $ path . '-> ' . $ pathItems
544
557
. '[ ' . $ index . '] ' );
545
- } elseif ($ additionalItems === false ) {
558
+ } elseif (! $ options -> skipValidation && $ additionalItems === false ) {
546
559
$ this ->fail (new ArrayException ('Unexpected array item ' ), $ path );
547
560
}
548
561
}
549
562
++$ index ;
550
563
}
551
564
}
552
565
553
- if ($ this ->uniqueItems ) {
566
+ if (! $ options -> skipValidation && $ this ->uniqueItems ) {
554
567
if (!UniqueItems::isValid ($ data )) {
555
568
$ this ->fail (new ArrayException ('Array is not unique ' ), $ path );
556
569
}
0 commit comments