korbit-ai[bot] commented on code in PR #35098:
URL: https://github.com/apache/superset/pull/35098#discussion_r2338258526
##########
superset/views/core.py:
##########
@@ -938,3 +938,25 @@ def welcome(self) -> FlaskResponse:
@deprecated(new_target="/sqllab/history")
def sqllab_history(self) -> FlaskResponse:
return redirect(url_for("SqllabView.history"))
+
+ @has_access
+ @expose("/swagger/v1")
+ def swagger_ui_redirect(self) -> FlaskResponse:
+ """
+ Redirect to Flask-AppBuilder's swagger UI with proper APPLICATION_ROOT
support.
+
+ This fixes the issue where /swagger/v1 doesn't work in subdirectory
deployments
+ by redirecting to Flask-AppBuilder's existing swagger endpoint.
+ """
+ # Check if swagger is enabled
+ if not app.config.get("FAB_API_SWAGGER_UI", False):
+ abort(404, "Swagger UI is disabled")
+
+ # Get the application root
+ app_root = app.config.get("APPLICATION_ROOT", "/").rstrip("/")
+
+ # Flask-AppBuilder's swagger endpoint is typically /api/v1/swagger
+ # Redirect to it with the proper application root prefix
+ fab_swagger_path = f"{app_root}/api/v1/swagger"
Review Comment:
### Potential Double Slash in Swagger Redirect URL <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The swagger redirect path is constructed without validating if app_root
results in a double slash when APPLICATION_ROOT is '/'
###### Why this matters
Could result in malformed URLs with double slashes (e.g., //api/v1/swagger)
which may cause issues with some web servers or clients.
###### Suggested change ∙ *Feature Preview*
Add handling for the app_root path to prevent double slashes:
```python
fab_swagger_path = f"{app_root}/api/v1/swagger" if app_root else
"/api/v1/swagger"
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:8cbd018a-8197-493b-9776-9763bf1bab4b -->
[](8cbd018a-8197-493b-9776-9763bf1bab4b)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]