swaggo / echo-swagger

echo middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
791 stars 125 forks source link

oauth2-redirect.html with query parameters return 404 #106

Open rytsh opened 1 year ago

rytsh commented 1 year ago

Hi, when I try to login oauth2 feature, it is redirection to this URL:

http://localhost:3000/swagger/oauth2-redirect.html?state=U3X..

But when I checked, if any query parameters go to this html oauth2-redirect.html route not found and return 404.

This should be bug and need to fix the route, serve steps.

v1.3.5 works fine with oauth2 redirection.

komron-m commented 12 months ago

I faced the same issue, the bug is in default case of switch statement of swagger.go, line 191 image

I suggest creating a fork and changing code in default case to:

parsedUrl, err := url.Parse(matches[2])
if err != nil {
    c.Error(err)

    return nil
}
c.Request().URL = parsedUrl
http.FileServer(http.FS(swaggerFiles.FS)).ServeHTTP(c.Response(), c.Request())

BTW: this issue is mentioned also here: https://github.com/swaggo/swag/issues/1117

reidlevesque commented 1 month ago

I made a PR for the suggested fix after testing it successfully in my fork.