diff --git a/.changeset/rare-pillows-change.md b/.changeset/rare-pillows-change.md new file mode 100644 index 00000000..e2c8519d --- /dev/null +++ b/.changeset/rare-pillows-change.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': minor +--- + +Export types that allow for separate declaratins of route handlers and hooks diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 3cb357db..f153fe93 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -153,6 +153,30 @@ type HandlerResponse = TypedResponse | Promise> type HonoInit = ConstructorParameters[0] +export type RouteHandler< + R extends RouteConfig, + E extends Env = Env, + I extends Input = InputTypeParam & + InputTypeQuery & + InputTypeHeader & + InputTypeCookie & + InputTypeForm & + InputTypeJson, + P extends string = ConvertPathType +> = Handler>> + +export type RouteHook< + R extends RouteConfig, + E extends Env = Env, + I extends Input = InputTypeParam & + InputTypeQuery & + InputTypeHeader & + InputTypeCookie & + InputTypeForm & + InputTypeJson, + P extends string = ConvertPathType +> = Hook> + export class OpenAPIHono< E extends Env = Env, S extends Schema = {}, @@ -176,8 +200,8 @@ export class OpenAPIHono< P extends string = ConvertPathType >( route: R, - handler: Handler>>, - hook?: Hook> + handler: RouteHandler, + hook?: RouteHook ): OpenAPIHono>, BasePath> => { this.openAPIRegistry.registerPath(route)