trpc-openapi
trpc-openapi copied to clipboard
Feat/support number boolean date input params
Seeking some feedback. This PR monkey patches the TRPCRouter to support number, boolean & Date out of the box (string was already supported) for queries inputs & pathParameters. I hope this would improve trpc-openapi incremental adoption, but I'm not sure wether I should just close this PR & force just encourage users to use z.preprocess instead...?
// Before PR
.query('some-query', {
meta: { openapi: {...} },
input: z.object({
offset: z.preprocess((arg) => {
if (typeof arg === 'string') return parseInt(arg);
return arg;
}, z.number().min(0)),
limit: z.preprocess((arg) => {
if (typeof arg === 'string') return parseInt(arg);
return arg;
}, z.number().min(10).max(50)),
}),
...
})
// After PR
.query('some-query', {
meta: { openapi: {...} },
input: z.object({
offset: z.number().min(0),
limit: z.number().min(10).max(50),
}),
...
})