@hono/zod-openapi 0.9.9 → 0.10.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.d.mts CHANGED
@@ -26,7 +26,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
26
26
  [K in Type]: z.output<RequestPart<R, Part>>;
27
27
  };
28
28
  } : {} : {};
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> ? {
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']] extends Record<'schema', ZodSchema<any>> ? {
30
30
  in: {
31
31
  json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
32
32
  };
@@ -34,7 +34,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
34
34
  json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
35
35
  };
36
36
  } : {} : {} : {} : {};
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> ? {
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']] extends Record<'schema', ZodSchema<any>> ? {
38
38
  in: {
39
39
  form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
40
40
  };
@@ -46,7 +46,7 @@ type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>
46
46
  type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
47
47
  type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
48
48
  type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
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']> : {} : {} : {} : {};
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']] extends Record<'schema', ZodSchema> ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
50
50
  type Hook<T, E extends Env, P extends string, O> = (result: {
51
51
  success: true;
52
52
  data: T;
@@ -84,11 +84,11 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
84
84
  };
85
85
  };
86
86
  };
87
- } ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], MergePath<BasePath, P>, I["in"], OutputType<R>>, BasePath>;
87
+ } ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R['method'], MergePath<BasePath, P>, I['in'], OutputType<R>>, BasePath>;
88
88
  getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
89
89
  getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
90
- doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
91
- doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
90
+ doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<'get', P, {}, {}>, BasePath>;
91
+ doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<'get', P, {}, {}>, BasePath>;
92
92
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
93
93
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
94
94
  basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>>;
@@ -97,7 +97,7 @@ type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${
97
97
  declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"> & {
98
98
  path: P;
99
99
  }>(routeConfig: R) => R & {
100
- getRoutingPath(): RoutingPath<R["path"]>;
100
+ getRoutingPath(): RoutingPath<R['path']>;
101
101
  };
102
102
 
103
103
  export { type Hook, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteHandler, type RouteHook, createRoute };
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
26
26
  [K in Type]: z.output<RequestPart<R, Part>>;
27
27
  };
28
28
  } : {} : {};
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> ? {
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']] extends Record<'schema', ZodSchema<any>> ? {
30
30
  in: {
31
31
  json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
32
32
  };
@@ -34,7 +34,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
34
34
  json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
35
35
  };
36
36
  } : {} : {} : {} : {};
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> ? {
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']] extends Record<'schema', ZodSchema<any>> ? {
38
38
  in: {
39
39
  form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
40
40
  };
@@ -46,7 +46,7 @@ type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>
46
46
  type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
47
47
  type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
48
48
  type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
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']> : {} : {} : {} : {};
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']] extends Record<'schema', ZodSchema> ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
50
50
  type Hook<T, E extends Env, P extends string, O> = (result: {
51
51
  success: true;
52
52
  data: T;
@@ -84,11 +84,11 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
84
84
  };
85
85
  };
86
86
  };
87
- } ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], MergePath<BasePath, P>, I["in"], OutputType<R>>, BasePath>;
87
+ } ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R['method'], MergePath<BasePath, P>, I['in'], OutputType<R>>, BasePath>;
88
88
  getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
89
89
  getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
90
- doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
91
- doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
90
+ doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<'get', P, {}, {}>, BasePath>;
91
+ doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<'get', P, {}, {}>, BasePath>;
92
92
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
93
93
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
94
94
  basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>>;
@@ -97,7 +97,7 @@ type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${
97
97
  declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"> & {
98
98
  path: P;
99
99
  }>(routeConfig: R) => R & {
100
- getRoutingPath(): RoutingPath<R["path"]>;
100
+ getRoutingPath(): RoutingPath<R['path']>;
101
101
  };
102
102
 
103
103
  export { type Hook, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteHandler, type RouteHook, createRoute };
package/dist/index.js CHANGED
@@ -61,19 +61,20 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
61
61
  const bodyContent = route.request?.body?.content;
62
62
  if (bodyContent) {
63
63
  for (const mediaType of Object.keys(bodyContent)) {
64
+ if (!bodyContent[mediaType]) {
65
+ continue;
66
+ }
67
+ const schema = bodyContent[mediaType]["schema"];
68
+ if (!(schema instanceof import_zod.ZodType)) {
69
+ continue;
70
+ }
64
71
  if (mediaType.startsWith("application/json")) {
65
- const schema = bodyContent[mediaType]["schema"];
66
- if (schema instanceof import_zod.ZodType) {
67
- const validator = (0, import_zod_validator.zValidator)("json", schema, hook);
68
- validators.push(validator);
69
- }
72
+ const validator = (0, import_zod_validator.zValidator)("json", schema, hook);
73
+ validators.push(validator);
70
74
  }
71
75
  if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
72
- const schema = bodyContent[mediaType]["schema"];
73
- if (schema instanceof import_zod.ZodType) {
74
- const validator = (0, import_zod_validator.zValidator)("form", schema, hook);
75
- validators.push(validator);
76
- }
76
+ const validator = (0, import_zod_validator.zValidator)("form", schema, hook);
77
+ validators.push(validator);
77
78
  }
78
79
  }
79
80
  }
package/dist/index.mjs CHANGED
@@ -39,19 +39,20 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
39
39
  const bodyContent = route.request?.body?.content;
40
40
  if (bodyContent) {
41
41
  for (const mediaType of Object.keys(bodyContent)) {
42
+ if (!bodyContent[mediaType]) {
43
+ continue;
44
+ }
45
+ const schema = bodyContent[mediaType]["schema"];
46
+ if (!(schema instanceof ZodType)) {
47
+ continue;
48
+ }
42
49
  if (mediaType.startsWith("application/json")) {
43
- const schema = bodyContent[mediaType]["schema"];
44
- if (schema instanceof ZodType) {
45
- const validator = zValidator("json", schema, hook);
46
- validators.push(validator);
47
- }
50
+ const validator = zValidator("json", schema, hook);
51
+ validators.push(validator);
48
52
  }
49
53
  if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
50
- const schema = bodyContent[mediaType]["schema"];
51
- if (schema instanceof ZodType) {
52
- const validator = zValidator("form", schema, hook);
53
- validators.push(validator);
54
- }
54
+ const validator = zValidator("form", schema, hook);
55
+ validators.push(validator);
55
56
  }
56
57
  }
57
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.9.9",
3
+ "version": "0.10.0",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -42,17 +42,17 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@cloudflare/workers-types": "^4.20240117.0",
45
- "hono": "^3.11.7",
45
+ "hono": "^4.2.2",
46
46
  "jest": "^29.7.0",
47
47
  "openapi3-ts": "^4.1.2",
48
48
  "tsup": "^8.0.1",
49
- "typescript": "^5.3.3",
50
- "vitest": "^1.0.1",
49
+ "typescript": "^5.4.4",
50
+ "vitest": "^1.4.0",
51
51
  "zod": "^3.22.1"
52
52
  },
53
53
  "dependencies": {
54
- "@asteasolutions/zod-to-openapi": "^5.5.0",
55
- "@hono/zod-validator": "0.1.11"
54
+ "@asteasolutions/zod-to-openapi": "^7.0.0",
55
+ "@hono/zod-validator": "0.2.1"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=16.0.0"