@@ -555,13 +555,13 @@ function maybeAddDefaultToObject(
555
555
obj . set ( key , computedDefault ) ;
556
556
}
557
557
} else if ( emptyObjectFields !== "skipDefaults" ) {
558
- if ( isSchemaObjectValue ( computedDefault ) ) {
559
- // If isParentRequired is undefined, then we are at the root level of the schema so defer to the requiredness of
560
- // the field key itself in the `requiredField` list
561
- const isSelfOrParentRequired = isSchemaRoot
562
- ? requiredFields . has ( key )
563
- : isParentRequired ;
558
+ // If isParentRequired is undefined, then we are at the root level of the schema so defer to the requiredness of
559
+ // the field key itself in the `requiredField` list
560
+ const isSelfOrParentRequired = isSchemaRoot
561
+ ? requiredFields . has ( key )
562
+ : isParentRequired ;
564
563
564
+ if ( isSchemaObjectValue ( computedDefault ) ) {
565
565
// If emptyObjectFields 'skipEmptyDefaults' store computedDefault if it's a non-empty object(e.g. not {})
566
566
if ( emptyObjectFields === "skipEmptyDefaults" ) {
567
567
if ( ! isSchemaValueEmpty ( computedDefault ) ) {
@@ -585,7 +585,7 @@ function maybeAddDefaultToObject(
585
585
computedDefault !== undefined &&
586
586
( emptyObjectFields === "populateAllDefaults" ||
587
587
emptyObjectFields === "skipEmptyDefaults" ||
588
- requiredFields . has ( key ) )
588
+ ( isSelfOrParentRequired && requiredFields . has ( key ) ) )
589
589
) {
590
590
obj . set ( key , computedDefault ) ;
591
591
}
0 commit comments