trigger.dev
trigger.dev copied to clipboard
[TRI-1772] Allow defining Zod schemas for HTTP Endpoints
It would be nice to be able to attach a Zod schema on a HTTP endpoint which would then correctly type the results of request.json:
const endpoint = client.defineHttpEndpoint({
id: "tRPC",
source: "unkey.dev",
verify: async (req) => {
// verify here
},
schema: z.object({ }) // schema here
})
Hi @ericallam ,
I wanted to give this a try, but had few queries. Can you please let me know:
- Where can I find the schemas for request.json for different calls.
- Do we need to implement the validation similar to verifyRequestSignature method. If yes, Can we return { success: false, reason: "Schema validation failed." } or is there any other message to return.
- There is an existing Zod type "RequestWithRawBodySchema" can we use the same to infer in EndpointOptions or should we keep it generic z.ZodType<z.ZodSchema
> - If you can provide an access to TRI-1772
Can you please review if I am on right trace? https://github.com/triggerdotdev/trigger.dev/compare/main...PradeepJoshiFreelancer:trigger.dev:TRI-1772?expand=1
Thanks