@@ -352,7 +352,10 @@ protected function validateScheme(Definition $scheme, JSONPath $jsonPath)
352
352
*/
353
353
protected function validateProperty (Property $ property , $ value )
354
354
{
355
- if ($ property ->required && $ value === null ) {
355
+ // Supported inside Swagger 3+ for Property, now will be null as default
356
+ $ nullable = true ;
357
+
358
+ if ($ nullable === false && $ value === null ) {
356
359
throw new RuntimeException (
357
360
sprintf (
358
361
'Property %s is required and cannot be null ' ,
@@ -365,14 +368,27 @@ protected function validateProperty(Property $property, $value)
365
368
case 'array ' :
366
369
if ($ property ->required ) {
367
370
if (gettype ($ value ) != $ property ->type ) {
368
- throw new RuntimeException (
369
- sprintf (
370
- 'Type of the property %s must be %s instead of %s actual ' ,
371
- $ property ->property ,
372
- $ property ->type ,
373
- gettype ($ value )
374
- )
375
- );
371
+ if ($ nullable ) {
372
+ if ($ value !== null ) {
373
+ throw new RuntimeException (
374
+ sprintf (
375
+ 'Type of the property %s must be %s|null (because nullable) instead of %s actual ' ,
376
+ $ property ->property ,
377
+ $ property ->type ,
378
+ gettype ($ value )
379
+ )
380
+ );
381
+ }
382
+ } else {
383
+ throw new RuntimeException (
384
+ sprintf (
385
+ 'Type of the property %s must be %s instead of %s actual ' ,
386
+ $ property ->property ,
387
+ $ property ->type ,
388
+ gettype ($ value )
389
+ )
390
+ );
391
+ }
376
392
}
377
393
378
394
if ($ property ->minItems ) {
@@ -407,18 +423,30 @@ protected function validateProperty(Property $property, $value)
407
423
case 'boolean ' :
408
424
case 'string ' :
409
425
case 'integer ' :
410
- if ($ value !== null && gettype ($ value ) != $ property ->type ) {
411
- throw new RuntimeException (
412
- sprintf (
413
- 'Type of the property %s must be %s instead of %s ' ,
414
- $ property ->property ,
415
- $ property ->type ,
416
- gettype ($ value )
417
- )
418
- );
426
+ if (gettype ($ value ) != $ property ->type ) {
427
+ if ($ nullable ) {
428
+ if ($ value !== null ) {
429
+ throw new RuntimeException (
430
+ sprintf (
431
+ 'Type of the property %s must be %s|null (because nullable) instead of %s ' ,
432
+ $ property ->property ,
433
+ $ property ->type ,
434
+ gettype ($ value )
435
+ )
436
+ );
437
+ }
438
+ } else {
439
+ throw new RuntimeException (
440
+ sprintf (
441
+ 'Type of the property %s must be %s instead of %s ' ,
442
+ $ property ->property ,
443
+ $ property ->type ,
444
+ gettype ($ value )
445
+ )
446
+ );
447
+ }
419
448
}
420
449
421
-
422
450
if ($ value !== null ) {
423
451
if (!$ this ->checkFormat ($ property , $ value )) {
424
452
throw new RuntimeException (
@@ -479,15 +507,28 @@ protected function validateProperty(Property $property, $value)
479
507
}
480
508
break ;
481
509
case 'number ' :
482
- if ($ value !== null && gettype ($ value ) != 'double ' ) {
483
- throw new RuntimeException (
484
- sprintf (
485
- 'Type of the property %s must be %s instead of %s ' ,
486
- $ property ->property ,
487
- $ property ->type ,
488
- gettype ($ value )
489
- )
490
- );
510
+ if (gettype ($ value ) != 'double ' ) {
511
+ if ($ nullable ) {
512
+ if ($ value !== null ) {
513
+ throw new RuntimeException (
514
+ sprintf (
515
+ 'Type of the property %s must be %s|null (because nullable) instead of %s ' ,
516
+ $ property ->property ,
517
+ $ property ->type ,
518
+ gettype ($ value )
519
+ )
520
+ );
521
+ }
522
+ } else {
523
+ throw new RuntimeException (
524
+ sprintf (
525
+ 'Type of the property %s must be %s instead of %s ' ,
526
+ $ property ->property ,
527
+ $ property ->type ,
528
+ gettype ($ value )
529
+ )
530
+ );
531
+ }
491
532
}
492
533
}
493
534
0 commit comments