Access zod IO schema in middleware #1066
-
Is it possible to access the IO schema as a callback parameter in middleware? I scrolled through all the properties of the request, response, and input params given by the middleware callback but did not see anything schema related, hoping I missed something. Outlining what I am trying to do below:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @noahdamiani , I don't understand the use-case. Handlers of the both However, it's easy for the handler to be aware of the schema — just declare it in a const in outer scope. const mySchema = z.object({ /* ... */ });
const myMiddleware = createMiddleware({
input: mySchema,
middleware: async () => {
return doYourStuff( mySchema )
}
}) |
Beta Was this translation helpful? Give feedback.
Hello @noahdamiani ,
I don't understand the use-case.
What are you trying to achieve exactly?
Handlers of the both
Middleware
andEndpoint
do not receive the schema — they receive the parsed and validated input data.However, it's easy for the handler to be aware of the schema — just declare it in a const in outer scope.