@@ -71,6 +71,10 @@ const OpenApi3_0DereferenceVisitor = stampit({
71
71
this . ancestors = new AncestorLineage ( ...ancestors ) ;
72
72
} ,
73
73
methods : {
74
+ toBaseURI ( uri : string ) : string {
75
+ return url . resolve ( this . reference . uri , url . sanitize ( url . stripHash ( uri ) ) ) ;
76
+ } ,
77
+
74
78
async toReference ( uri : string ) : Promise < IReference > {
75
79
// detect maximum depth of resolution
76
80
if ( this . reference . depth >= this . options . resolve . maxDepth ) {
@@ -79,8 +83,7 @@ const OpenApi3_0DereferenceVisitor = stampit({
79
83
) ;
80
84
}
81
85
82
- const baseURI = url . resolve ( this . reference . uri , url . sanitize ( url . stripHash ( uri ) ) ) ;
83
-
86
+ const baseURI = this . toBaseURI ( uri ) ;
84
87
const { refSet } = this . reference ;
85
88
86
89
// we've already processed this Reference in past
@@ -130,16 +133,17 @@ const OpenApi3_0DereferenceVisitor = stampit({
130
133
return false ;
131
134
}
132
135
133
- const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
134
- const { uri : retrievalURI } = reference ;
135
- const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
136
+ const retrievalURI = this . toBaseURI ( toValue ( referencingElement . $ref ) ) ;
136
137
137
138
// ignore resolving external Reference Objects
138
139
if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
139
140
// skip traversing this reference element but traverse all it's child elements
140
141
return undefined ;
141
142
}
142
143
144
+ const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
145
+ const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
146
+
143
147
this . indirections . push ( referencingElement ) ;
144
148
145
149
const jsonPointer = uriToPointer ( $refBaseURI ) ;
@@ -253,16 +257,17 @@ const OpenApi3_0DereferenceVisitor = stampit({
253
257
return false ;
254
258
}
255
259
256
- const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
257
- const retrievalURI = reference . uri ;
258
- const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
260
+ const retrievalURI = this . toBaseURI ( toValue ( referencingElement . $ref ) ) ;
259
261
260
262
// ignore resolving external Path Item Objects
261
263
if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
262
264
// skip traversing this Path Item element but traverse all it's child elements
263
265
return undefined ;
264
266
}
265
267
268
+ const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
269
+ const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
270
+
266
271
this . indirections . push ( referencingElement ) ;
267
272
268
273
const jsonPointer = uriToPointer ( $refBaseURI ) ;
@@ -377,14 +382,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
377
382
if ( isStringElement ( linkElement . operationRef ) ) {
378
383
// possibly non-semantic referenced element
379
384
const jsonPointer = uriToPointer ( toValue ( linkElement . operationRef ) ) ;
380
- const reference = await this . toReference ( toValue ( linkElement . operationRef ) ) ;
385
+ const retrievalURI = this . toBaseURI ( toValue ( linkElement . operationRef ) ) ;
381
386
382
387
// ignore resolving external Operation Object reference
383
- if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== reference . uri ) {
388
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
384
389
// skip traversing this Link element but traverse all it's child elements
385
390
return undefined ;
386
391
}
387
392
393
+ const reference = await this . toReference ( toValue ( linkElement . operationRef ) ) ;
394
+
388
395
operationElement = evaluate ( jsonPointer , reference . value . result ) ;
389
396
// applying semantics to a referenced element
390
397
if ( isPrimitiveElement ( operationElement ) ) {
@@ -447,14 +454,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
447
454
) ;
448
455
}
449
456
450
- const reference = await this . toReference ( toValue ( exampleElement . externalValue ) ) ;
457
+ const retrievalURI = this . toBaseURI ( toValue ( exampleElement . externalValue ) ) ;
451
458
452
459
// ignore resolving external Example Objects
453
- if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== reference . uri ) {
460
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
454
461
// skip traversing this Example element but traverse all it's child elements
455
462
return undefined ;
456
463
}
457
464
465
+ const reference = await this . toReference ( toValue ( exampleElement . externalValue ) ) ;
466
+
458
467
// shallow clone of the referenced element
459
468
const valueElement = cloneShallow ( reference . value . result ) ;
460
469
// annotate operation element with info about origin
0 commit comments