Broken basePath with AbstractPathProvider in version 2.5.0 of springfox-swagger2
See original GitHub issue- Version 2.5.0 (same in 2.6.0)
- Bug: AbstractPathProvider extension point is broken for swagger2 due to this code block in Swagger2Controller:
Swagger swagger = mapper.mapDocumentation(documentation);
if (isNullOrEmpty(swagger.getHost())) {
final UriComponents uriComponents = componentsFrom(servletRequest);
swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath());
swagger.host(hostName(uriComponents));
}
Here you can see that even if the new path is getting to the Swagger object (line 1), it gets overwritten when “getHost” is checked. According to the swagger spec the host isn’t even required, so this kind of assumptions should not be made.
On the other hand, the basePath is overwritten when a host is not provided which is the main reason for this bug.
The last version that we know that works is 2.3.1.
Sample implementation of AbstractPathProvider:
class BasePathAwareRelativePathProvider extends AbstractPathProvider {
private String basePath;
public BasePathAwareRelativePathProvider(String basePath) {
this.basePath = basePath;
}
@Override
protected String applicationPath() {
return basePath;
}
...
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Broken basePath with AbstractPathProvider in version 2.5.0 of ...
Version 2.5.0 (same in 2.6.0); Bug: AbstractPathProvider extension point is broken for swagger2 due to this code block in Swagger2Controller ...
Read more >docs/release-notes.md · serv/springfox - Gitee.com
2.5.0 Release Notes ... (#1507) Broken basePath with AbstractPathProvider in version 2.5.0 of springfox-swagger2 @danielbcorreia; (#1435) Setting a Custom ...
Read more >java - Swagger 2 Issue - Spring Boot - Stack Overflow
Searching about I tried to change versions to 2.8.0, 2.7.0, 3.0.0... also returns error. The application is an apirest with task list activities ......
Read more >io.springfox:springfox-spring-web: Versions | Openbase
NOTE: This is a breaking change release, I've tried to maintain backwards ... basePath with AbstractPathProvider in version 2.5.0 of springfox-swagger2 ...
Read more >Springfox Reference Documentation - GitHub Pages
x version. Spring Boot Applications. Remove library inclusions of earlier releases. Specifically remove springfox-swagger2 and springfox-swagger ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’re just trying to set the “basePath” property on the swagger spec to be, for example, “/something” (instead of the default “/”).
This was working before the change that I mentioned for X-Forwarded-Host was introduced. The blank/null host should not mean that the basePath should be touched.
We can avoid the problem by setting the hostname ourselves before that code takes place, but that is another workaround, and that is an optional field on the swagger spec.
In my opinion, a further check needs to exist when you check for
isNullOrEmpty(swagger.getHost())
, so you don’t override the basePath when you don’t need to. We are not using X-Forwarded-Host, so our basePath should not be overwritten.I can try to put together a pull request to try to fix this.
@dilipkrish Is this available in a SNAPSHOT build for testing?