-
Notifications
You must be signed in to change notification settings - Fork 191
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
[zod-openapi] Wrong return type from use
#843
Comments
@hono/zod-openapi
returns wrong type from use
use
use
use
Hi @hpohlmeyer That's right, OpenAPIHono does not provide that feature due to the limitations of Hono's type definitions. It will have to be redefined in |
@hpohlmeyer the way that i do it is i separate the router and server part: export const mainRouter = new OpenAPIHono()
.basePath('/api/v1')
.route('/auth', authRouter)
.doc('/doc', {})
export type AppType = typeof mainRouter; const app = new OpenAPIHono()
.use(
'*',
cors({ origin: [process.env.DASHBOARD_URL], credentials: true })
)
.route('/', mainRouter);
const port = getPortFromURL(process.env.API_URL, 3000);
serve({ fetch: app.fetch, port }).on('listening', () => {
console.log(`>>> API running on ::${port}`);
}); Hope that helps! |
Any updates on this? It's an annoying bug because it makes using middleware impossible without getting type errors if they are chained in the usual way. Even this example from the readme:
Is not correct as this creates a type error. I have not tested using the middleware property on the createRoute object but even then I don't think that would be a solution because I assume that middleware would be tied to the single route and not to a collection of routes. I've added an issue to report this in more detail: #930 |
When using the chaining approach needed for Hono RPC with a middleware,
OpenApiHono
specific methods do not exist on the chain anymore after usinguse
, becauseuse
returnsHono
instead ofOpenApiHono
.Ideally these kind of issues would be solved by returning
this
from the base hono class, but we would need to pass on the modified generics tothis
, which is not supported by typescript yet. That means every Hono method should be repesented in theOpenAPIHono
class definition as well, but withOpenAPIHono
as the return type. To fix this issue it looks like we need to add theuse
method with the proper return type to theOpenAPIHono
type declaration.The text was updated successfully, but these errors were encountered: