@@ -35,14 +35,17 @@ function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = Pars
3535 options : O ,
3636) {
3737 // console.log('Bundling $ref pointers in %s', parser.$refs._root$Ref.path);
38+ const rootScopeBase = parser . $refs . _root$Ref . dynamicIdScope
39+ ? getSchemaBasePath ( parser . $refs . _root$Ref . path ! , parser . schema )
40+ : parser . $refs . _root$Ref . path ! ;
3841
3942 // Build an inventory of all $ref pointers in the JSON Schema
4043 const inventory : InventoryEntry [ ] = [ ] ;
4144 crawl < S , O > (
4245 parser ,
4346 "schema" ,
4447 parser . $refs . _root$Ref . path + "#" ,
45- parser . $refs . _root$Ref . path ! ,
48+ rootScopeBase ,
4649 parser . $refs . _root$Ref . dynamicIdScope ,
4750 "#" ,
4851 0 ,
@@ -96,7 +99,7 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
9699 const isExcludedPath = bundleOptions . excludedPathMatcher || ( ( ) => false ) ;
97100
98101 if ( obj && typeof obj === "object" && ! ArrayBuffer . isView ( obj ) && ! isExcludedPath ( pathFromRoot ) ) {
99- const currentScopeBase = dynamicIdScope ? getSchemaBasePath ( scopeBase , obj ) : scopeBase ;
102+ const currentScopeBase = scopeBase ;
100103 if ( $Ref . isAllowed$Ref ( obj ) ) {
101104 inventory$Ref ( parent , key , path , currentScopeBase , dynamicIdScope , pathFromRoot , indirections , inventory , $refs , options ) ;
102105 } else {
@@ -121,14 +124,17 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
121124 const keyPath = Pointer . join ( path , key ) ;
122125 const keyPathFromRoot = Pointer . join ( pathFromRoot , key ) ;
123126 const value = obj [ key ] ;
127+ const childScopeBase =
128+ dynamicIdScope && value && typeof value === "object" && ! ArrayBuffer . isView ( value )
129+ ? getSchemaBasePath ( currentScopeBase , value )
130+ : currentScopeBase ;
124131
125132 if ( $Ref . isAllowed$Ref ( value ) ) {
126- const valueScopeBase = dynamicIdScope ? getSchemaBasePath ( currentScopeBase , value ) : currentScopeBase ;
127133 inventory$Ref (
128134 obj ,
129135 key ,
130136 keyPath ,
131- valueScopeBase ,
137+ childScopeBase ,
132138 dynamicIdScope ,
133139 keyPathFromRoot ,
134140 indirections ,
@@ -137,7 +143,7 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
137143 options ,
138144 ) ;
139145 } else {
140- crawl ( obj , key , keyPath , currentScopeBase , dynamicIdScope , keyPathFromRoot , indirections , inventory , $refs , options ) ;
146+ crawl ( obj , key , keyPath , childScopeBase , dynamicIdScope , keyPathFromRoot , indirections , inventory , $refs , options ) ;
141147 }
142148
143149 // We need to ensure that we have an object to work with here because we may be crawling
0 commit comments