@@ -429,9 +429,12 @@ function getSyncedObject(data, schema, getRef) {
429429 }
430430
431431 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_ || '' ;
433436 } 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 {
435438 // if the current value is not in choices, we reset to blank
436439 if ( ! valueInChoices ( schemaValue , data [ key ] ) ) data [ key ] = '' ;
437440
@@ -446,6 +449,8 @@ function getSyncedObject(data, schema, getRef) {
446449 if ( schemaValue . hasOwnProperty ( 'const' ) ) newData [ key ] = schemaValue . const ;
447450 }
448451
452+ if ( schema . hasOwnProperty ( 'oneOf' ) ) newData = _extends ( { } , newData , getSyncedOneOf ( data , schema , getRef ) ) ;
453+ if ( schema . hasOwnProperty ( 'anyOf' ) ) newData = _extends ( { } , newData , getSyncedAnyOf ( data , schema , getRef ) ) ;
449454 return newData ;
450455}
451456
@@ -539,6 +544,13 @@ function findMatchingSubschemaIndex(data, schema, getRef, schemaName) {
539544 }
540545 }
541546
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+
542554 return index ;
543555}
544556function dataObjectMatchesSchema ( data , subschema ) {
0 commit comments