@@ -429,9 +429,12 @@ function getSyncedObject(data, schema, getRef) {
429
429
}
430
430
431
431
if ( ! data . hasOwnProperty ( key ) ) {
432
- if ( type === 'array' ) newData [ key ] = getSyncedArray ( [ ] , schemaValue , getRef ) ; else if ( type === 'object' ) newData [ key ] = getSyncedObject ( { } , schemaValue , getRef ) ; else if ( type === 'boolean' ) newData [ key ] = default_ === false ? false : default_ || null ; else if ( type === 'integer' || type === 'number' ) newData [ key ] = default_ === 0 ? 0 : default_ || null ; else newData [ key ] = default_ || '' ;
432
+ /* This key is declared in schema but it's not present in the data.
433
+ So we can use blank data here.
434
+ */
435
+ if ( type === 'array' ) newData [ key ] = getSyncedArray ( [ ] , schemaValue , getRef ) ; else if ( type === 'object' ) newData [ key ] = getSyncedObject ( { } , schemaValue , getRef ) ; else if ( type === 'oneOf' ) newData [ key ] = getBlankOneOf ( schemaValue , getRef ) ; else if ( type === 'anyOf' ) newData [ key ] = getBlankAntOf ( schemaValue , getRef ) ; else if ( type === 'boolean' ) newData [ key ] = default_ === false ? false : default_ || null ; else if ( type === 'integer' || type === 'number' ) newData [ key ] = default_ === 0 ? 0 : default_ || null ; else newData [ key ] = default_ || '' ;
433
436
} else {
434
- if ( type === 'array' ) newData [ key ] = getSyncedArray ( data [ key ] , schemaValue , getRef ) ; else if ( type === 'object' ) newData [ key ] = getSyncedObject ( data [ key ] , schemaValue , getRef ) ; else {
437
+ if ( type === 'array' ) newData [ key ] = getSyncedArray ( data [ key ] , schemaValue , getRef ) ; else if ( type === 'object' ) newData [ key ] = getSyncedObject ( data [ key ] , schemaValue , getRef ) ; else if ( type === 'oneOf' ) newData [ key ] = getSyncedOneOf ( data [ key ] , schemaValue , getRef ) ; else if ( type === 'anyOf' ) newData [ key ] = getSyncedAnyOf ( data [ key ] , schemaValue , getRef ) ; else {
435
438
// if the current value is not in choices, we reset to blank
436
439
if ( ! valueInChoices ( schemaValue , data [ key ] ) ) data [ key ] = '' ;
437
440
@@ -446,6 +449,8 @@ function getSyncedObject(data, schema, getRef) {
446
449
if ( schemaValue . hasOwnProperty ( 'const' ) ) newData [ key ] = schemaValue . const ;
447
450
}
448
451
452
+ if ( schema . hasOwnProperty ( 'oneOf' ) ) newData = _extends ( { } , newData , getSyncedOneOf ( data , schema , getRef ) ) ;
453
+ if ( schema . hasOwnProperty ( 'anyOf' ) ) newData = _extends ( { } , newData , getSyncedAnyOf ( data , schema , getRef ) ) ;
449
454
return newData ;
450
455
}
451
456
@@ -539,6 +544,13 @@ function findMatchingSubschemaIndex(data, schema, getRef, schemaName) {
539
544
}
540
545
}
541
546
547
+ if ( index === null ) {
548
+ // still no match found
549
+ if ( data === null ) // for null data, return the first subschema and hope for the best
550
+ index = 1 ; else // for anything else, throw error
551
+ throw new Error ( "No matching subschema found in '" + schemaName + "' for data '" + data + "' (type: " + dataType + ")" ) ;
552
+ }
553
+
542
554
return index ;
543
555
}
544
556
function dataObjectMatchesSchema ( data , subschema ) {
0 commit comments