Closed matannahmani closed 1 year ago
After more playing around i managed to almost get it, but the client still doesn't recognize the parameters client: api builder:
function genParamsFromZ<R extends z.ZodRawShape>(
schema: z.ZodObject<R, 'strip'>,
type: 'Query' | 'Body' | 'Header'
) {
const object = schema.shape;
const params = Object.keys(object).map((key) => {
const keyTyped = key as keyof R;
return {
type,
name: keyTyped,
schema: object[keyTyped],
};
});
return params;
}
export const sesGroupZodiosRouter = apiBuilder({
method: 'get',
path: path('aptinfo'),
parameters: [...genParamsFromZ(getApartmentInfoInputZod, 'Query')],
errors,
response: responseZ(getApartmentInfoOutputZod),
alias: 'group.apt.info',
description: 'Get Apartment Info',
})
// .addEndPoint({...})
.build();
typescript definition on hover:
sorry i can't provide help to do this. if you need inspiration go check : https://github.com/thelinuxlich/zodios-api-shorthand
Hey, I love the package and I've been trying to make a util function to spread a ZodObject into parameters instead of having to manually write the fields. I was wondering if there is any built-in function for this or if would you mind adding support for it. I tried making my own function but the types aren't being drilled properly, client get's a type error and no Intellisense
Here is my run so far: Here we define the params generator
and then on the client: