samikshathorat21 opened a new pull request, #41857:
URL: https://github.com/apache/superset/pull/41857

   ### SUMMARY
   
   This PR addresses issue #33304, where the Swagger UI may fail to load the 
OpenAPI specification when Apache Superset is deployed under a custom 
application root (`SUPERSET_APP_ROOT` / `APPLICATION_ROOT`).
   
   Under certain deployment configurations, the generated OpenAPI specification 
URL does not include the configured application prefix. As a result, the 
browser requests the OpenAPI specification from an incorrect path (for example, 
`/api/v1/_openapi` instead of `/prefix/api/v1/_openapi`), causing a `404 Not 
Found` response and preventing the Swagger UI from rendering correctly.
   
   This change introduces a server-side adjustment in `superset/app.py` that 
ensures the correct OpenAPI URL is provided to the Swagger template when 
`APPLICATION_ROOT` is configured. The implementation avoids client-side URL 
manipulation and keeps the template unchanged.
   
   Additionally, this PR includes regression tests covering the different 
deployment scenarios to ensure the correct OpenAPI URL is rendered.
   
   ---
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   #### Before
   
   - Swagger UI is accessed at:
     ```
     /prefix/swagger/v1
     ```
   - Browser requests:
     ```
     /api/v1/_openapi
     ```
   - Result:
     - HTTP 404 Not Found
     - Swagger UI fails to load the API specification.
   
   #### After
   
   - Swagger UI is accessed at:
     ```
     /prefix/swagger/v1
     ```
   - Browser requests:
     ```
     /prefix/api/v1/_openapi
     ```
   - Result:
     - HTTP 200 OK
     - Swagger UI successfully loads the OpenAPI specification.
   
   ---
   
   ### TESTING INSTRUCTIONS
   
   #### Environment
   
   ```bash
   export SUPERSET_APP_ROOT=/prefix
   export SUPERSET_ENABLE_SWAGGER_UI=true
   ```
   
   #### Initialize Superset
   
   ```bash
   superset db upgrade
   superset init
   ```
   
   #### Start the server
   
   ```bash
   flask run -p 8088
   ```
   
   #### Manual Verification
   
   1. Open:
   
      ```
      http://localhost:8088/prefix/swagger/v1
      ```
   
   2. Open the browser Developer Tools → Network tab.
   
   3. Verify that the OpenAPI specification is requested from:
   
      ```
      /prefix/api/v1/_openapi
      ```
   
   4. Confirm that the request returns **HTTP 200** and the Swagger UI renders 
successfully.
   
   #### Regression Tests
   
   Run:
   
   ```bash
   pytest tests/unit_tests/test_swagger_prefix.py -v
   ```
   
   The regression tests verify:
   
   - Default deployment (no application prefix)
   - Deployment using `SCRIPT_NAME`
   - Deployment using `APPLICATION_ROOT`
   
   ---


-- 
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]

Reply via email to