3.0.0 Not possible to change base path with NGINX X-Forwarded-Prefix
See original GitHub issueI just upgraded to the latest version of springfox-swagger2 (3.0.0). We have a proxy server and our X-Forward-Prefix (/headers) are configured (NGINX).
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Prefix /api/animals;
proxy_set_header X-Real-IP $remote_addr;
With the old version of springfox-swagger2 (2.10.5) we configured our Docket:
return new Docket(DocumentationType.SWAGGER_2) //
// Workaround for bug https://github.com/springfox/springfox/issues/2622
.pathProvider(new RelativePathProvider(null) {
@Override
public String getApplicationBasePath() {
return "/api/animals";
}
});
This resulted in a base path: [ Base URL: xxxx.com/api/animals/rest ] The /rest part is always present for our rest endpoints and is not part of the reverse proxy.
Swagger ui itself works fine and runs on the https://xxxx.com/api/animals/rest/swagger-ui/index.html
Now according to https://github.com/springfox/springfox/issues/2622 we should not add the addProvider anymore (its even not possible anymore), but when we remove this lines it result in a bad request url: Base URL: xxxx.com/rest instead of xxxx.com/api/animals/rest, so the value of X-Forward-Prefix is still missing. I already tried configuring pathMapping(path) on the Docket but this results in: xxxx.com/rest/api/animals, same for :
.pathProvider(new DefaultPathProvider() {
@Override
public String getDocumentationPath() {
return "/api/animals/";
}
});
This results in: [ Base URL: xxxx.com/rest ] --> WRONG, should be: https://xxxx.com/api/animals/rest/ https://xxxx.com/api/animals/rest/v2/api-docs. --> correct
Thanks for your help!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Just found a solution to set the
basePath
programmatically. In my case, I use theX-Forwarded-*
headers from upstream HTTP proxies, but setting thebasePath
statically is also no problem. Base for this solution are Springfox Plugins that allow manipulation of the generated swagger.Kotlin:
This is my solution in java.Hope to be helpful.