import { OpenAPIRegistry, OpenApiGeneratorV3, RouteConfig as RouteConfig$1, ZodContentObject, ZodMediaTypeObject, ZodRequestBody, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi"; import { Context, Env, ErrorHandler, Handler, Hono, Input, MiddlewareHandler, NotFoundHandler, Schema, ToSchema, TypedResponse, ValidationTargets } from "hono"; import { ZodError, ZodType, z } from "zod"; import { H, MergePath, MergeSchemaPath } from "hono/types"; import { ClientErrorStatusCode, InfoStatusCode, RedirectStatusCode, ServerErrorStatusCode, StatusCode, SuccessStatusCode } from "hono/utils/http-status"; import { JSONParsed, RemoveBlankRecord } from "hono/utils/types"; import { OpenAPIObject } from "openapi3-ts/oas30"; import { OpenAPIObject as OpenAPIObject$1 } from "openapi3-ts/oas31"; //#region src/index.d.ts type MaybePromise = Promise | T$1; type RouteConfig = RouteConfig$1 & { middleware?: H | H[]; hide?: boolean; }; type RequestTypes = { body?: ZodRequestBody; params?: ZodType; query?: ZodType; cookies?: ZodType; headers?: ZodType | ZodType[]; }; type IsJson = T$1 extends string ? T$1 extends `application/${infer Start}json${infer _End}` ? Start extends "" | `${string}+` | `vnd.${string}+` ? "json" : never : never : never; type IsForm = T$1 extends string ? T$1 extends `multipart/form-data${infer _Rest}` | `application/x-www-form-urlencoded${infer _Rest}` ? "form" : never : never; type ReturnJsonOrTextOrResponse = ContentType extends string ? ContentType extends `application/${infer Start}json${infer _End}` ? Start extends "" | `${string}+` | `vnd.${string}+` ? TypedResponse, ExtractStatusCode, "json"> : never : ContentType extends `text/plain${infer _Rest}` ? TypedResponse, "text"> : Response : never; type RequestPart = Part extends keyof R$1["request"] ? R$1["request"][Part] : {}; type HasUndefined = undefined extends T$1 ? true : false; type InputTypeBase = R$1["request"] extends RequestTypes ? RequestPart extends ZodType ? { in: { [K in Type]: HasUndefined extends true ? { [K2 in keyof z.input>]?: z.input>[K2] } : { [K2 in keyof z.input>]: z.input>[K2] } }; out: { [K in Type]: z.output> }; } : {} : {}; type InputTypeJson = R$1["request"] extends RequestTypes ? R$1["request"]["body"] extends ZodRequestBody ? R$1["request"]["body"]["content"] extends ZodContentObject ? IsJson extends never ? {} : R$1["request"]["body"]["content"][keyof R$1["request"]["body"]["content"]] extends Record<"schema", ZodType> ? { in: { json: z.input; }; out: { json: z.output; }; } : {} : {} : {} : {}; type InputTypeForm = R$1["request"] extends RequestTypes ? R$1["request"]["body"] extends ZodRequestBody ? R$1["request"]["body"]["content"] extends ZodContentObject ? IsForm extends never ? {} : R$1["request"]["body"]["content"][keyof R$1["request"]["body"]["content"]] extends Record<"schema", ZodType> ? { in: { form: z.input; }; out: { form: z.output; }; } : {} : {} : {} : {}; type InputTypeParam = InputTypeBase; type InputTypeQuery = InputTypeBase; type InputTypeHeader = InputTypeBase; type InputTypeCookie = InputTypeBase; type ExtractContent = T$1 extends { [K in keyof T$1]: infer A } ? A extends Record<"schema", ZodType> ? z.infer : never : never; type StatusCodeRangeDefinitions = { "1XX": InfoStatusCode; "2XX": SuccessStatusCode; "3XX": RedirectStatusCode; "4XX": ClientErrorStatusCode; "5XX": ServerErrorStatusCode; }; type RouteConfigStatusCode = keyof StatusCodeRangeDefinitions | StatusCode; type ExtractStatusCode = T$1 extends keyof StatusCodeRangeDefinitions ? StatusCodeRangeDefinitions[T$1] : T$1; type DefinedStatusCodes = keyof R$1["responses"] & RouteConfigStatusCode; type RouteConfigToTypedResponse = { [Status in DefinedStatusCodes]: R$1["responses"][Status] extends { content: infer Content; } ? undefined extends Content ? never : ReturnJsonOrTextOrResponse, Status> : TypedResponse<{}, ExtractStatusCode, string> }[DefinedStatusCodes] | ("default" extends keyof R$1["responses"] ? R$1["responses"]["default"] extends { content: infer Content; } ? undefined extends Content ? never : ReturnJsonOrTextOrResponse, Exclude>>> : TypedResponse<{}, Exclude>>, string> : never); type Hook = (result: { target: keyof ValidationTargets; } & ({ success: true; data: T$1; } | { success: false; error: ZodError; }), c: Context) => R$1; type ConvertPathType = T$1 extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${ConvertPathType}` : T$1; type OpenAPIHonoOptions = { defaultHook?: Hook; }; type HonoInit = ConstructorParameters[0] & OpenAPIHonoOptions; /** * Turns `T | T[] | undefined` into `T[]` */ type AsArray = T$1 extends undefined ? [] : T$1 extends any[] ? T$1 : [T$1]; /** * Like simplify but recursive */ type DeepSimplify = { [KeyType in keyof T$1]: T$1[KeyType] extends Record ? DeepSimplify : T$1[KeyType] } & {}; /** * Helper to infer generics from {@link MiddlewareHandler} */ type OfHandlerType = T$1 extends MiddlewareHandler ? { env: E; path: P; input: I; } : never; /** * Reduce a tuple of middleware handlers into a single * handler representing the composition of all * handlers. */ type MiddlewareToHandlerType[]> = M extends [infer First, infer Second, ...infer Rest] ? First extends MiddlewareHandler ? Second extends MiddlewareHandler ? Rest extends MiddlewareHandler[] ? MiddlewareToHandlerType<[MiddlewareHandler["env"] & OfHandlerType["env"]>, OfHandlerType["path"], OfHandlerType["input"]>, ...Rest]> : never : never : never : M extends [infer Last] ? Last : MiddlewareHandler; type RouteMiddlewareParams = OfHandlerType>>; type RouteConfigToEnv = RouteMiddlewareParams extends never ? Env : RouteMiddlewareParams["env"]; type RouteHandler, I$1 extends Input = InputTypeParam & InputTypeQuery & InputTypeHeader & InputTypeCookie & InputTypeForm & InputTypeJson, P$1 extends string = ConvertPathType> = Handler> : MaybePromise> | MaybePromise>; type RouteHook, I$1 extends Input = InputTypeParam & InputTypeQuery & InputTypeHeader & InputTypeCookie & InputTypeForm & InputTypeJson, P$1 extends string = ConvertPathType> = Hook | Response | Promise | void | Promise>; type OpenAPIObjectConfig = Parameters["generateDocument"]>[0]; type OpenAPIObjectConfigure = OpenAPIObjectConfig | ((context: Context) => OpenAPIObjectConfig); type OpenAPIGeneratorOptions = ConstructorParameters[1]; type OpenAPIGeneratorConfigure = OpenAPIGeneratorOptions | ((context: Context) => OpenAPIGeneratorOptions); /** * Utility type to convert Hono types to OpenAPIHono types. * Replaces Hono return types with OpenAPIHono in function signatures. * * @example * ```ts * type MyOpenAPIHono = HonoToOpenAPIHono> * ``` */ type HonoToOpenAPIHono = T$1 extends Hono ? OpenAPIHono : T$1; /** * Converts a Hono instance to OpenAPIHono type. * Use this function to restore the OpenAPIHono type after chaining methods like `get`, `post`, `use`, etc. * @example * ```ts * import { OpenAPIHono, $ } from '@hono/zod-openapi' * * const app = $( * new OpenAPIHono().use(middleware) * ) * app.openapi(route, handler) * ``` */ declare const $: >(app: T) => HonoToOpenAPIHono; type ComputeInput = InputTypeParam & InputTypeQuery & InputTypeHeader & InputTypeCookie & InputTypeForm & InputTypeJson; type HandlerFromRoute = Handler, ComputeInput, R$1 extends { responses: { [statusCode: number]: { content: { [mediaType: string]: ZodMediaTypeObject; }; }; }; } ? MaybePromise> : MaybePromise> | MaybePromise>; type HookFromRoute = Hook, E$1, ConvertPathType, R$1 extends { responses: { [statusCode: number]: { content: { [mediaType: string]: ZodMediaTypeObject; }; }; }; } ? MaybePromise> | undefined : MaybePromise> | MaybePromise | undefined> | undefined; type SchemaFromRoutes = Routes extends readonly [infer Head, ...infer Tail] ? Head extends { route: infer R extends RouteConfig; addRoute?: infer AddRoute; } ? ([AddRoute] extends [false] ? {} : ToSchema>, ComputeInput, RouteConfigToTypedResponse>) & SchemaFromRoutes : {} : {}; type OpenAPIRoute = { route: R$1; handler: HandlerFromRoute; hook?: HookFromRoute; addRoute?: AddRoute$1; }; declare const defineOpenAPIRoute: (def: OpenAPIRoute) => OpenAPIRoute; declare class OpenAPIHono extends Hono { openAPIRegistry: OpenAPIRegistry; defaultHook?: OpenAPIHonoOptions["defaultHook"]; constructor(init?: HonoInit); /** * * @param {RouteConfig} route - The route definition which you create with `createRoute()`. * @param {Handler} handler - The handler. If you want to return a JSON object, you should specify the status code with `c.json()`. * @param {Hook} hook - Optional. The hook method defines what it should do after validation. * @example * app.openapi( * route, * (c) => { * // ... * return c.json( * { * age: 20, * name: 'Young man', * }, * 200 // You should specify the status code even if it's 200. * ) * }, * (result, c) => { * if (!result.success) { * return c.json( * { * code: 400, * message: 'Custom Message', * }, * 400 * ) * } * } *) */ openapi: & InputTypeQuery & InputTypeHeader & InputTypeCookie & InputTypeForm & InputTypeJson, P extends string = ConvertPathType>({ middleware: routeMiddleware, hide, ...route }: R, handler: Handler["env"] & E$1 : E$1, P, I, R extends { responses: { [statusCode: number]: { content: { [mediaType: string]: ZodMediaTypeObject; }; }; }; } ? MaybePromise> : MaybePromise> | MaybePromise>, hook?: Hook> | undefined : MaybePromise> | MaybePromise | undefined> | undefined) => OpenAPIHono, I, RouteConfigToTypedResponse>, BasePath>; /** * Register a list of routes with full Type Safety and RPC support. * * @param inputs - An array of objects containing { route, handler, hook }. * Must be defined `as const` or inline to preserve tuple types. */ openapiRoutes: (inputs: Inputs) => OpenAPIHono, BasePath>; getOpenAPIDocument: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject; getOpenAPI31Document: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject$1; doc:

(path: P, configureObject: OpenAPIObjectConfigure, configureGenerator?: OpenAPIGeneratorConfigure) => OpenAPIHono, {}, {}>, BasePath>; doc31:

(path: P, configureObject: OpenAPIObjectConfigure, configureGenerator?: OpenAPIGeneratorConfigure) => OpenAPIHono, {}, {}>, BasePath>; route(path: SubPath, app: Hono): OpenAPIHono> & S$1, BasePath>; route(path: SubPath): Hono, BasePath>; basePath(path: SubPath): OpenAPIHono>; onError: (handler: ErrorHandler) => OpenAPIHono; notFound: (handler: NotFoundHandler) => OpenAPIHono; } type RoutingPath = P$1 extends `${infer Head}/{${infer Param}}${infer Tail}` ? `${Head}/:${Param}${RoutingPath}` : P$1; declare const createRoute:

& { path: P; }>(routeConfig: R) => R & { getRoutingPath(): RoutingPath; }; //#endregion export { $, DeepSimplify, HonoToOpenAPIHono, Hook, MiddlewareToHandlerType, OfHandlerType, OpenAPIGeneratorConfigure, OpenAPIGeneratorOptions, OpenAPIHono, OpenAPIHonoOptions, OpenAPIObjectConfigure, OpenAPIRoute, RouteConfig, RouteConfigToEnv, RouteConfigToTypedResponse, RouteHandler, RouteHook, createRoute, defineOpenAPIRoute, extendZodWithOpenApi, z }; //# sourceMappingURL=index.d.ts.map