-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chaining middleware with .openapi creates type errors #930
Comments
That works correctly and does not throw a type error in my environment: Or can I reproduce it? |
That's strange. The only difference between your code and mine is that as the handler to my routes I'm using a custom handler type which is just a RouteHandler type with the RouteConfig and AppBindings attached to it.
But I tried using an inline handler and I get the same result. https://github.com/Rick-Phoenix/odinproj-odinbook this is the repo where I am having this issue. It should be pretty easy to understand as all the parts involved in the process are the ones I've described in my original post, but let me know if I can clarify the issue any further. |
@Rick-Phoenix Thank you for your explanation and for sharing the repo. I've tried it. Does this work for you? It does not throw a type error: |
It does not throw a type error if called that way but then the middleware doesn't get called because the routes get matched beforehand. The only workaround I have found for this is to apply all of my global middleware before appending the openapi routes to the hono instance like in the picture below. |
Ah, yes. Exactly, you are right. I think your way is better currently. |
Which middleware has the bug?
@hono/zod-openapi
What version of the middleware?
0.18.3
What version of Hono are you using?
4.6.15
What runtime/platform is your app running on? (with version if possible)
Node 20.17.0
What steps can reproduce the bug?
The readme for zod-openapi indicates this method for using middleware with OpenApiHono:
However, this does not work and creates type errors.
So in my case I am doing this:
And this is creating a series of type errors
As the .openapi method is not present after chaining with .use.
The only way to make it work is to keep separate instances of OpenApiHono and not chain .use and .openapi on the same instance.
However, this method hinders flexibility in structuring routes.
The text was updated successfully, but these errors were encountered: