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>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</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
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e725b253-8240-4788-b755-6dba3ddc7537?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to