feat: Zod-Openapi-Middleware: Export types to allow handlers and hooks to be declared in more places. (#167)
* Exported Handler and Hook types * Performed changesetpull/169/head
parent
a8747ab6fe
commit
dbebf747c9
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@hono/zod-openapi': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Export types that allow for separate declaratins of route handlers and hooks
|
|
@ -153,6 +153,30 @@ type HandlerResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>
|
||||||
|
|
||||||
type HonoInit = ConstructorParameters<typeof Hono>[0]
|
type HonoInit = ConstructorParameters<typeof Hono>[0]
|
||||||
|
|
||||||
|
export type RouteHandler<
|
||||||
|
R extends RouteConfig,
|
||||||
|
E extends Env = Env,
|
||||||
|
I extends Input = InputTypeParam<R> &
|
||||||
|
InputTypeQuery<R> &
|
||||||
|
InputTypeHeader<R> &
|
||||||
|
InputTypeCookie<R> &
|
||||||
|
InputTypeForm<R> &
|
||||||
|
InputTypeJson<R>,
|
||||||
|
P extends string = ConvertPathType<R['path']>
|
||||||
|
> = Handler<E, P, I, HandlerResponse<OutputType<R>>>
|
||||||
|
|
||||||
|
export type RouteHook<
|
||||||
|
R extends RouteConfig,
|
||||||
|
E extends Env = Env,
|
||||||
|
I extends Input = InputTypeParam<R> &
|
||||||
|
InputTypeQuery<R> &
|
||||||
|
InputTypeHeader<R> &
|
||||||
|
InputTypeCookie<R> &
|
||||||
|
InputTypeForm<R> &
|
||||||
|
InputTypeJson<R>,
|
||||||
|
P extends string = ConvertPathType<R['path']>
|
||||||
|
> = Hook<I, E, P, OutputType<R>>
|
||||||
|
|
||||||
export class OpenAPIHono<
|
export class OpenAPIHono<
|
||||||
E extends Env = Env,
|
E extends Env = Env,
|
||||||
S extends Schema = {},
|
S extends Schema = {},
|
||||||
|
@ -176,8 +200,8 @@ export class OpenAPIHono<
|
||||||
P extends string = ConvertPathType<R['path']>
|
P extends string = ConvertPathType<R['path']>
|
||||||
>(
|
>(
|
||||||
route: R,
|
route: R,
|
||||||
handler: Handler<E, P, I, HandlerResponse<OutputType<R>>>,
|
handler: RouteHandler<R, E, I, P>,
|
||||||
hook?: Hook<I, E, P, OutputType<R>>
|
hook?: RouteHook<R, E, I, P>
|
||||||
): OpenAPIHono<E, ToSchema<R['method'], P, I['in'], OutputType<R>>, BasePath> => {
|
): OpenAPIHono<E, ToSchema<R['method'], P, I['in'], OutputType<R>>, BasePath> => {
|
||||||
this.openAPIRegistry.registerPath(route)
|
this.openAPIRegistry.registerPath(route)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue