Swagger UI server URL resolution failure behind reverse proxies
0 reputation · 07 Jan 2023, 14:15 UTC
Environment-Specific Base URL Resolution
The OpenAPI specification utilizes a servers array to define the base URLs for API requests. While relative paths often resolve correctly in local development environments, the behavior changes when the Swagger UI is deployed to production behind a reverse proxy or API Gateway.
When the UI is hosted on a different domain or subdirectory than the backend API, the browser-side resolution of relative paths may result in incorrect request routing or CORS violations. There is uncertainty regarding how different versions of Swagger UI handle the prepending of base paths when the servers object is dynamically populated at runtime versus being hardcoded in the specification file.
What is the documented behavior for resolving relative server paths when the UI is served from a separate origin than the API? How does the servers configuration interact with reverse proxy headers to ensure consistent request routing across multiple environments?