Skip to content

fix: make it possible to have the same path parameter twice in URL - #2175

Closed
juniorrantila wants to merge 1 commit into
oapi-codegen:mainfrom
juniorrantila:main
Closed

juniorrantila wants to merge 1 commit into
oapi-codegen:mainfrom
juniorrantila:main

Conversation

@juniorrantila

Copy link
Copy Markdown
Contributor

This makes it possible to parse the keycloak openapi spec, which for one API has a URL of '/admin/realms/{realm}/clients/{client-uuid}/roles/{role-name}/composites/clients/{client-uuid}'.

This makes it possible to parse the keycloak openapi spec, which for one
API has a URL of '/admin/realms/{realm}/clients/{client-uuid}/roles/{role-name}/composites/clients/{client-uuid}'.
@juniorrantila juniorrantila changed the title Make it possible to have the same path parameter twice in URL fix: make it possible to have the same path parameter twice in URL Dec 17, 2025
@jamietanna

Copy link
Copy Markdown
Member

Related: #1574

mromaszewicz added a commit to mromaszewicz/oapi-codegen that referenced this pull request Feb 14, 2026
Some real-world OpenAPI specs (e.g. Keycloak) reuse the same path
parameter more than once in a single URI, such as:
/clients/{client-uuid}/roles/{role-name}/composites/clients/{client-uuid}

Previously this caused a "has 4 positional parameters, but spec has 3
declared" error because SortParamsByPath compared raw URI placeholder
count against unique declared parameters.

Fix this by deduplicating the path parameters extracted from the URI
(preserving first-occurrence order) before matching them against the
spec declared parameters. This is the right level to fix the issue
rather than scattering dedup logic across template helpers.

Fixes oapi-codegen#1574
Supersedes oapi-codegen#2175

Co-Authored-By: Junior Rantila <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@mromaszewicz

Copy link
Copy Markdown
Member

Thanks for doing this, @juniorrantila , however, this isn't the right fix for the problem. The problem needs to be fixed at the time the schemas for the parameters are gathered for each path. I'm closing this commit, and added you as a Co-Author on a new one, so you get some credit for finding this.

mromaszewicz added a commit that referenced this pull request Feb 15, 2026
Some real-world OpenAPI specs (e.g. Keycloak) reuse the same path
parameter more than once in a single URI, such as:
/clients/{client-uuid}/roles/{role-name}/composites/clients/{client-uuid}

Previously this caused a "has 4 positional parameters, but spec has 3
declared" error because SortParamsByPath compared raw URI placeholder
count against unique declared parameters.

Fix this by deduplicating the path parameters extracted from the URI
(preserving first-occurrence order) before matching them against the
spec declared parameters. This is the right level to fix the issue
rather than scattering dedup logic across template helpers.

Fixes #1574
Supersedes #2175

Co-authored-by: Junior Rantila <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants