Skip to content

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

@smikulcik

Description

@smikulcik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions