@@ -428,15 +428,19 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
428
428
let maxItems = schema . get ( "maxItems" )
429
429
let minItems = schema . get ( "minItems" )
430
430
let pattern = schema . get ( "pattern" )
431
+ const isReadOnly = schema . get ( "readOnly" , false )
432
+
433
+ let isRequired = isReadOnly
434
+ ? false
435
+ : requiredByParam || requiredBySchema === true
431
436
432
- const schemaRequiresValue = requiredByParam || requiredBySchema === true
433
437
const hasValue = value !== undefined && value !== null
434
- const isValidEmpty = ! schemaRequiresValue && ! hasValue
438
+ const isValidEmpty = ! isRequired && ! hasValue
435
439
436
440
const needsExplicitConstraintValidation = hasValue && type === "array"
437
441
438
442
const requiresFurtherValidation =
439
- schemaRequiresValue
443
+ isRequired
440
444
|| needsExplicitConstraintValidation
441
445
|| ! isValidEmpty
442
446
@@ -471,7 +475,7 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
471
475
472
476
const passedAnyCheck = allChecks . some ( v => ! ! v )
473
477
474
- if ( schemaRequiresValue && ! passedAnyCheck && ! bypassRequiredCheck ) {
478
+ if ( isRequired && ! passedAnyCheck && ! bypassRequiredCheck ) {
475
479
errors . push ( "Required field is not provided" )
476
480
return errors
477
481
}
@@ -491,7 +495,8 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
491
495
}
492
496
if ( schema && schema . has ( "required" ) && isFunc ( requiredBySchema . isList ) && requiredBySchema . isList ( ) ) {
493
497
requiredBySchema . forEach ( key => {
494
- if ( objectVal [ key ] === undefined ) {
498
+ const propIsReadOnly = schema . getIn ( [ "properties" , key , "readOnly" ] , false )
499
+ if ( ! propIsReadOnly && objectVal [ key ] === undefined ) {
495
500
errors . push ( { propKey : key , error : "Required property not found" } )
496
501
}
497
502
} )
0 commit comments