Same-document $refs in OpenAPI 3.1 definitions fail to dereference when the base URI has a non-http(s) scheme. Every $ref throws Could not resolve reference: Evaluation failed on URI: "<baseDoc>#/components/...".
The dereference visitor evaluates a $ref as a JSON Schema URI first, and that evaluation throws EvaluationJsonSchemaUriError for plain pointer refs under any base. The recovery in the catch block (JSON Pointer / $anchor evaluation) is gated on isURL, which is false when no registered resolver can read the base scheme, so non-http(s) bases never reach it. A same-document reference doesn't need a resolver at all, the document is already in the ReferenceSet. This change allows the recovery for same-document references regardless of the base scheme.
References to other documents with unresolvable schemes keep the current behavior, the $ref-urn-unresolvable fixtures pass unchanged.
Motivation and Context
This breaks swagger-ui when embedded in runtimes that are not served over http(s). Electron loads the renderer over file://, swagger-ui derives baseDoc from document.baseURI, and every OpenAPI 3.1 definition with internal $refs fails to render. OpenAPI 3.0 is unaffected since it resolves through a different strategy.
Added a regression test in test/resolver/strategies/openapi-3-1-apidom: resolving a 3.1 petstore with baseDoc: 'file:///app/index.html' fails on main and passes with this change.
npm run test:unit passes. The only failures are in test/execute/openapi-3-2.js, which fail identically on a clean main checkout.
Also verified in the originating environment, an Electron app rendering OpenAPI 3.1 definitions through swagger-ui-react over file://.
Screenshots (if appropriate):
Types of changes
No code changes (changes to documentation, CI, metadata, etc)
Dependency changes (any modification to dependencies in package.json)
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Same-document $refs in OpenAPI 3.1 definitions fail to dereference when the base URI has a non-http(s) scheme. Every $ref throws Could not resolve reference: Evaluation failed on URI: "<baseDoc>#/components/...".
The dereference visitor evaluates a $ref as a JSON Schema URI first, and that evaluation throws EvaluationJsonSchemaUriError for plain pointer refs under any base. The recovery in the catch block (JSON Pointer / $anchor evaluation) is gated on isURL, which is false when no registered resolver can read the base scheme, so non-http(s) bases never reach it. A same-document reference doesn't need a resolver at all, the document is already in the ReferenceSet. This change allows the recovery for same-document references regardless of the base scheme.
References to other documents with unresolvable schemes keep the current behavior, the $ref-urn-unresolvable fixtures pass unchanged.
Motivation and Context
This breaks swagger-ui when embedded in runtimes that are not served over http(s). Electron loads the renderer over file://, swagger-ui derives baseDoc from document.baseURI, and every OpenAPI 3.1 definition with internal $refs fails to render. OpenAPI 3.0 is unaffected since it resolves through a different strategy.
Related downstream reports: swagger-api/swagger-ui#9922, swagger-api/swagger-ui#10599.
How Has This Been Tested?
Added a regression test in test/resolver/strategies/openapi-3-1-apidom: resolving a 3.1 petstore with baseDoc: 'file:///app/index.html' fails on main and passes with this change.
npm run test:unit passes. The only failures are in test/execute/openapi-3-2.js, which fail identically on a clean main checkout.
Also verified in the originating environment, an Electron app rendering OpenAPI 3.1 definitions through swagger-ui-react over file://.
Screenshots (if appropriate):
Types of changes
Checklist: