Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
k0l11 opened this issue Jan 23, 2023 · 0 comments · Fixed by #247
Closed

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

k0l11 opened this issue Jan 23, 2023 · 0 comments · Fixed by #247
Labels
bug Something isn't working

Comments

@k0l11
Copy link

k0l11 commented Jan 23, 2023

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.

@k0l11 k0l11 changed the title Path parameters don't get coerced on POST/PATCH/PUT Path parameters require explicit coerce on POST/PATCH/PUT Jan 23, 2023
@jlalmes jlalmes added the bug Something isn't working label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants