Closed Uzlopak closed 7 months ago
Not sure if this works if you add a preSerialization
hook
// This by itself may work
fastify.addHook('preSerialization', async function (_, reply, payload) {
const status = reply.statusCode;
return status > 299 ? { status, error: payload } : { status, data: payload };
});
// I think this will break it (which i am kind of debating if it's a good thing to have this)
fastify.addHook('onRoute', function (routeOptions) {
const responseSchema = routeOptions.schema?.response as Record<string, unknown>;
if (responseSchema && responseSchema['200']) {
responseSchema['200'] = z.object({
status: z.number(),
data: responseSchema['200'] as AnyZodObject,
});
}
});```
@kevbook Why wasn't it breaking before?
@Uzlopak why close?
@kibertoad Its like open for about 9 months. Should have come to a conclusion in that time.
sorry, I didn't get to it in time. I'll do my best to reintroduce it in upcoming weeks
Could result in some nice perf gains.