trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

[TRI-1772] Allow defining Zod schemas for HTTP Endpoints

Open ericallam opened this issue 2 years ago • 1 comments

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
})

TRI-1772

ericallam avatar Dec 18 '23 11:12 ericallam

Hi @ericallam ,

I wanted to give this a try, but had few queries. Can you please let me know:

  1. Where can I find the schemas for request.json for different calls.
  2. 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.
  3. 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>
  4. 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

PradeepJoshiFreelancer avatar Jan 17 '24 13:01 PradeepJoshiFreelancer