diff --git a/apidom/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts b/apidom/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts index 486848fc56..2c4d0142c6 100644 --- a/apidom/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts +++ b/apidom/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts @@ -337,8 +337,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ } // compute baseURI using rules around $id and $ref keywords - const base$idURI = resolveInherited$id(referencingElement); - const baseURI = this.toBaseURI(base$idURI); + const baseURI = resolveInherited$id(this.reference.uri, referencingElement); const file = File({ uri: baseURI }); const isUnknownURI = none((r: IResolver) => r.canRead(file), this.options.resolve.resolvers); const isExternal = this.reference.uri !== baseURI && !isUnknownURI; @@ -352,7 +351,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ } // compute Reference object - const reference = isUnknownURI ? this.reference : await this.toReference(base$idURI); + const reference = isUnknownURI ? this.reference : await this.toReference(baseURI); this.indirections.push(referencingElement); diff --git a/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/util.ts b/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/util.ts index 235eaf119a..59397f0574 100644 --- a/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/util.ts +++ b/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/util.ts @@ -1,4 +1,4 @@ -import { reduceRight } from 'ramda'; +import { reduce } from 'ramda'; import { Element } from 'apidom'; import { SchemaElement } from 'apidom-ns-openapi-3-1'; @@ -8,19 +8,22 @@ import * as url from '../../../util/url'; * Folding of inherited$id list from right to left using * URL resolving mechanism. */ -export const resolveInherited$id = (schemaElement: SchemaElement) => - reduceRight( - ($id: string, acc: string): string => { +export const resolveInherited$id = (baseURI: string, schemaElement: SchemaElement) => { + const inherited$id = schemaElement.meta.get('inherited$id').toValue(); + + return reduce( + (acc: string, $id: string): string => { const uriWithoutHash = url.stripHash($id); const sanitizedURI = url.isFileSystemPath(uriWithoutHash) ? url.fromFileSystemPath(uriWithoutHash) : uriWithoutHash; - return url.resolve(sanitizedURI, acc); + return url.resolve(acc, sanitizedURI); }, - schemaElement.$ref?.toValue(), - schemaElement.meta.get('inherited$id').toValue(), + baseURI, + [...inherited$id, schemaElement.$ref?.toValue()], ); +}; /** * Cached version of SchemaElement.refract. diff --git a/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts b/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts index 85a99ea5aa..fe9680c81b 100644 --- a/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts +++ b/apidom/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts @@ -209,8 +209,7 @@ const OpenApi3_1ResolveVisitor = stampit({ } // compute Reference object using rules around $id and $ref keywords - const base$idURI = resolveInherited$id(schemaElement); - const baseURI = this.toBaseURI(base$idURI); + const baseURI = resolveInherited$id(this.reference.uri, schemaElement); const file = File({ uri: baseURI }); const isUnknownURI = none((r: IResolver) => r.canRead(file), this.options.resolve.resolvers); const isExternal = this.reference.uri !== baseURI && !isUnknownURI; @@ -224,7 +223,7 @@ const OpenApi3_1ResolveVisitor = stampit({ } if (!has(baseURI, this.crawlingMap)) { - this.crawlingMap[baseURI] = isUnknownURI ? this.reference : this.toReference(base$idURI); + this.crawlingMap[baseURI] = isUnknownURI ? this.reference : this.toReference(baseURI); } this.crawledElements.push(schemaElement); @@ -325,7 +324,7 @@ const OpenApi3_1ResolveVisitor = stampit({ async crawlSchemaElement(referencingElement: SchemaElement) { // compute Reference object using rules around $id and $ref keywords - const base$idURI = resolveInherited$id(referencingElement); + const base$idURI = resolveInherited$id(this.reference.uri, referencingElement); const baseURI = this.toBaseURI(base$idURI); const file = File({ uri: baseURI }); const isUnknownURI = none((r: IResolver) => r.canRead(file), this.options.resolve.resolvers);