@@ -29,8 +29,6 @@ const validLargeArrayMechanisms = [
29
29
30
30
let schemaIdCounter = 0
31
31
32
- const mergedSchemaRef = Symbol ( 'fjs-merged-schema-ref' )
33
-
34
32
function isValidSchema ( schema , name ) {
35
33
if ( ! validate ( schema ) ) {
36
34
if ( name ) {
@@ -93,7 +91,8 @@ function build (schema, options) {
93
91
options,
94
92
refResolver : new RefResolver ( ) ,
95
93
rootSchemaId : schema . $id || `__fjs_root_${ schemaIdCounter ++ } ` ,
96
- validatorSchemasIds : new Set ( )
94
+ validatorSchemasIds : new Set ( ) ,
95
+ mergedSchemasIds : new Map ( )
97
96
}
98
97
99
98
const schemaId = getSchemaId ( schema , context . rootSchemaId )
@@ -408,7 +407,7 @@ function mergeLocations (context, mergedSchemaId, mergedLocations) {
408
407
409
408
const mergedSchemas = [ ]
410
409
for ( const location of mergedLocations ) {
411
- const schema = cloneOriginSchema ( location . schema , location . schemaId )
410
+ const schema = cloneOriginSchema ( context , location . schema , location . schemaId )
412
411
delete schema . $id
413
412
414
413
mergedSchemas . push ( schema )
@@ -421,7 +420,7 @@ function mergeLocations (context, mergedSchemaId, mergedLocations) {
421
420
return mergedLocation
422
421
}
423
422
424
- function cloneOriginSchema ( schema , schemaId ) {
423
+ function cloneOriginSchema ( context , schema , schemaId ) {
425
424
const clonedSchema = Array . isArray ( schema ) ? [ ] : { }
426
425
427
426
if (
@@ -431,8 +430,9 @@ function cloneOriginSchema (schema, schemaId) {
431
430
schemaId = schema . $id
432
431
}
433
432
434
- if ( schema [ mergedSchemaRef ] ) {
435
- clonedSchema [ mergedSchemaRef ] = schema [ mergedSchemaRef ]
433
+ const mergedSchemaRef = context . mergedSchemasIds . get ( schema )
434
+ if ( mergedSchemaRef ) {
435
+ context . mergedSchemasIds . set ( clonedSchema , mergedSchemaRef )
436
436
}
437
437
438
438
for ( const key in schema ) {
@@ -443,7 +443,7 @@ function cloneOriginSchema (schema, schemaId) {
443
443
}
444
444
445
445
if ( typeof value === 'object' && value !== null ) {
446
- value = cloneOriginSchema ( value , schemaId )
446
+ value = cloneOriginSchema ( context , value , schemaId )
447
447
}
448
448
449
449
clonedSchema [ key ] = value
@@ -780,14 +780,14 @@ function buildConstSerializer (location, input) {
780
780
function buildAllOf ( context , location , input ) {
781
781
const schema = location . schema
782
782
783
- let mergedSchemaId = schema [ mergedSchemaRef ]
783
+ let mergedSchemaId = context . mergedSchemasIds . get ( schema )
784
784
if ( mergedSchemaId ) {
785
785
const mergedLocation = getMergedLocation ( context , mergedSchemaId )
786
786
return buildValue ( context , mergedLocation , input )
787
787
}
788
788
789
789
mergedSchemaId = `__fjs_merged_${ schemaIdCounter ++ } `
790
- schema [ mergedSchemaRef ] = mergedSchemaId
790
+ context . mergedSchemasIds . set ( schema , mergedSchemaId )
791
791
792
792
const { allOf, ...schemaWithoutAllOf } = location . schema
793
793
const locations = [
@@ -828,13 +828,13 @@ function buildOneOf (context, location, input) {
828
828
const optionLocation = oneOfsLocation . getPropertyLocation ( index )
829
829
const optionSchema = optionLocation . schema
830
830
831
- let mergedSchemaId = optionSchema [ mergedSchemaRef ]
831
+ let mergedSchemaId = context . mergedSchemasIds . get ( optionSchema )
832
832
let mergedLocation = null
833
833
if ( mergedSchemaId ) {
834
834
mergedLocation = getMergedLocation ( context , mergedSchemaId )
835
835
} else {
836
836
mergedSchemaId = `__fjs_merged_${ schemaIdCounter ++ } `
837
- optionSchema [ mergedSchemaRef ] = mergedSchemaId
837
+ context . mergedSchemasIds . set ( optionSchema , mergedSchemaId )
838
838
839
839
mergedLocation = mergeLocations ( context , mergedSchemaId , [
840
840
locationWithoutOneOf ,
@@ -882,13 +882,13 @@ function buildIfThenElse (context, location, input) {
882
882
const ifSchemaRef = ifLocation . getSchemaRef ( )
883
883
884
884
const thenLocation = location . getPropertyLocation ( 'then' )
885
- let thenMergedSchemaId = thenSchema [ mergedSchemaRef ]
885
+ let thenMergedSchemaId = context . mergedSchemasIds . get ( thenSchema )
886
886
let thenMergedLocation = null
887
887
if ( thenMergedSchemaId ) {
888
888
thenMergedLocation = getMergedLocation ( context , thenMergedSchemaId )
889
889
} else {
890
890
thenMergedSchemaId = `__fjs_merged_${ schemaIdCounter ++ } `
891
- thenSchema [ mergedSchemaRef ] = thenMergedSchemaId
891
+ context . mergedSchemasIds . set ( thenSchema , thenMergedSchemaId )
892
892
893
893
thenMergedLocation = mergeLocations ( context , thenMergedSchemaId , [
894
894
rootLocation ,
@@ -907,13 +907,13 @@ function buildIfThenElse (context, location, input) {
907
907
}
908
908
909
909
const elseLocation = location . getPropertyLocation ( 'else' )
910
- let elseMergedSchemaId = elseSchema [ mergedSchemaRef ]
910
+ let elseMergedSchemaId = context . mergedSchemasIds . get ( elseSchema )
911
911
let elseMergedLocation = null
912
912
if ( elseMergedSchemaId ) {
913
913
elseMergedLocation = getMergedLocation ( context , elseMergedSchemaId )
914
914
} else {
915
915
elseMergedSchemaId = `__fjs_merged_${ schemaIdCounter ++ } `
916
- elseSchema [ mergedSchemaRef ] = elseMergedSchemaId
916
+ context . mergedSchemasIds . set ( elseSchema , elseMergedSchemaId )
917
917
918
918
elseMergedLocation = mergeLocations ( context , elseMergedSchemaId , [
919
919
rootLocation ,
0 commit comments