@@ -94,7 +94,7 @@ export class ResolveRunner implements Types.IResolveRunner {
9494 return this . _source ;
9595 }
9696
97- public async resolve ( jsonPointer ?: string ) : Promise < Types . IResolveResult > {
97+ public async resolve ( jsonPointer ?: string , opts ?: Types . IResolveOpts ) : Promise < Types . IResolveResult > {
9898 const resolved : Types . IResolveResult = {
9999 result : this . source ,
100100 refMap : { } ,
@@ -171,68 +171,67 @@ export class ResolveRunner implements Types.IResolveRunner {
171171 }
172172 }
173173
174- if ( typeof this . _source !== 'object' ) {
175- resolved . result = this . _source ;
176- return resolved ;
177- }
178-
179- // If using parseAuthorityResult, do not need to replace local pointers here (parseAuthorityResult is responsible)
180- // if this is not an uri, then we should parse even if parseAuthorityResult is present
181- if ( this . dereferenceInline ) {
182- this . _source = produce ( this . _source , ( draft : any ) => {
183- let processOrder : any [ ] = [ ] ;
184-
185- try {
186- processOrder = crawler . pointerGraph . overallOrder ( ) ;
187-
188- // loop through the pointer graph in the correct order, setting values we go
189- // this is where local pointers are replaced with their resolved values
190- for ( const pointer of processOrder ) {
191- const dependants = crawler . pointerGraph . dependantsOf ( pointer ) ;
192- if ( ! dependants . length ) continue ;
193-
194- const pointerPath = pointerToPath ( pointer ) ;
195- const val = get ( draft , pointerPath ) ;
196- for ( const dependant of dependants ) {
197- // check to prevent circular references in the resulting JS object
198- // this implementation is MUCH more performant than decycling the final object to remove circulars
199- let isCircular ;
200- const dependantPath = pointerToPath ( dependant ) ;
201- const dependantStems = crawler . pointerStemGraph . dependenciesOf ( pointer ) ;
202- for ( const stem of dependantStems ) {
203- if ( startsWith ( dependantPath , pointerToPath ( stem ) ) ) {
204- isCircular = true ;
205- break ;
174+ if ( typeof this . _source === 'object' ) {
175+ // If using parseAuthorityResult, do not need to replace local pointers here (parseAuthorityResult is responsible)
176+ // if this is not an uri, then we should parse even if parseAuthorityResult is present
177+ if ( this . dereferenceInline ) {
178+ this . _source = produce ( this . _source , ( draft : any ) => {
179+ let processOrder : any [ ] = [ ] ;
180+
181+ try {
182+ processOrder = crawler . pointerGraph . overallOrder ( ) ;
183+
184+ // loop through the pointer graph in the correct order, setting values we go
185+ // this is where local pointers are replaced with their resolved values
186+ for ( const pointer of processOrder ) {
187+ const dependants = crawler . pointerGraph . dependantsOf ( pointer ) ;
188+ if ( ! dependants . length ) continue ;
189+
190+ const pointerPath = pointerToPath ( pointer ) ;
191+ const val = get ( draft , pointerPath ) ;
192+ for ( const dependant of dependants ) {
193+ // check to prevent circular references in the resulting JS object
194+ // this implementation is MUCH more performant than decycling the final object to remove circulars
195+ let isCircular ;
196+ const dependantPath = pointerToPath ( dependant ) ;
197+ const dependantStems = crawler . pointerStemGraph . dependenciesOf ( pointer ) ;
198+ for ( const stem of dependantStems ) {
199+ if ( startsWith ( dependantPath , pointerToPath ( stem ) ) ) {
200+ isCircular = true ;
201+ break ;
202+ }
206203 }
207- }
208204
209- // TODO: we might want to track and expose these circulars in the future?
210- if ( isCircular ) continue ;
211-
212- resolved . refMap [ pathToPointer ( dependantPath ) ] = pathToPointer ( pointerPath ) ;
213-
214- if ( val ) {
215- set ( draft , dependantPath , val ) ;
216- } else {
217- resolved . errors . push ( {
218- code : 'POINTER_MISSING' ,
219- message : `'${ pointer } ' does not exist` ,
220- path : dependantPath ,
221- uri : this . baseUri ,
222- uriStack : this . uriStack ,
223- pointerStack : [ ] ,
224- } ) ;
205+ // TODO: we might want to track and expose these circulars in the future?
206+ if ( isCircular ) continue ;
207+
208+ resolved . refMap [ pathToPointer ( dependantPath ) ] = pathToPointer ( pointerPath ) ;
209+
210+ if ( val ) {
211+ set ( draft , dependantPath , val ) ;
212+ } else {
213+ resolved . errors . push ( {
214+ code : 'POINTER_MISSING' ,
215+ message : `'${ pointer } ' does not exist` ,
216+ path : dependantPath ,
217+ uri : this . baseUri ,
218+ uriStack : this . uriStack ,
219+ pointerStack : [ ] ,
220+ } ) ;
221+ }
225222 }
226223 }
224+ } catch ( e ) {
225+ // (MM) TODO: report this error? usually means some sort of uncaught circular structure
227226 }
228- } catch ( e ) {
229- // (MM) TODO: report this error? usually means some sort of uncaught circular structure
230- }
231- } ) ;
232- }
227+ } ) ;
228+ }
233229
234- if ( targetPath ) {
235- resolved . result = get ( this . _source , targetPath ) ;
230+ if ( targetPath ) {
231+ resolved . result = get ( this . _source , targetPath ) ;
232+ } else {
233+ resolved . result = this . _source ;
234+ }
236235 } else {
237236 resolved . result = this . _source ;
238237 }
@@ -246,7 +245,7 @@ export class ResolveRunner implements Types.IResolveRunner {
246245 result : resolved . result ,
247246 targetAuthority : ref ,
248247 parentAuthority : this . baseUri ,
249- parentPath : targetPath ,
248+ parentPath : opts ? opts . parentPath || [ ] : [ ] ,
250249 fragment : ref . fragment ( ) ,
251250 } ) ;
252251
@@ -442,7 +441,7 @@ export class ResolveRunner implements Types.IResolveRunner {
442441 // only resolve the uri result if we were able to look it up and create the resolver
443442 // @ts -ignore
444443 if ( uriResolver ) {
445- lookupResult . resolved = await uriResolver . resolve ( Utils . uriToJSONPointer ( ref ) ) ;
444+ lookupResult . resolved = await uriResolver . resolve ( Utils . uriToJSONPointer ( ref ) , { parentPath } ) ;
446445
447446 // if pointer resolution failed, revert to the original value (which will be a $ref most of the time)
448447 if ( lookupResult . resolved . errors . length ) {
0 commit comments