diff --git a/packages/apidom-ns-asyncapi-2/src/index.ts b/packages/apidom-ns-asyncapi-2/src/index.ts index f91e9bde66..a14705eebd 100644 --- a/packages/apidom-ns-asyncapi-2/src/index.ts +++ b/packages/apidom-ns-asyncapi-2/src/index.ts @@ -23,7 +23,6 @@ export { isAsyncApiVersionElement, isChannelBindingsElement, isChannelItemElement, - isChannelItemElementExternal, isChannelsElement, isComponentsElement, isContactElement, @@ -34,7 +33,6 @@ export { isParameterElement, isParametersElement, isReferenceElement, - isReferenceElementExternal, isSchemaElement, isBooleanJsonSchemaElement, isSecurityRequirementElement, diff --git a/packages/apidom-ns-asyncapi-2/src/predicates.ts b/packages/apidom-ns-asyncapi-2/src/predicates.ts index a1a126f2de..05b1c187c9 100644 --- a/packages/apidom-ns-asyncapi-2/src/predicates.ts +++ b/packages/apidom-ns-asyncapi-2/src/predicates.ts @@ -1,10 +1,4 @@ -import { - BooleanElement, - createPredicate, - isBooleanElement, - isStringElement, - toValue, -} from '@swagger-api/apidom-core'; +import { BooleanElement, createPredicate, isBooleanElement } from '@swagger-api/apidom-core'; import type { ElementPredicate } from '@swagger-api/apidom-core'; import AsyncApi2Element from './elements/AsyncApi2'; @@ -69,21 +63,6 @@ export const isChannelItemElement = createPredicate( }, ); -export const isChannelItemElementExternal: ElementPredicate = ( - element: unknown, -): element is ChannelItemElement => { - if (!isChannelItemElement(element)) { - return false; - } - if (!isStringElement(element.$ref)) { - return false; - } - - const value = toValue(element.$ref); - - return typeof value === 'string' && value.length > 0 && !value.startsWith('#'); -}; - export const isChannelsElement = createPredicate( ({ hasBasicElementProps, isElementType, primitiveEq }) => { return (element: unknown): element is ChannelsElement => @@ -184,18 +163,6 @@ export const isReferenceElement = createPredicate( }, ); -export const isReferenceElementExternal: ElementPredicate = ( - element: unknown, -): element is ReferenceElement => { - if (!isReferenceElement(element)) { - return false; - } - - const value = toValue(element.$ref); - - return typeof value === 'string' && value.length > 0 && !value.startsWith('#'); -}; - export const isSchemaElement = createPredicate( ({ hasBasicElementProps, isElementType, primitiveEq }) => { return (element: unknown): element is SchemaElement => diff --git a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts index 2da53419fa..d8e1a83ba3 100644 --- a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts @@ -17,8 +17,6 @@ import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { ChannelItemElement, getNodeType, - isChannelItemElementExternal, - isReferenceElementExternal, isReferenceLikeElement, isBooleanJsonSchemaElement, keyMap, @@ -126,16 +124,16 @@ const AsyncApi2DereferenceVisitor = stampit({ return false; } - // ignore resolving external Reference Objects - if (!this.options.resolve.external && isReferenceElementExternal(referencingElement)) { - // skip traversing this schema but traverse all it's child schemas - return undefined; - } - const reference = await this.toReference(toValue(referencingElement.$ref)); const { uri: retrievalURI } = reference; const $refBaseURI = url.resolve(retrievalURI, toValue(referencingElement.$ref)); + // 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; + } + this.indirections.push(referencingElement); const jsonPointer = uriToPointer($refBaseURI); @@ -266,15 +264,16 @@ const AsyncApi2DereferenceVisitor = stampit({ return false; } - // ignore resolving external ChannelItem Elements - if (!this.options.resolve.external && isChannelItemElementExternal(referencingElement)) { - return undefined; - } - const reference = await this.toReference(toValue(referencingElement.$ref)); const retrievalURI = reference.uri; const $refBaseURI = url.resolve(retrievalURI, toValue(referencingElement.$ref)); + // ignore resolving external Channel Item Objects + if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== retrievalURI) { + // skip traversing this channel item but traverse all it's child elements + return undefined; + } + this.indirections.push(referencingElement); const jsonPointer = uriToPointer($refBaseURI); diff --git a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts index 0b22fbcd81..52b958f79b 100644 --- a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts +++ b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts @@ -12,8 +12,6 @@ import { keyMap, ReferenceElement, ChannelItemElement, - isReferenceElementExternal, - isChannelItemElementExternal, } from '@swagger-api/apidom-ns-asyncapi-2'; import { Reference as IReference } from '../../../types'; @@ -82,14 +80,14 @@ const AsyncApi2ResolveVisitor = stampit({ }, ReferenceElement(referenceElement: ReferenceElement) { - // ignore resolving external Reference Objects - if (!this.options.resolve.external && isReferenceElementExternal(referenceElement)) { - return false; - } - const uri = toValue(referenceElement.$ref); const baseURI = this.toBaseURI(uri); + // // ignore resolving external Reference Objects + if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== baseURI) { + return false; + } + if (!has(baseURI, this.crawlingMap)) { this.crawlingMap[baseURI] = this.toReference(uri); } @@ -104,14 +102,14 @@ const AsyncApi2ResolveVisitor = stampit({ return undefined; } - // ignore resolving external Reference Objects - if (!this.options.resolve.external && isChannelItemElementExternal(channelItemElement)) { - return undefined; - } - const uri = toValue(channelItemElement.$ref); const baseURI = this.toBaseURI(uri); + // ignore resolving external Channel Item Objects + if (!this.options.resolve.external && url.stripHash(this.reference.uri) !== baseURI) { + return undefined; + } + if (!has(baseURI, this.crawlingMap)) { this.crawlingMap[baseURI] = this.toReference(uri); }