Skip to content

Swagger Middleware drops trailing slash and can't find path #238

@ArFe

Description

@ArFe

While joining the paths together opts.BasePath and opts.Path, path.Join drops the trailing slash.

pth := path.Join(opts.BasePath, opts.Path)

So, a /example/ui/ becomes /example/ui, and I get the error
"/example/ui" not found if I try to access /example/ui/

This is a problem because other languages use the trailing / as a pattern (for example python as here http://thomaxxl.pythonanywhere.com/api/ ), and we have webserver that use swagger in different languages.

There are 2 solutions, in my opinion:

  1. [Preferred/Easiest] compare apples to apples and submit r.URL.Path to path.Join as well here:
    if r.URL.Path == pth {

    if path.Join(r.URL.Path) == pth {
  2. do not use path.Join to join the opts.BasePath and opts.Path, just concatenate them

I can submit a PR for option 1 if you agree.

PS. It seems go is planning to have it's own JoinPath() inside net/url, and that could fix the problem in the future:
golang/go#47005
golang/go#52074

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions