@@ -14,8 +14,10 @@ export function getBlankObject(schema, getRef) {
1414 let isRef = value . hasOwnProperty ( '$ref' ) ;
1515 let isConst = value . hasOwnProperty ( 'const' ) ;
1616
17- if ( isRef )
18- value = getRef ( value [ '$ref' ] ) ;
17+ if ( isRef ) {
18+ value = { ...getRef ( value [ '$ref' ] ) , ...value } ;
19+ delete value [ '$ref' ] ;
20+ }
1921
2022 let type = normalizeKeyword ( value . type ) ;
2123
@@ -81,7 +83,8 @@ export function getBlankArray(schema, getRef) {
8183 if ( schema . items . hasOwnProperty ( '$ref' ) ) {
8284 // :TODO: this mutates the original schema
8385 // but i'll fix it later
84- schema . items = getRef ( schema . items [ '$ref' ] ) ;
86+ schema . items = { ...getRef ( schema . items [ '$ref' ] ) , ...schema . items } ;
87+ delete schema . items [ '$ref' ] ;
8588 }
8689
8790 let type = normalizeKeyword ( schema . items . type ) ;
@@ -166,8 +169,10 @@ export function getBlankAnyOf(schema, getRef) {
166169
167170
168171export function getBlankData ( schema , getRef ) {
169- if ( schema . hasOwnProperty ( '$ref' ) )
170- schema = getRef ( schema [ '$ref' ] ) ;
172+ if ( schema . hasOwnProperty ( '$ref' ) ) {
173+ schema = { ...getRef ( schema [ '$ref' ] ) , ...schema } ;
174+ delete schema [ '$ref' ] ;
175+ }
171176
172177 let type = getSchemaType ( schema ) ;
173178
@@ -209,7 +214,8 @@ function getSyncedArray(data, schema, getRef) {
209214 if ( schema . items . hasOwnProperty ( '$ref' ) ) {
210215 // :TODO: this will most probably mutate the original schema
211216 // but i'll fix it later
212- schema . items = getRef ( schema . items [ '$ref' ] )
217+ schema . items = { ...getRef ( schema . items [ '$ref' ] ) , ...schema . items } ;
218+ delete schema . items [ '$ref' ] ;
213219 }
214220
215221 let type ;
@@ -291,8 +297,10 @@ function getSyncedObject(data, schema, getRef) {
291297
292298 let isRef = schemaValue . hasOwnProperty ( '$ref' ) ;
293299
294- if ( isRef )
295- schemaValue = getRef ( schemaValue [ '$ref' ] ) ;
300+ if ( isRef ) {
301+ schemaValue = { ...getRef ( schemaValue [ '$ref' ] ) , ...schemaValue } ;
302+ delete schemaValue [ '$ref' ] ;
303+ }
296304
297305 let type ;
298306 let default_ ;
@@ -384,8 +392,10 @@ export function getSyncedAnyOf(data, schema, getRef) {
384392
385393export function getSyncedData ( data , schema , getRef ) {
386394 // adds those keys to data which are in schema but not in data
387- if ( schema . hasOwnProperty ( '$ref' ) )
388- schema = getRef ( schema [ '$ref' ] ) ;
395+ if ( schema . hasOwnProperty ( '$ref' ) ) {
396+ schema = { ...getRef ( schema [ '$ref' ] ) , ...schema } ;
397+ delete schema [ '$ref' ] ;
398+ }
389399
390400
391401 let type = getSchemaType ( schema ) ;
@@ -424,8 +434,10 @@ export function findMatchingSubschemaIndex(data, schema, getRef, schemaName) {
424434 for ( let i = 0 ; i < subschemas . length ; i ++ ) {
425435 let subschema = subschemas [ i ] ;
426436
427- if ( subschema . hasOwnProperty ( '$ref' ) )
428- subschema = getRef ( subschema [ '$ref' ] ) ;
437+ if ( subschema . hasOwnProperty ( '$ref' ) ) {
438+ subschema = { ...getRef ( subschema [ '$ref' ] ) , ...subschema } ;
439+ delete subschema [ '$ref' ] ;
440+ }
429441
430442 let subType = getSchemaType ( subschema ) ;
431443
@@ -453,8 +465,10 @@ export function findMatchingSubschemaIndex(data, schema, getRef, schemaName) {
453465 for ( let i = 0 ; i < subschemas . length ; i ++ ) {
454466 let subschema = subschemas [ i ] ;
455467
456- if ( subschema . hasOwnProperty ( '$ref' ) )
457- subschema = getRef ( subschema [ '$ref' ] ) ;
468+ if ( subschema . hasOwnProperty ( '$ref' ) ) {
469+ subschema = { ...getRef ( subschema [ '$ref' ] ) , ...subschema } ;
470+ delete subschema [ '$ref' ] ;
471+ }
458472
459473 let subType = getSchemaType ( subschema ) ;
460474
0 commit comments