Skip to content

Commit

Permalink
feat(reference): add support for skipping internal references in Open…
Browse files Browse the repository at this point in the history
…API 3.0.x dereference strategy (#3904)

Refs #3451
  • Loading branch information
char0n committed Mar 7, 2024
1 parent dc787bf commit 4da622a
Showing 1 changed file with 34 additions and 6 deletions.
Expand Up @@ -143,11 +143,18 @@ const OpenApi3_0DereferenceVisitor = stampit({
}

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

// ignore resolving internal Reference Objects
if (!this.options.resolve.internal && isInternalReference) {
// skip traversing this reference element
return false;
}
// ignore resolving external Reference Objects
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
// skip traversing this reference element but traverse all it's child elements
return undefined;
if (!this.options.resolve.external && isExternalReference) {
// skip traversing this reference element
return false;
}

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

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

// ignore resolving internal Path Item Objects
if (!this.options.resolve.internal && isInternalReference) {
// skip traversing this Path Item element but traverse all it's child elements
return undefined;
}
// ignore resolving external Path Item Objects
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
if (!this.options.resolve.external && isExternalReference) {
// skip traversing this Path Item element but traverse all it's child elements
return undefined;
}
Expand Down Expand Up @@ -406,9 +420,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
// possibly non-semantic referenced element
const jsonPointer = uriToPointer(toValue(linkElement.operationRef));
const retrievalURI = this.toBaseURI(toValue(linkElement.operationRef));
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
const isExternalReference = !isInternalReference;

// ignore resolving internal Operation Object reference
if (!this.options.resolve.internal && isInternalReference) {
// skip traversing this Link element but traverse all it's child elements
return undefined;
}
// ignore resolving external Operation Object reference
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
if (!this.options.resolve.external && isExternalReference) {
// skip traversing this Link element but traverse all it's child elements
return undefined;
}
Expand Down Expand Up @@ -485,9 +506,16 @@ const OpenApi3_0DereferenceVisitor = stampit({
}

const retrievalURI = this.toBaseURI(toValue(exampleElement.externalValue));
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
const isExternalReference = !isInternalReference;

// ignore resolving external Example Objects
if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) {
if (!this.options.resolve.internal && isInternalReference) {
// skip traversing this Example element but traverse all it's child elements
return undefined;
}
// ignore resolving external Example Objects
if (!this.options.resolve.external && isExternalReference) {
// skip traversing this Example element but traverse all it's child elements
return undefined;
}
Expand Down

0 comments on commit 4da622a

Please sign in to comment.