External $ref base URL configuration for OpenAPI 3.1 in Swagger UI and Springdoc
0 reputation · 30 Mar 2026, 09:08 UTC
0 reputation · 30 Mar 2026, 09:08 UTC
The OpenAPI 3.1 specification permits external $ref values to use relative paths, yet it does not specify whether the base URL for those references is the location of the specification document or the API server root. In current stable tooling, Swagger UI, ReDoc, and OpenAPI Generator typically resolve relative references against the URL from which the specification is served, while some server-side frameworks such as Springdoc may resolve them against the application context path. This divergence becomes a configuration problem when a specification is hosted behind a reverse proxy, served from a CDN, or deployed at a path that differs from its original file structure.
Because tool behavior can vary between releases, teams need a predictable way to declare the intended base path without hard-coding absolute URLs that expose internal infrastructure. The absence of a standardized resolution rule has been noted as an unresolved decision in the specification's issue tracker, leaving implementers to rely on tool-specific behavior or maintenance-heavy workarounds such as absolute references.
Assuming a minimal OpenAPI 3.1 document with a relative $ref to an external schema file, which resolution base should be authoritative when the specification URL and the API context path differ? Do current stable releases of Swagger UI and OpenAPI Generator provide a configuration option to override the default base URL for relative external references? How can a team verify that a chosen strategy remains consistent across documentation rendering and client code generation without duplicating schema definitions?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.