swagger-express-middleware icon indicating copy to clipboard operation
swagger-express-middleware copied to clipboard

if swagger's basePath is / and endpoint paths start with /, the middleware requires requests be made with two slashes

Open alex-dow opened this issue 8 years ago • 9 comments

If swagger's basepath is / and an endpoint is /some/api/endpoint, then one must access the url as //some/api/endpoint otherwise paths won't match.

alex-dow avatar May 06 '16 14:05 alex-dow

+1

whq731 avatar Jun 15 '16 04:06 whq731

having the same issue

Ohmnivore avatar Aug 01 '16 14:08 Ohmnivore

If your API is served from the root directory, then your basePath should be empty (unset), not a forward slash. You should only set basePath if your API is served from a subdirectory, or if all of your API endpoints start with the same path segment(s).

JamesMessinger avatar Aug 01 '16 16:08 JamesMessinger

I ported my code from https://github.com/apigee-127/swagger-express, and its project template sets forward slash for basePath. I eventually found the other issue which describes the solution.

Ohmnivore avatar Aug 01 '16 17:08 Ohmnivore

Hmmm... I didn't realize Swagger Express was doing that. It's technically incorrect, per the spec, but I'll add code to Swagger Express Middleware to handle it.

JamesMessinger avatar Aug 01 '16 18:08 JamesMessinger

Would a pull request help or are you already working on this issue? And update the swagger-server with a new version of this lib? Some Swagger specifications have this basePath with a forward slash and it would be a nice to have if it worked as is.

sey avatar Oct 13 '16 12:10 sey

A PR would be greatly appreciated. I've got lots of other stuff on my plate right now, so I haven't been able to work on this project in months. :(

JamesMessinger avatar Oct 13 '16 12:10 JamesMessinger

Hey guys, any news on this? Is there any way to handle this via middleware options?

nmitic avatar Feb 20 '19 12:02 nmitic

Currently the solution is to remove the basePath option, since it shouldn't be just a /.

JamesMessinger avatar Feb 20 '19 12:02 JamesMessinger