-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Which middleware is the feature for?
@hono/zod-openapi
What is the feature you are proposing?
I would like to define routes and handlers in separate files for better organization and register them in a central file where I declare the app object.
Let's say I have the file routes/shorturls.ts:
export const createShortUrlRoute = createRoute({})
// What's the type of createShortUrlHandler ?
export const createShortUrlHandler = async (c) => {
const data = c.req.valid('json');
}and the main file index.ts where I declare the app and I register the routes:
import { OpenAPIHono } from "@hono/zod-openapi";
export const app = new OpenAPIHono();
// I would like to register the routes here
app.openapi(createShortUrlRoute, createShortUrlHandler)The problem is the type of createShortUrlHandler, if I use a normal Handler type, I loose the request and response validation types, I tried also to reuse the types declared in the sourcecode of @hono/zod-openapi but basically I need to copy 100s of lines of code.
Proposed solution
Can you expose the type of the handler so I can do something like this:
import { OpenAPIHandler } from "@hono/zod-openapi";
export const createShortUrlRoute = createRoute({})
export const createShortUrlHandler: OpenAPIHandler<typeof createShortUrlRoute> = async (c) => {
const data = c.req.valid('json');
}Actual solution
Today I have my OpenAPIHono app defined in a dedicated app.ts file and I have multiple route files that import app and register the routes and finally all route files are imported into index.ts as import './routes/shorturls.ts'