Skip to content

Commit 4da622a

Browse files
authored
feat(reference): add support for skipping internal references in OpenAPI 3.0.x dereference strategy (#3904)
Refs #3451
1 parent dc787bf commit 4da622a

File tree

1 file changed

+34
-6
lines changed
  • packages/apidom-reference/src/dereference/strategies/openapi-3-0

1 file changed

+34
-6
lines changed

packages/apidom-reference/src/dereference/strategies/openapi-3-0/visitor.ts

+34-6
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,18 @@ const OpenApi3_0DereferenceVisitor = stampit({
143143
}
144144

145145
const retrievalURI = this.toBaseURI(toValue(referencingElement.$ref));
146+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
147+
const isExternalReference = !isInternalReference;
146148

149+
// ignore resolving internal Reference Objects
150+
if (!this.options.resolve.internal && isInternalReference) {
151+
// skip traversing this reference element
152+
return false;
153+
}
147154
// ignore resolving external Reference Objects
148-
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
149-
// skip traversing this reference element but traverse all it's child elements
150-
return undefined;
155+
if (!this.options.resolve.external && isExternalReference) {
156+
// skip traversing this reference element
157+
return false;
151158
}
152159

153160
const reference = await this.toReference(toValue(referencingElement.$ref));
@@ -273,9 +280,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
273280
}
274281

275282
const retrievalURI = this.toBaseURI(toValue(referencingElement.$ref));
283+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
284+
const isExternalReference = !isInternalReference;
276285

286+
// ignore resolving internal Path Item Objects
287+
if (!this.options.resolve.internal && isInternalReference) {
288+
// skip traversing this Path Item element but traverse all it's child elements
289+
return undefined;
290+
}
277291
// ignore resolving external Path Item Objects
278-
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
292+
if (!this.options.resolve.external && isExternalReference) {
279293
// skip traversing this Path Item element but traverse all it's child elements
280294
return undefined;
281295
}
@@ -406,9 +420,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
406420
// possibly non-semantic referenced element
407421
const jsonPointer = uriToPointer(toValue(linkElement.operationRef));
408422
const retrievalURI = this.toBaseURI(toValue(linkElement.operationRef));
423+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
424+
const isExternalReference = !isInternalReference;
409425

426+
// ignore resolving internal Operation Object reference
427+
if (!this.options.resolve.internal && isInternalReference) {
428+
// skip traversing this Link element but traverse all it's child elements
429+
return undefined;
430+
}
410431
// ignore resolving external Operation Object reference
411-
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
432+
if (!this.options.resolve.external && isExternalReference) {
412433
// skip traversing this Link element but traverse all it's child elements
413434
return undefined;
414435
}
@@ -485,9 +506,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
485506
}
486507

487508
const retrievalURI = this.toBaseURI(toValue(exampleElement.externalValue));
509+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
510+
const isExternalReference = !isInternalReference;
488511

489512
// ignore resolving external Example Objects
490-
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
513+
if (!this.options.resolve.internal && isInternalReference) {
514+
// skip traversing this Example element but traverse all it's child elements
515+
return undefined;
516+
}
517+
// ignore resolving external Example Objects
518+
if (!this.options.resolve.external && isExternalReference) {
491519
// skip traversing this Example element but traverse all it's child elements
492520
return undefined;
493521
}

0 commit comments

Comments
 (0)