Adding swagger to hono API
I want to add a swagger doc to my API and when I add middleware to any new OpenAPIHono instance the .openapi method disappears.
this is my factory method. the instance returned doesn't have
.openapi
, so I can pass my schema returned by createRoute().2 Replies
I believe hono openapi has a note about how the handle middleware hono instances, but the just is that it doesn’t change the return types of any middleware so if it’s your own middleware, you should define it using
new OpenAPIHono
instead of new Hono
if it’s not your middleware, one workaround is you can define your routes in a separate route const routes = new OpenAPIHono()…
and then in your main app new OpenAPIHono().use(middleware).route("", routes)
it turns out you have to break it up and it works perfectly