Skip to content

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

Open
rusackas wants to merge 2 commits into
masterfrom
adopt/swagger-application-root
Open

fix(swagger): support URL prefix via APPLICATION_ROOT in OpenAPI and Swagger UI#40908
rusackas wants to merge 2 commits into
masterfrom
adopt/swagger-application-root

Conversation

@rusackas

@rusackas rusackas commented Jun 9, 2026

Copy link
Copy Markdown
Member

SUMMARY

Adopts #34407 by @rsbhatti — thank you for the original work! 🙏

When Superset is deployed behind a reverse proxy with a URL prefix (APPLICATION_ROOT / SUPERSET_APP_ROOT), the Swagger UI breaks because it can't generate the OpenAPI server URLs or locate the spec under the prefix (#33304). This adds an APPLICATION_ROOT-aware OpenAPI endpoint (/api/<version>/_openapi) and Swagger view, gated by a new config flag:

FAB_API_SWAGGER_UI_SUPERSET_APP_ROOT = False  # default: standard FAB Swagger UI

When enabled, the spec's servers URL and the Swagger UI's openapi_uri are resolved through APPLICATION_ROOT, so the docs work under a prefix. Default behavior is unchanged.

What changed vs. the original PR

I adopted #34407 and applied a few cleanups so it's merge-ready:

  • Kept the existing FAB_API_SWAGGER_UI = True flag (the original inadvertently removed it).
  • Dropped an unrelated AUTH_ROLE_PUBLIC = 'Public' change the original accidentally included.
  • Added ASF license headers and type hints to the new superset/openapi module.
  • Fixed the SupsersetSwaggerViewSupersetSwaggerView class-name typo.
  • Added a unit test for the schema-name resolver.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend; gated behind a default-off config flag.

TESTING INSTRUCTIONS

pytest tests/unit_tests/openapi/test_manager.py

Manual: set APPLICATION_ROOT = "/myprefix" and FAB_API_SWAGGER_UI_SUPERSET_APP_ROOT = True, then load the Swagger UI under the prefix and confirm the spec loads and server URLs include the prefix.

ADDITIONAL INFORMATION

Closes #34407

🤖 Generated with Claude Code

…Swagger UI

Adopts #34407 by @rsbhatti. Serves the OpenAPI spec and an APPLICATION_ROOT-aware
Swagger UI for Superset deployments behind a URL prefix (reverse proxy), gated by
a new FAB_API_SWAGGER_UI_SUPERSET_APP_ROOT flag (default False).

Adoption cleanups over the original:
- keep the existing FAB_API_SWAGGER_UI flag (the original removed it)
- drop an unrelated AUTH_ROLE_PUBLIC change that the original accidentally included
- add ASF license headers and type hints to the new openapi module
- fix the SupsersetSwaggerView -> SupersetSwaggerView class-name typo
- add a unit test for the schema-name resolver

Closes #34407
Fixes #33304

Co-authored-by: rsbhatti <rajvindrasinghbhatti12@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #65fc76

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset/openapi/manager.py - 1
    • Inconsistent authorization decorators · Line 47-49
      Authorization inconsistency detected: SupersetOpenApi uses @Protect()/@safe with allow_browser_login=True (lines 47-49) while SupersetSwaggerView uses @has_access (line 108). These different authorization patterns may cause confusion about expected access requirements.
  • superset/initialization/__init__.py - 1
    • SEMANTIC_DEAD_CODE: Unused import on disabled feature path · Line 67-67
      Import on line 67 is unconditional but only used conditionally at lines 467-469. When `FAB_API_SWAGGER_UI_SUPERSET_APP_ROOT` is False (the default), `SupersetOpenApi` and `SupersetSwaggerView` are imported but never used, causing `apispec` and related dependencies to load unnecessarily at startup. This is semantic dead code with maintenance and performance impact.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/openapi/manager.py - 3
Review Details
  • Files reviewed - 6 · Commit Range: b53a6e0..b53a6e0
    • superset/config.py
    • superset/initialization/__init__.py
    • superset/openapi/__init__.py
    • superset/openapi/manager.py
    • tests/unit_tests/openapi/__init__.py
    • tests/unit_tests/openapi/test_manager.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added api Related to the REST API change:backend Requires changing the backend infra:webserver Infra setup and configuration related to webserver labels Jun 9, 2026
@github-actions github-actions Bot removed the api Related to the REST API label Jun 9, 2026
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.18033% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.13%. Comparing base (0133ebc) to head (1d81438).
⚠️ Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
superset/openapi/manager.py 50.94% 26 Missing ⚠️
superset/initialization/__init__.py 16.66% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40908      +/-   ##
==========================================
- Coverage   64.13%   64.13%   -0.01%     
==========================================
  Files        2653     2655       +2     
  Lines      143606   143685      +79     
  Branches    33132    33143      +11     
==========================================
+ Hits        92105    92149      +44     
- Misses      49888    49919      +31     
- Partials     1613     1617       +4     
Flag Coverage Δ
hive 39.51% <49.18%> (+<0.01%) ⬆️
mysql 58.24% <49.18%> (+<0.01%) ⬆️
postgres 58.31% <49.18%> (-0.01%) ⬇️
presto 41.10% <49.18%> (+<0.01%) ⬆️
python 59.78% <49.18%> (-0.01%) ⬇️
sqlite 57.93% <49.18%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread superset/openapi/manager.py
Comment thread superset/openapi/manager.py Outdated
Comment thread superset/initialization/__init__.py Outdated
…malize app root

Address review feedback:
- Gate the APPLICATION_ROOT-aware Swagger/OpenAPI registration on
  FAB_API_SWAGGER_UI so the global Swagger disable still takes precedence.
- Suppress FAB's default OpenAPI/Swagger views (FAB_ADD_OPENAPI_VIEWS) when
  the prefix-aware variant is active, so the two don't register duplicate URL
  rules for /api/<version>/_openapi and /swagger/<version>.
- Normalize APPLICATION_ROOT (treat '/' as empty, strip trailing slash) so the
  Swagger UI spec URL is not built as a protocol-relative '//api/...' URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 1d81438
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a285273a93d2b0008a96782
😎 Deploy Preview https://deploy-preview-40908--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6b7c0f

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: b53a6e0..1d81438
    • superset/initialization/__init__.py
    • superset/openapi/manager.py
    • tests/unit_tests/openapi/test_manager.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend infra:webserver Infra setup and configuration related to webserver size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to access swagger API after enabling prefix routing

2 participants