Skip to content

Unexpected behavior with multiple path parameters in nested routes #86

@malolago

Description

@malolago

Bug description

When defining a route with two path parameters (for example /users/:userId/posts/:postId), the generated client incorrectly places both parameters in the first call to tuyau.users({...}). As a result, the second parameter (postId) is not scoped to the .posts() call as expected.

What’s happening

For a route like:

GET /users/:userId/posts/:postId

The generated client ends up like this:

await tuyau.users({ userId, postId }).posts().$get()

So both userId and postId are passed together in the .users() call.

Expected behavior

I would expect the client to allow chaining the parameters for each segment, like:

await tuyau
  .users({ userId })
  .posts({ postId })
  .$get()

Meaning the parameter for the posts segment should be passed in the .posts({ … }) call.

Steps to reproduce

  1. Define a route with two path parameters, for example:
router.get('/users/:userId/posts/:postId', 'PostsController.show')
  1. Generate the API client.
  2. Try to call it like:
await tuyau.users({ userId, postId }).posts({}).$get()
  1. Observe that postId stays with users() instead of being scoped to .posts().

Environment

  • @tuyau/core: 0.4.2
  • Node: v22.18.0
  • OS: Windows 11

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