Skip to content
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

Feature Request: Support multi-wildcard names for same tree branch #364

Open
smikulcik opened this issue Mar 17, 2023 · 1 comment
Open

Comments

@smikulcik
Copy link

I see many similar issues, but I can't quite find one for tracking this particular feature request to support same-branch wildcards with different names.

Problem

I'm doing some OpenAPI code generation stuff and I'd like to use the parameter names from that document to build out the router path. But sometimes, the parameter in OpenAPI don't match up with other operations in the same tree. I can't change the parameter names in this OpenAPI document, I'd like to have httprouter (or gin) support this flow.

Example Failure

router := httprouter.New()
router.GET(`/foo/:bar`, h)
router.GET(`/foo/:fighters/are/great`, h)
panic: ':fighters' in new path '/foo/:fighters/are/great' conflicts with existing wildcard ':bar' in existing prefix '/foo/:bar'

https://go.dev/play/p/6Xu_jNomZtP

httprouter/tree.go

Lines 169 to 173 in 3425025

panic("'" + pathSeg +
"' in new path '" + fullPath +
"' conflicts with existing wildcard '" + n.path +
"' in existing prefix '" + prefix +
"'")

I understand it's not supported today, but can we add support for same-path but different parameter names?

Related Issues

@nathangeneral23
Copy link

That's an interesting scenario. In a standard REST API those two parameters should theoretically be the same. Are both routes using the same handler function as that's how it appears?

As a work-around, could you set the parameter names to both be param1. Then create a variable with the 'correct' or domain-specific param name in the handler function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants