Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Path parameters require explicit coerce on POST/PATCH/PUT #243

@k0l11

Description

@k0l11

If have the following procedure

sayHello: t.procedure
    .meta({ openapi: { method: 'POST', path: '/say-hello/{id}' } })
    .input(z.object({ id: z.number(), greeting: z.string() }))
    .output(z.object({ greeting: z.string() }))
    .query(({ input }) => {
      return { greeting: `${input.greeting} ${input.id}!` };
    })

and I send the following request

POST http://localhost:3000/say-hello/1
Content-Type: application/json

{
    "greeting": "Test"
}

then I get

{
  "message": "Input validation failed",
  "code": "BAD_REQUEST",
  "issues": [
    {
      "code": "invalid_type",
      "expected": "number",
      "received": "string",
      "path": [
        "id"
      ],
      "message": "Expected number, received string"
    }
  ]
}

Looks like having a request body somehow messes with coercion of the path parameter. Using z.coerce.number() instead of z.number() for id works for now. It should work without the explicit coerce according to the PR that added this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions