swaggerize-express icon indicating copy to clipboard operation
swaggerize-express copied to clipboard

Bug in routing

Open slinkydeveloper opened this issue 9 years ago • 4 comments

I've got the swagger spec like this:

paths:
  /users/{query}: (get, put, delete)
  /users/findUser: (get)
  /users/newUser: (post)

The paths are defined in this order. After the implementation of handlers, if i try to call the path /users/findUser it will execute the handler for path /users/{query}. I know that usually in an express application if i define a path with path parameter before another path without path parameter express will execute the handler of path with path parameter, but in this case swagger specs doesn't have to be depending to implementation.

Thank you

slinkydeveloper avatar Sep 16 '16 11:09 slinkydeveloper

This module uses the express router. I've not seen a router that would avoid this issue.

Are you saying that calling post on /usres/findUser calls the query route? Because it shouldn't due to the methods you've declared above.

tlivings avatar Oct 09 '16 14:10 tlivings

I think the issue is the order in which they registered in react router, so if in the spec you define /users/{query} before /users/findUser, the path will match that one first.

I know those routes are probably just an example, but if you follow more closely to REST standards, you shouldn't have this issue:

paths:
  /users: (post: createUser, get: queryUsers)
  /users/{id}: (get: findOne, put: update, delete: removeUser)

@slinkydeveloper Have you tried reordering your paths to make the /users/{query} appear after the others?

ksmithut avatar Nov 30 '16 16:11 ksmithut

Resolved reordering the paths. But i think that when paths are added in swaggerize-express, paths without regex must be added before paths with regex, to avoid this issue. As I said, IMHO api specification must be indipendent from implementation

slinkydeveloper avatar Apr 03 '17 10:04 slinkydeveloper

@tlivings sorry typing error i updated the issue description

slinkydeveloper avatar Apr 03 '17 10:04 slinkydeveloper