Skip to content

fix(swagger): support URL prefix via APPLICATION_ROOT in OpenAPI and Swagger UI #34407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rsbhatti
Copy link

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

@dosubot dosubot bot added the api Related to the REST API label Jul 30, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Security 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.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines +69 to +71
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to access swagger API after enabling prefix routing
1 participant