@@ -26,9 +26,6 @@ import {
26
26
OperationElement ,
27
27
PathItemElement ,
28
28
isOperationElement ,
29
- isReferenceElementExternal ,
30
- isPathItemElementExternal ,
31
- isLinkElementExternal ,
32
29
} from '@swagger-api/apidom-ns-openapi-3-0' ;
33
30
34
31
import { Reference as IReference } from '../../../types' ;
@@ -133,16 +130,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
133
130
return false ;
134
131
}
135
132
136
- // ignore resolving external Reference Objects
137
- if ( ! this . options . resolve . external && isReferenceElementExternal ( referencingElement ) ) {
138
- // skip traversing this schema but traverse all it's child schemas
139
- return undefined ;
140
- }
141
-
142
133
const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
143
134
const { uri : retrievalURI } = reference ;
144
135
const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
145
136
137
+ // ignore resolving external Reference Objects
138
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
139
+ // skip traversing this reference element but traverse all it's child elements
140
+ return undefined ;
141
+ }
142
+
146
143
this . indirections . push ( referencingElement ) ;
147
144
148
145
const jsonPointer = uriToPointer ( $refBaseURI ) ;
@@ -256,15 +253,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
256
253
return false ;
257
254
}
258
255
259
- // ignore resolving external Path Item Elements
260
- if ( ! this . options . resolve . external && isPathItemElementExternal ( referencingElement ) ) {
261
- return undefined ;
262
- }
263
-
264
256
const reference = await this . toReference ( toValue ( referencingElement . $ref ) ) ;
265
257
const retrievalURI = reference . uri ;
266
258
const $refBaseURI = url . resolve ( retrievalURI , toValue ( referencingElement . $ref ) ) ;
267
259
260
+ // ignore resolving external Path Item Objects
261
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== retrievalURI ) {
262
+ // skip traversing this Path Item element but traverse all it's child elements
263
+ return undefined ;
264
+ }
265
+
268
266
this . indirections . push ( referencingElement ) ;
269
267
270
268
const jsonPointer = uriToPointer ( $refBaseURI ) ;
@@ -367,11 +365,6 @@ const OpenApi3_0DereferenceVisitor = stampit({
367
365
return undefined ;
368
366
}
369
367
370
- // ignore resolving external Path Item Elements
371
- if ( ! this . options . resolve . external && isLinkElementExternal ( linkElement ) ) {
372
- return undefined ;
373
- }
374
-
375
368
// operationRef and operationId fields are mutually exclusive
376
369
if ( isStringElement ( linkElement . operationRef ) && isStringElement ( linkElement . operationId ) ) {
377
370
throw new ApiDOMError (
@@ -385,6 +378,13 @@ const OpenApi3_0DereferenceVisitor = stampit({
385
378
// possibly non-semantic referenced element
386
379
const jsonPointer = uriToPointer ( toValue ( linkElement . operationRef ) ) ;
387
380
const reference = await this . toReference ( toValue ( linkElement . operationRef ) ) ;
381
+
382
+ // ignore resolving external Operation Object reference
383
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== reference . uri ) {
384
+ // skip traversing this Link element but traverse all it's child elements
385
+ return undefined ;
386
+ }
387
+
388
388
operationElement = evaluate ( jsonPointer , reference . value . result ) ;
389
389
// applying semantics to a referenced element
390
390
if ( isPrimitiveElement ( operationElement ) ) {
@@ -440,11 +440,6 @@ const OpenApi3_0DereferenceVisitor = stampit({
440
440
return false ;
441
441
}
442
442
443
- // ignore resolving ExampleElement externalValue
444
- if ( ! this . options . resolve . external && isStringElement ( exampleElement . externalValue ) ) {
445
- return undefined ;
446
- }
447
-
448
443
// value and externalValue fields are mutually exclusive
449
444
if ( exampleElement . hasKey ( 'value' ) && isStringElement ( exampleElement . externalValue ) ) {
450
445
throw new ApiDOMError (
@@ -454,6 +449,12 @@ const OpenApi3_0DereferenceVisitor = stampit({
454
449
455
450
const reference = await this . toReference ( toValue ( exampleElement . externalValue ) ) ;
456
451
452
+ // ignore resolving external Example Objects
453
+ if ( ! this . options . resolve . external && url . stripHash ( this . reference . uri ) !== reference . uri ) {
454
+ // skip traversing this Example element but traverse all it's child elements
455
+ return undefined ;
456
+ }
457
+
457
458
// shallow clone of the referenced element
458
459
const valueElement = cloneShallow ( reference . value . result ) ;
459
460
// annotate operation element with info about origin
0 commit comments