@hono/zod-openapi 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -107,11 +107,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
107
107
  app.openAPIRegistry.definitions.forEach((def) => {
108
108
  switch (def.type) {
109
109
  case "component":
110
- return this.openAPIRegistry.registerComponent(
111
- def.componentType,
112
- def.name,
113
- def.component
114
- );
110
+ return this.openAPIRegistry.registerComponent(def.componentType, def.name, def.component);
115
111
  case "route":
116
112
  return this.openAPIRegistry.registerPath({
117
113
  ...def.route,
@@ -123,10 +119,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
123
119
  path: `${path}${def.webhook.path}`
124
120
  });
125
121
  case "schema":
126
- return this.openAPIRegistry.register(
127
- def.schema._def.openapi._internal.refId,
128
- def.schema
129
- );
122
+ return this.openAPIRegistry.register(def.schema._def.openapi._internal.refId, def.schema);
130
123
  case "parameter":
131
124
  return this.openAPIRegistry.registerParameter(
132
125
  def.schema._def.openapi._internal.refId,
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
- import { OpenAPIRegistry, RouteConfig, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
3
+ import { RouteConfig, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Schema, Hono, Input, Handler, ToSchema, Context, TypedResponse } from 'hono';
5
+ import { Env, Input, Handler, Schema, Hono, ToSchema, Context, TypedResponse } from 'hono';
6
6
  import { MergeSchemaPath, MergePath } from 'hono/dist/types/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
8
  import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
@@ -23,7 +23,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
23
23
  [K in Type]: z.input<RequestPart<R, Part>>;
24
24
  };
25
25
  out: {
26
- [K in Type]: z.input<RequestPart<R, Part>>;
26
+ [K in Type]: z.output<RequestPart<R, Part>>;
27
27
  };
28
28
  } : {} : {};
29
29
  type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ? R['request']['body'] extends ZodRequestBody ? R['request']['body']['content'] extends ZodContentObject ? IsJson<keyof R['request']['body']['content']> extends never ? {} : R['request']['body']['content'][keyof R['request']['body']['content']]['schema'] extends ZodSchema<any> ? {
@@ -31,7 +31,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
31
31
  json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
32
32
  };
33
33
  out: {
34
- json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
34
+ json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
35
35
  };
36
36
  } : {} : {} : {} : {};
37
37
  type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ? R['request']['body'] extends ZodRequestBody ? R['request']['body']['content'] extends ZodContentObject ? IsForm<keyof R['request']['body']['content']> extends never ? {} : R['request']['body']['content'][keyof R['request']['body']['content']]['schema'] extends ZodSchema<any> ? {
@@ -39,9 +39,13 @@ type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ?
39
39
  form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
40
40
  };
41
41
  out: {
42
- form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
42
+ form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
43
43
  };
44
44
  } : {} : {} : {} : {};
45
+ type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>;
46
+ type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
47
+ type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
48
+ type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
45
49
  type OutputType<R extends RouteConfig> = R['responses'] extends Record<infer _, infer C> ? C extends ResponseConfig ? C['content'] extends ZodContentObject ? IsJson<keyof C['content']> extends never ? {} : C['content'][keyof C['content']]['schema'] extends ZodSchema ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
46
50
  type Hook<T, E extends Env, P extends string, O> = (result: {
47
51
  success: true;
@@ -53,10 +57,12 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
53
57
  type ConvertPathType<T extends string> = T extends `${infer _}/{${infer Param}}${infer _}` ? `/:${Param}` : T;
54
58
  type HandlerResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
55
59
  type HonoInit = ConstructorParameters<typeof Hono>[0];
60
+ 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>>>;
61
+ 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>>;
56
62
  declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
57
63
  openAPIRegistry: OpenAPIRegistry;
58
64
  constructor(init?: HonoInit);
59
- openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: Handler<E, P, I, HandlerResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
65
+ openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: RouteHandler<R, E, I, P>, hook?: RouteHook<R, E, I, P> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
60
66
  getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
61
67
  getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
62
68
  doc: (path: string, config: OpenAPIObjectConfig) => void;
@@ -71,4 +77,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
71
77
  getRoutingPath(): RoutingPath<R["path"]>;
72
78
  };
73
79
 
74
- export { OpenAPIHono, createRoute };
80
+ export { OpenAPIHono, RouteHandler, RouteHook, createRoute };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
- import { OpenAPIRegistry, RouteConfig, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
3
+ import { RouteConfig, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Schema, Hono, Input, Handler, ToSchema, Context, TypedResponse } from 'hono';
5
+ import { Env, Input, Handler, Schema, Hono, ToSchema, Context, TypedResponse } from 'hono';
6
6
  import { MergeSchemaPath, MergePath } from 'hono/dist/types/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
8
  import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
@@ -23,7 +23,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
23
23
  [K in Type]: z.input<RequestPart<R, Part>>;
24
24
  };
25
25
  out: {
26
- [K in Type]: z.input<RequestPart<R, Part>>;
26
+ [K in Type]: z.output<RequestPart<R, Part>>;
27
27
  };
28
28
  } : {} : {};
29
29
  type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ? R['request']['body'] extends ZodRequestBody ? R['request']['body']['content'] extends ZodContentObject ? IsJson<keyof R['request']['body']['content']> extends never ? {} : R['request']['body']['content'][keyof R['request']['body']['content']]['schema'] extends ZodSchema<any> ? {
@@ -31,7 +31,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
31
31
  json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
32
32
  };
33
33
  out: {
34
- json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
34
+ json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
35
35
  };
36
36
  } : {} : {} : {} : {};
