Closed Woody88 closed 1 year ago
I would also like know the answer to this question. I like this lib, it can create really nice swagger but unfortunately this is a major deal breaker that it cannot reply with HTTP code other than 200.
Hello,
Sorry for the very late reply.
I have pushed 1.3.1 today, with a proposed solution that is backwards-compatible:
f.zod.get(
`/item/:id`,
{
operationId: `getTodoItem`,
params: `TodoItemId`,
response: {
200: `TodoItem`,
404: `TodoItemNotFoundError`,
},
},
async ({ params: { id } }, reply) => {
const item = state.todoItems.find((item) => item.id === id);
if (item) {
return item;
}
reply.code(404);
return {
id,
message: `item not found`,
};
}
);
Does this solve your problem?
Hello,
I would like to know how does
fastify-zod
expect users to modify the reply status for a specific route?As of now, the
RouteHandler
type does not expose theFastifyReply
object: https://github.com/elierotenberg/fastify-zod/blob/4b1abf7971113f20fed5ff2013d7b5f06faeb782/src/FastifyZod.ts#L44-L52I can only think of using the
onSend
hook to intercept the reply request and modify the status code.