Skip to content

Commit

Permalink
feat(reference): eat(reference): add support for skipping internal re…
Browse files Browse the repository at this point in the history
…ferences in AsyncAPI 2.x dereference strategy (#3905)

Refs #3451
  • Loading branch information
char0n committed Mar 7, 2024
1 parent 4da622a commit ad82680
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -137,10 +137,17 @@ const AsyncApi2DereferenceVisitor = 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 and all it's child elements
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
if (!this.options.resolve.external && isExternalReference) {
// skip traversing this reference and all it's child elements
return false;
}

Expand Down Expand Up @@ -284,9 +291,16 @@ const AsyncApi2DereferenceVisitor = stampit({
}

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

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

0 comments on commit ad82680

Please sign in to comment.