question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 7 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danielbcorreiacommented, Oct 6, 2016
@RestController
public class PingController {

    @ApiOperation(value = "Ping endpoint", notes = "Ping endpoint")
    @RequestMapping(value = "/ping", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
    @ApiResponses(value = {@ApiResponse(code = 200, message = "OK")})
    public ResponseEntity<String> ping() {
        return ResponseEntity.ok("pong");
    }
}

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.

0reactions
jonathannaguincommented, Apr 21, 2017

@dilipkrish Is this available in a SNAPSHOT build for testing?

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found