Skip to content

fix: extract path parameters correctly when the router is mounted as subrouter - #134

Merged
pk-work merged 2 commits into
eclipse-vertx:mainfrom
SiteNetSoft:fix/subrouter-path-params
Aug 10, 2026
Merged

fix: extract path parameters correctly when the router is mounted as subrouter#134
pk-work merged 2 commits into
eclipse-vertx:mainfrom
SiteNetSoft:fix/subrouter-path-params

Conversation

@jnbdz

@jnbdz jnbdz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

As reported in #120: RequestUtils calculates the position of a path parameter from the beginning of the OpenAPI path template (/entities/{id} → segment 2) and applies it to the path of the incoming request. When the router built from the contract is mounted as a subrouter (e.g. mainRouter.route("/my-service/*").subRouter(router)), the request path (/my-service/entities/5) contains additional leading segments, so the calculated position points to the wrong segment. Validation then either fails with a confusing type error or — worse — silently validates the wrong value (for string parameters).

Changes

Mounting a router can only prepend segments to the request path, so the number of additional leading segments can be determined by comparing the segment count of the request path with the segment count of the path template. The parameter position is now shifted by this mount offset:

  • Routers mounted as subrouter (at any depth) now extract path parameters correctly, with and without trailing slash.
  • For routers that are not mounted, the offset is 0 and the behaviour is unchanged — including the existing handling of empty path parameters.
  • Also removed the unused Parameter argument of extractPathParameters that was mentioned in the issue discussion.

One limitation worth being transparent about: a mounted router receiving an empty trailing path parameter (/my-service/test/) remains ambiguous, because without knowing the mount point the extra segments cannot be distinguished from the parameter itself. Resolving that fully would require the mount information from vertx-web (see vert-x3/vertx-web#2694). This change fixes the practically relevant cases without any API change.

Fixes #120

jnbdz added 2 commits August 9, 2026 21:17
…subrouter

The position of a path parameter was calculated from the beginning of
the OpenAPI path template and applied to the path of the incoming
request. When the router built from the contract is mounted as a
subrouter, the request path contains additional leading segments, so the
calculated position pointed to the wrong segment and validation failed
or, even worse, validated the wrong value.

Since mounting a router can only prepend segments to the request path,
the number of additional leading segments is now determined by comparing
the number of segments of the request path with the number of segments
of the path template, and the parameter position is shifted accordingly.
For routers that are not mounted as subrouter the behaviour is
unchanged.

Fixes eclipse-vertx#120
@pk-work
pk-work merged commit 2c61293 into eclipse-vertx:main Aug 10, 2026
5 checks passed
@pk-work

pk-work commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@jnbdz Thank you!

@jnbdz
jnbdz deleted the fix/subrouter-path-params branch August 12, 2026 02:23
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

Successfully merging this pull request may close these issues.

Request validation may fail due to incorrect path parameter extraction

2 participants