diff --git a/src/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js b/src/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js index 74018cab3..c2e1bf1ef 100644 --- a/src/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +++ b/src/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js @@ -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; diff --git a/test/resolver/strategies/openapi-3-1-apidom/index.js b/test/resolver/strategies/openapi-3-1-apidom/index.js index 8085546c7..65d7fa6d6 100644 --- a/test/resolver/strategies/openapi-3-1-apidom/index.js +++ b/test/resolver/strategies/openapi-3-1-apidom/index.js @@ -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', () => {