-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
configUrl cache issue when using Swagger-UI #1712
Comments
how this is been solved, i am facing same issue my api but on my production which is a ui visit swagger via a proxy https://localhost:8082/services/swagger-ui/index.html how do i handle make both works |
I made a hack on my side to fix the issue (does not work when two requests from different context path arrives at the same time public class AlwaysComputeConfigUrlSwaggerTransformer extends SwaggerIndexPageTransformer {
public AlwaysComputeConfigUrlSwaggerTransformer(SwaggerUiConfigProperties swaggerUiConfig, SwaggerUiOAuthProperties swaggerUiOAuthProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, SwaggerWelcomeCommon swaggerWelcomeCommon, ObjectMapperProvider objectMapperProvider) {
super(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters, swaggerWelcomeCommon, objectMapperProvider);
}
@Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
this.swaggerUiConfigParameters.setConfigUrl(null); // force parent class to compute data
return super.transform(request, resource, transformerChain);
}
} All you have to do is instanciate it from your This is quite dirty yet, we see that the config url which is an attribute of a Of course I use |
should be fixed by #1748 |
Hello @bnasslahsen, |
Thank you @antechrestos for your feedback. |
The problem is still present even in the springdoc-openapi version = 2.2.0. The only working solution for me is the one proposed by @antechrestos with a @Bean
@RequestScope
public SwaggerIndexPageTransformer computeConfigUrlSwagger(SwaggerUiConfigProperties swaggerUiConfig,
SwaggerUiOAuthProperties swaggerUiOAuthProperties, SwaggerUiConfigParameters swaggerUiConfigParameters,
SwaggerWelcomeCommon swaggerWelcomeCommon, ObjectMapperProvider objectMapperProvider) {
return new SwaggerIndexPageTransformer(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters,
swaggerWelcomeCommon, objectMapperProvider) {
@Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)
throws IOException {
this.swaggerUiConfigParameters.setConfigUrl(null);
return super.transform(request, resource, transformerChain);
}
};
} |
The workaround by @antechrestos does not work for me, problem is still present. |
@bnasslahsen can this be reopened? |
This can be reopened if an issue is confirmed. |
I can confirm this issue still exists with springdoc 2.3.0, when accessing /xxx/swagger-ui/index.html, it uses the cached configUrl, however when accessing /xxx/swagger-ui.html the cached url will be updated and it works, but it redirects to /xxx/swagger-ui/index.html so people will bookmark this address and it will use cached url. |
Issue still exists on springdoc 2.4.0 |
Describe the bug
Hello,
Our users access swagger using direct access to api : http://localhost:8080/api/v0/swagger-ui/index.html
And other users access the swagger UI behind nginx proxy : http://localhost/api/v0/myservice/swagger-ui/index.html
The problem is the config url is calculated just the first time and used for both access.
The issue is well known and described here
To Reproduce
Steps to reproduce the behavior:
Call swagger ui using nginx proxy : http://localhost/api/v0/myservice/swagger-ui/index.html
Call swagger UI without the proxy : http://localhost:8080/api/v0/swagger-ui/index.html
In the second call we have error message : Failed to load remote configuration.
It's because it makes a call to http://localhost:8080/api/v0/myservice/v3/api-docs/swagger-config that is built the first time when calling the swagger via nginx.
2.6.6
1.6.9
Please find HelloController with nginxConfig
Expected behavior
Both URLS work without any impact:
URL without nginx : http://localhost:8080/api/v0/swagger-ui/index.html
URL with nginx : http://localhost/api/v0/myservice/swagger-ui/index.html
Screenshots


If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Thank you for your help
Best Regards,
The text was updated successfully, but these errors were encountered: