Skip to content
Open
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 @@ -564,7 +564,13 @@ class OpenAPI3_1SwaggerClientDereferenceVisitor extends OpenAPI3_1DereferenceVis
* No SchemaElement($id=URL) was not found, so we're going to try to resolve
* the URL and assume the returned response is a JSON Schema.
*/
if (isURL && error instanceof EvaluationJsonSchemaUriError) {
const isSameDocumentReference =
$refBaseURIStrippedHash === url.stripHash(this.reference.uri);

if (
(isURL || (isUnknownURI && isSameDocumentReference)) &&
error instanceof EvaluationJsonSchemaUriError
) {
if (isAnchor(uriToAnchor($refBaseURI))) {
// we're dealing with JSON Schema $anchor here
isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
Expand Down
16 changes: 16 additions & 0 deletions test/resolver/strategies/openapi-3-1-apidom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ describe('resolve', () => {
expect(resolvedSpec).toMatchSnapshot();
});
});

describe('and baseDoc option has a non-http(s) scheme', () => {
test('should dereference internal $refs', async () => {
const spec = globalThis.loadJsonFile(path.join(fixturePath, 'petstore.json'));
const resolvedSpec = await SwaggerClient.resolve({
spec,
baseDoc: 'file:///app/index.html',
});

expect(resolvedSpec.errors).toEqual([]);
expect(
resolvedSpec.spec.paths['/pets'].get.responses['200'].content['application/json']
.schema
).toMatchObject({ type: 'array' });
});
});
});

describe('and url option is provided', () => {
Expand Down