-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Path params with conflicting names #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm this is surely from the router resolution algorithm. using the same names work but it fails when different names are used... Maybe I'll try looking into it. Do you have any leads? |
This is because the nodes on the Router only have an internal structure to store the path parameters (pnames), and the same node is used for all the HTTP methods. That's the reason why the path parameters that ends up in the node for that url are the ones of the PUT (vid and gid) |
After thinking and reasoning about why currently router has that behavour. I would say - it is correct. Why would parameter at same place be conceptually different for GET vs PUT methods? in REST sense having different parameter identifier for same field Probably in forcing user to use same parameter names for parameter at same place is more consistent for their API and code readability. |
@aldas I agree with you. I have a little PR that panics when the same route with different route params is added (regarding HTTP method). If everyone agrees I can submit it. If someone upgrades Echo to that code, I think it will be easy to fix it, but besides of that maybe the PR should be tagged as v5. Any thoughts? |
From now, Echo panics if a route that was already added, is added again but for a different HTTP method and the path params are different. e.g. GET /translation/:lang -> Added OK PUT /translation/:lang -> Added OK DELETE /translation/:id -> Panic Partially Fixes labstack#1726 labstack#1744
Issue Description
I had created routes using GET and PUT with path parameters. Using the same names in both works fine, but if the names are different it doesn't work.
Checklist
Expected behaviour
I would expect each path to own its own path parameters.
Actual behaviour
Not all path parameters expected are found. The order or declaration affects which ones are missing.
Steps to reproduce
In
router_test.go
, changeTestRouterTwoParam
to have both GET and PUT paths and for these to have distinct parameter names.This test fails. If the two
Add
statements are swapped, it still fails but in a different place.Version/commit
v4.1.17-99-g936c48a
The text was updated successfully, but these errors were encountered: