From dbebf747c9c7ca94bf22259772d8b1e0623ce68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Bergstr=C3=B6m=20=28NotoriousSledge=29?= <95848357+exsjabe@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:59:22 +0200 Subject: [PATCH] feat: Zod-Openapi-Middleware: Export types to allow handlers and hooks to be declared in more places. (#167) * Exported Handler and Hook types * Performed changeset --- .changeset/rare-pillows-change.md | 5 +++++ packages/zod-openapi/src/index.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changeset/rare-pillows-change.md 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)