fix(swagger): support URL prefix via APPLICATION_ROOT in OpenAPI and Swagger UI#34407
fix(swagger): support URL prefix via APPLICATION_ROOT in OpenAPI and Swagger UI#34407rsbhatti wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Unsafe Use of Host Header in Server URL Construction ▹ view | 🧠 Incorrect |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/openapi/init.py | ✅ |
| superset/openapi/manager.py | ✅ |
| superset/initialization/init.py | ✅ |
| superset/config.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| servers = current_app.config.get( | ||
| "FAB_OPENAPI_SERVERS", [{"url": request.host_url.rstrip("/")+current_app.config.get("APPLICATION_ROOT","/")}] | ||
| ) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
Hi @rsbhatti 👋 This PR has multiple CI failures (License Check, pre-commit, unit tests, database tests) and has been inactive for about 4 months. Converting to draft until resolved. When you have time, please:
If you're no longer able to work on this, let us know and we can close it or have someone else pick it up. Thanks for your contribution! |
|
Okay, thanks for the update. I’ll look into the failures and work on resolving them. |
63bb56d to
5031569
Compare
|
Thank you for this, @rsbhatti! 🙏 I've adopted it in #40908 (on the origin repo) with you credited as co-author. It keeps your approach and adds a few merge-readiness cleanups — retains the existing |
Description
This PR fixes #33304 by adding support for Superset deployments behind a URL prefix (e.g., when APPLICATION_ROOT or SUPERSET_APP_ROOT is set) in both the OpenAPI specification and the Swagger UI.
Motivation
Currently, when Superset is deployed behind a reverse proxy with a URL prefix, the Swagger UI breaks because it does not correctly generate the OpenAPI server URLs or locate the spec file using the prefix. This makes it impossible to use the Swagger-based API documentation in such environments.
Changes
Introduced a new SupersetOpenApi class to expose OpenAPI specs per version at /api//_openapi, dynamically resolving and registering API views.
Introduced a new SupsersetSwaggerView to render the Swagger UI HTML page with the correct openapi_uri, taking APPLICATION_ROOT into account.
Reused the existing Swagger HTML template (swagger.html), only modifying how it receives the OpenAPI URL.
Provided fallbacks to default behavior for backward compatibility (no prefix set).
Ensured compatibility with both prefixed and non-prefixed deployments.
How to Test
Set APPLICATION_ROOT = "/myprefix"
Visit /myprefix/swagger/v1 and confirm:
Swagger UI loads correctly
OpenAPI spec is loaded from /myprefix/api/v1/_openapi
"Try It Out" works for all endpoints
Related Issues
Fixes: #33304
Fixes #35464