37
37
  type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ? R['request']['body'] extends ZodRequestBody ? R['request']['body']['content'] extends ZodContentObject ? IsForm<keyof R['request']['body']['content']> extends never ? {} : R['request']['body']['content'][keyof R['request']['body']['content']]['schema'] extends ZodSchema<any> ? {
@@ -39,9 +39,13 @@ type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ?
39
39
  form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
40
40
  };
41
41
  out: {
42
- form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
42
+ form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
43
43
  };
44
44
  } : {} : {} : {} : {};
45
+ type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>;
46
+ type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
47
+ type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
48
+ type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
45
49
  type OutputType<R extends RouteConfig> = R['responses'] extends Record<infer _, infer C> ? C extends ResponseConfig ? C['content'] extends ZodContentObject ? IsJson<keyof C['content']> extends never ? {} : C['content'][keyof C['content']]['schema'] extends ZodSchema ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
46
50
  type Hook<T, E extends Env, P extends string, O> = (result: {
47
51
  success: true;
@@ -53,10 +57,12 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
53
57
  type ConvertPathType<T extends string> = T extends `${infer _}/{${infer Param}}${infer _}` ? `/:${Param}` : T;
54
58
  type HandlerResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
55
59
  type HonoInit = ConstructorParameters<typeof Hono>[0];
60
+ 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>>>;
61
+ 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>>;
56
62
  declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
57
63
  openAPIRegistry: OpenAPIRegistry;
58
64
  constructor(init?: HonoInit);
59
- openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: Handler<E, P, I, HandlerResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
65
+ openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: RouteHandler<R, E, I, P>, hook?: RouteHook<R, E, I, P> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
60
66
  getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
61
67
  getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
62
68
  doc: (path: string, config: OpenAPIObjectConfig) => void;
@@ -71,4 +77,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
71
77
  getRoutingPath(): RoutingPath<R["path"]>;
72
78
  };
73
79
 
74
- export { OpenAPIHono, createRoute };
80
+ export { OpenAPIHono, RouteHandler, RouteHook, createRoute };
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  // src/index.ts
2
- import { OpenApiGeneratorV3, OpenApiGeneratorV31, OpenAPIRegistry } from "@asteasolutions/zod-to-openapi";
2
+ import {
3
+ OpenApiGeneratorV3,
4
+ OpenApiGeneratorV31,
5
+ OpenAPIRegistry
6
+ } from "@asteasolutions/zod-to-openapi";
3
7
  import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
4
8
  import { zValidator } from "@hono/zod-validator";
5
9
  import { Hono } from "hono";
@@ -81,11 +85,7 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
81
85
  app.openAPIRegistry.definitions.forEach((def) => {
82
86
  switch (def.type) {
83
87
  case "component":
84
- return this.openAPIRegistry.registerComponent(
85
- def.componentType,
86
- def.name,
87
- def.component
88
- );
88
+ return this.openAPIRegistry.registerComponent(def.componentType, def.name, def.component);
89
89
  case "route":
90
90
  return this.openAPIRegistry.registerPath({
91
91
  ...def.route,
@@ -97,10 +97,7 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
97
97
  path: `${path}${def.webhook.path}`
98
98
  });
99
99
  case "schema":
100
- return this.openAPIRegistry.register(
101
- def.schema._def.openapi._internal.refId,
102
- def.schema
103
- );
100
+ return this.openAPIRegistry.register(def.schema._def.openapi._internal.refId, def.schema);
104
101
  case "parameter":
105
102
  return this.openAPIRegistry.registerParameter(
106
103
  def.schema._def.openapi._internal.refId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "zod": "3.*"
32
32
  },
33
33
  "devDependencies": {
34
- "hono": "^3.5.8",
34
+ "hono": "^3.6.3",
35
35
  "zod": "^3.22.1"
36
36
  },
37
37
  "dependencies": {