HonoH
Hono14mo ago
ggggggg

POST @hono/zod-validator seems to fail

I have a fairly minimal use-case, in which I'd like to validate that the json posted to an endpoint is correct ala zod. However, it bombs immediately with the following.

{"success":false,"error":{"issues":[{"code":"invalid_type","expected":"string","received":"undefined","path":["source"],"message":"Required"}],"name":"ZodError"}}


POST some json:
curl http://localhost:8000/beepboop -d '{
  "source": "astring"
}'


To the handler:
const schema = z.object({
  source: z.string(),
});

app.post("/beepboop", zValidator("json", reapSchema), (c) => {
  console.log("never got here");

  return c.json({ success: true });
});


These seems consistent with the documentation at https://github.com/honojs/middleware/tree/main/packages/zod-validator
Was this page helpful?