@@ -339,7 +339,7 @@ async function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilena
339
339
/**
340
340
* Converts contents received from remoteRefResolver into stringified JSON
341
341
* @param {string | object } content - contents from remoteRefResolver
342
- * @returns Stringified JSON contents
342
+ * @returns { string } Stringified JSON contents
343
343
*/
344
344
function convertToJSONString ( content ) {
345
345
if ( typeof content === 'object' ) {
@@ -351,17 +351,24 @@ async function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilena
351
351
return JSON . stringify ( parsedFile . oasObject ) ;
352
352
}
353
353
354
- let contentFromRemote = await remoteRefResolver ( property . $ref ) ,
355
- nodeTemp = {
356
- fileName : tempRef ,
357
- path : tempRef ,
358
- content : convertToJSONString ( contentFromRemote )
359
- } ;
354
+ try {
355
+ let contentFromRemote = await remoteRefResolver ( property . $ref ) ,
356
+ nodeTemp = {
357
+ fileName : tempRef ,
358
+ path : tempRef ,
359
+ content : convertToJSONString ( contentFromRemote )
360
+ } ;
360
361
361
- remoteRefContentMap . set ( tempRef , contentFromRemote ) ;
362
+ remoteRefContentMap . set ( tempRef , contentFromRemote ) ;
362
363
363
- allData . push ( nodeTemp ) ;
364
- resolveInner ( ) ;
364
+ allData . push ( nodeTemp ) ;
365
+ }
366
+ catch ( err ) {
367
+ // swallow the err
368
+ }
369
+ finally {
370
+ resolveInner ( ) ;
371
+ }
365
372
} )
366
373
) ;
367
374
@@ -447,84 +454,91 @@ async function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilena
447
454
}
448
455
449
456
const hasRemoteReferenceTypeKey = Object . keys ( property )
450
- . find (
451
- ( key ) => {
452
- const isExternal = isExtURLRef ( property , key ) ,
453
-
454
- // Only process URL refs if remoteRefResolver is provided and a valid function
455
- isReferenciable = isExternal && _ . isFunction ( remoteRefResolver ) ;
457
+ . find (
458
+ ( key ) => {
459
+ const isExternal = isExtURLRef ( property , key ) ,
456
460
457
- return isReferenciable ;
458
- }
459
- ) ;
461
+ // Only process URL refs if remoteRefResolver is provided and a valid function
462
+ isReferenciable = isExternal && _ . isFunction ( remoteRefResolver ) ;
460
463
461
- if ( hasRemoteReferenceTypeKey ) {
462
- const tempRef = calculatePath ( parentFilename , property . $ref ) ,
463
- nodeTrace = handleLocalCollisions (
464
- getTraceFromParentKeyInComponents ( this , tempRef , mainKeys , version , commonPathFromData ) ,
465
- rootMainKeys
466
- ) ,
467
- componentKey = nodeTrace [ nodeTrace . length - 1 ] ,
468
- referenceInDocument = getJsonPointerRelationToRoot (
469
- tempRef ,
470
- nodeTrace ,
471
- version
464
+ return isReferenciable ;
465
+ }
472
466
) ,
473
- traceToParent = [ ...this . parents . map ( ( item ) => {
474
- return item . key ;
475
- } ) . filter ( ( item ) => {
476
- return item !== undefined ;
477
- } ) , this . key ] ;
467
+ handleRemoteURLReference = ( ) => {
468
+ const tempRef = calculatePath ( parentFilename , property . $ref ) ;
478
469
479
- let newValue = Object . assign ( { } , this . node ) ,
480
- [ , local ] = tempRef . split ( localPointer ) ,
481
- nodeFromData ,
482
- refHasContent = false ,
483
- parseResult ,
484
- newRefInDoc ,
485
- inline ,
486
- contentFromRemote = remoteRefContentMap . get ( tempRef ) ,
487
- nodeTemp = {
488
- fileName : tempRef ,
489
- path : tempRef ,
490
- content : contentFromRemote
491
- } ;
470
+ if ( remoteRefContentMap . get ( tempRef ) === undefined ) {
471
+ return ;
472
+ }
492
473
493
- nodeFromData = nodeTemp ;
474
+ let nodeTrace = handleLocalCollisions (
475
+ getTraceFromParentKeyInComponents ( this , tempRef , mainKeys , version , commonPathFromData ) ,
476
+ rootMainKeys
477
+ ) ,
478
+ componentKey = nodeTrace [ nodeTrace . length - 1 ] ,
479
+ referenceInDocument = getJsonPointerRelationToRoot (
480
+ tempRef ,
481
+ nodeTrace ,
482
+ version
483
+ ) ,
484
+ traceToParent = [ ...this . parents . map ( ( item ) => {
485
+ return item . key ;
486
+ } ) . filter ( ( item ) => {
487
+ return item !== undefined ;
488
+ } ) , this . key ] ,
489
+ newValue = Object . assign ( { } , this . node ) ,
490
+ [ , local ] = tempRef . split ( localPointer ) ,
491
+ nodeFromData ,
492
+ refHasContent = false ,
493
+ parseResult ,
494
+ newRefInDoc ,
495
+ inline ,
496
+ contentFromRemote = remoteRefContentMap . get ( tempRef ) ,
497
+ nodeTemp = {
498
+ fileName : tempRef ,
499
+ path : tempRef ,
500
+ content : contentFromRemote
501
+ } ;
502
+
503
+ nodeFromData = nodeTemp ;
504
+
505
+ if ( nodeFromData && nodeFromData . content ) {
506
+ parseResult = parseFile ( JSON . stringify ( nodeFromData . content ) ) ;
507
+ if ( parseResult . result ) {
508
+ newValue . $ref = referenceInDocument ;
509
+ refHasContent = true ;
510
+ nodeFromData . parsed = parseResult ;
511
+ }
512
+ }
513
+ this . update ( { $ref : tempRef } ) ;
494
514
495
- if ( nodeFromData && nodeFromData . content ) {
496
- parseResult = parseFile ( JSON . stringify ( nodeFromData . content ) ) ;
497
- if ( parseResult . result ) {
498
- newValue . $ref = referenceInDocument ;
499
- refHasContent = true ;
500
- nodeFromData . parsed = parseResult ;
515
+ if ( nodeTrace . length === 0 ) {
516
+ inline = true ;
501
517
}
502
- }
503
- this . update ( { $ref : tempRef } ) ;
504
518
505
- if ( nodeTrace . length === 0 ) {
506
- inline = true ;
507
- }
519
+ if ( _ . isNil ( globalReferences [ tempRef ] ) ) {
520
+ nodeReferenceDirectory [ tempRef ] = {
521
+ local,
522
+ keyInComponents : nodeTrace ,
523
+ node : newValue ,
524
+ reference : inline ? newRefInDoc : referenceInDocument ,
525
+ traceToParent,
526
+ parentNodeKey : parentFilename ,
527
+ mainKeyInTrace : nodeTrace [ nodeTrace . length - 1 ] ,
528
+ refHasContent,
529
+ inline
530
+ } ;
531
+ }
508
532
509
- if ( _ . isNil ( globalReferences [ tempRef ] ) ) {
510
- nodeReferenceDirectory [ tempRef ] = {
511
- local,
512
- keyInComponents : nodeTrace ,
513
- node : newValue ,
514
- reference : inline ? newRefInDoc : referenceInDocument ,
515
- traceToParent,
516
- parentNodeKey : parentFilename ,
517
- mainKeyInTrace : nodeTrace [ nodeTrace . length - 1 ] ,
518
- refHasContent,
519
- inline
520
- } ;
521
- }
533
+ mainKeys [ componentKey ] = tempRef ;
522
534
523
- mainKeys [ componentKey ] = tempRef ;
535
+ if ( ! added ( property . $ref , referencesInNode ) ) {
536
+ referencesInNode . push ( { path : pathSolver ( property ) , keyInComponents : nodeTrace , newValue : this . node } ) ;
537
+ }
538
+ } ;
524
539
525
- if ( ! added ( property . $ref , referencesInNode ) ) {
526
- referencesInNode . push ( { path : pathSolver ( property ) , keyInComponents : nodeTrace , newValue : this . node } ) ;
527
- }
540
+ if ( hasRemoteReferenceTypeKey ) {
541
+ handleRemoteURLReference ( ) ;
528
542
}
529
543
}
530
544
} ) ;
0 commit comments