mattp
mattp
Explore posts from servers
HHono
Created by mattp on 6/13/2024 in #help
@hono/zod-openapi: How to write OpenAPI doc for middleware responses?
oh i figured it out. must explicitly given the response status to prevent type error.
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
401: {
// ...
}
},
}),
async (ctx) => {
// do something
return ctx.json({ ok: true }, 200) // <- explict
}
)
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
401: {
// ...
}
},
}),
async (ctx) => {
// do something
return ctx.json({ ok: true }, 200) // <- explict
}
)
2 replies