You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to openapi you should prefer oneOf unless your responses can be a combination of things.
However, @hono/zod-openapi uses anyOf for all of the generated schemas - this is due to the underlying implementation of zod-to-openapi - you can see an issue here and an in progress PR here
All of the inferred types from @hono/zod-openapi to hono really only work if using zod .or which in turn generates schemas with anyOf - if all of your API clients are just using hono rpc, this should be fine. If any of your clients are not hono rpc and are using some kind of openapi client generation, they could run into issues with endpoints that return anyOf in the schema.
Short answer - just use .or / anyOf if you are only using hono / hono rpc.
//code
selectTaskSchema,
z.object({ message: z.string() }),
], "The selected task"),
},
export const single: RouteHandler<SingleTaskRoute, AppBindings> = async (c) => {
const { id } = c.req.valid("param");
const task = await db.query.taskTable.findFirst({
where: (task, { eq }) => eq(task.id, id),
});
if (!task) {
return c.json({ message: "Task not found" }, 200);
}
return c.json(task, 200);
};
I am getting type error on single handler
I know you did response it with different status code also i can do it
But I just want to know how oneOf schema will work with handler properly
If I want to response with same status code but different json then how handler will infer the type
The text was updated successfully, but these errors were encountered: