Skip to content
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

Bug Report: Swagger UI Fails to Recognize Context Path Randomly Behind API Gateway #2769

Open
cjullien opened this issue Oct 28, 2024 · 0 comments

Comments

@cjullien
Copy link

I am experiencing an issue with Swagger UI not properly recognizing the context path in a Spring Boot 3 application deployed behind an API gateway. The application works correctly locally and functioned as expected in Spring Boot 2. However, when deployed on a server with the API gateway, Swagger UI intermittently fails to load the configuration, especially when accessed from different operating systems.

I've this error
GET https://myAPIGateway/v3/api-docs/swagger-config 404 (Not Found) on swagger-ui-bundle.js

try {
            m = await (s.userFetch || fetch)(s.url, s),
            m = await Ju.serializeRes(m, i, s),
            s.responseInterceptor && (m = await s.responseInterceptor(m) || m)
        } 

Environment:

Spring Boot version: 3.x.x2.6.0[insert your version]
Operating Systems tested: macOS, Windows
API Gateway: Gravitee.io
Steps to Reproduce:

Deploy the Spring Boot application behind an API gateway on a server.
Access Swagger UI from a macOS device and confirm it loads correctly with the context path set to /myContextPath.
Access the same Swagger UI from a Windows device, which fails with the error "Failed to load remote configuration."
After this, access from macOS again, and it now also shows the same error.
Expected Behavior:

Swagger UI should consistently recognize and load the API documentation from the correct context path (/myContextPath/v3/api-docs) regardless of the operating system used to access it.
Actual Behavior:

The URL used for Swagger configuration sometimes defaults to /v3/api-docs/swagger-config instead of /myContextPath/v3/api-docs/swagger-config, leading to a failure in loading the configuration.
Additional Notes:

I have tried clearing the cache and disabling CORS, but the issue persists.
This behavior is a regression, as everything was functioning correctly in Spring Boot 2.
The issue seems to be related to how Swagger UI bundles and loads its configuration behind the API gateway.
Suggested Solutions:

It may be helpful to investigate how the context path is being determined and ensure that it consistently resolves correctly across different platforms and API gateway configurations.
Consider providing an option to explicitly set the base path for Swagger UI in the configuration settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant