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?
I have an auth middleware which will check if the api token is provided in the request header, so it will respond with 401 or pass. How to make sure every protected route will be applied with the 401 response?
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
// 401
},
}),
async (ctx) => {
// do something
}
)
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
// 401
},
}),
async (ctx) => {
// do something
}
)
2 replies