Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reduceRight } from 'ramda';
import { reduce } from 'ramda';
import { Element } from 'apidom';
import { SchemaElement } from 'apidom-ns-openapi-3-1';

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down