@hono/zod-openapi 0.9.0 → 0.9.2
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 +24 -7
- package/dist/index.d.ts +24 -7
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
2
|
import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
|
|
3
|
-
import { RouteConfig, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
|
|
3
|
+
import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
|
|
4
4
|
import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
|
|
5
5
|
import { Env, Input, Handler, Context, Schema, Hono, ToSchema, TypedResponse } from 'hono';
|
|
6
6
|
import { MergeSchemaPath, MergePath } from 'hono/types';
|
|
@@ -20,7 +20,7 @@ type IsForm<T> = T extends string ? T extends `multipart/form-data${infer _Rest}
|
|
|
20
20
|
type RequestPart<R extends RouteConfig, Part extends string> = Part extends keyof R['request'] ? R['request'][Part] : {};
|
|
21
21
|
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends AnyZodObject ? {
|
|
22
22
|
in: {
|
|
23
|
-
[K in Type]: z.
|
|
23
|
+
[K in Type]: z.input<RequestPart<R, Part>>;
|
|
24
24
|
};
|
|
25
25
|
out: {
|
|
26
26
|
[K in Type]: z.output<RequestPart<R, Part>>;
|
|
@@ -28,7 +28,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
|
|
|
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> ? {
|
|
30
30
|
in: {
|
|
31
|
-
json: z.
|
|
31
|
+
json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
32
32
|
};
|
|
33
33
|
out: {
|
|
34
34
|
json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
@@ -36,7 +36,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
|
|
|
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> ? {
|
|
38
38
|
in: {
|
|
39
|
-
form: z.
|
|
39
|
+
form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
40
40
|
};
|
|
41
41
|
out: {
|
|
42
42
|
form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
@@ -55,19 +55,36 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
55
55
|
error: ZodError;
|
|
56
56
|
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void;
|
|
57
57
|
type ConvertPathType<T extends string> = T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${ConvertPathType<Rest>}` : T;
|
|
58
|
-
type
|
|
58
|
+
type HandlerTypedResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
|
+
type HandlerAllResponse<O> = Response | Promise<Response> | TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
60
|
type OpenAPIHonoOptions<E extends Env> = {
|
|
60
61
|
defaultHook?: Hook<any, E, any, any>;
|
|
61
62
|
};
|
|
62
63
|
type HonoInit<E extends Env> = ConstructorParameters<typeof Hono>[0] & OpenAPIHonoOptions<E>;
|
|
63
|
-
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,
|
|
64
|
+
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, R extends {
|
|
65
|
+
responses: {
|
|
66
|
+
[statusCode: string]: {
|
|
67
|
+
content: {
|
|
68
|
+
[mediaType: string]: ZodMediaTypeObject;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
} ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>;
|
|
64
73
|
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>>;
|
|
65
74
|
type OpenAPIObjectConfigure<E extends Env, P extends string> = OpenAPIObjectConfig | ((context: Context<E, P>) => OpenAPIObjectConfig);
|
|
66
75
|
declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
|
|
67
76
|
openAPIRegistry: OpenAPIRegistry;
|
|
68
77
|
defaultHook?: OpenAPIHonoOptions<E>['defaultHook'];
|
|
69
78
|
constructor(init?: HonoInit<E>);
|
|
70
|
-
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,
|
|
79
|
+
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, R extends {
|
|
80
|
+
responses: {
|
|
81
|
+
[statusCode: string]: {
|
|
82
|
+
content: {
|
|
83
|
+
[mediaType: string]: ZodMediaTypeObject;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
} ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
|
|
71
88
|
getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
|
|
72
89
|
getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
|
|
73
90
|
doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
2
|
import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
|
|
3
|
-
import { RouteConfig, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
|
|
3
|
+
import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
|
|
4
4
|
import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
|
|
5
5
|
import { Env, Input, Handler, Context, Schema, Hono, ToSchema, TypedResponse } from 'hono';
|
|
6
6
|
import { MergeSchemaPath, MergePath } from 'hono/types';
|
|
@@ -20,7 +20,7 @@ type IsForm<T> = T extends string ? T extends `multipart/form-data${infer _Rest}
|
|
|
20
20
|
type RequestPart<R extends RouteConfig, Part extends string> = Part extends keyof R['request'] ? R['request'][Part] : {};
|
|
21
21
|
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends AnyZodObject ? {
|
|
22
22
|
in: {
|
|
23
|
-
[K in Type]: z.
|
|
23
|
+
[K in Type]: z.input<RequestPart<R, Part>>;
|
|
24
24
|
};
|
|
25
25
|
out: {
|
|
26
26
|
[K in Type]: z.output<RequestPart<R, Part>>;
|
|
@@ -28,7 +28,7 @@ type InputTypeBase<R extends RouteConfig, Part extends string, Type extends stri
|
|
|
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> ? {
|
|
30
30
|
in: {
|
|
31
|
-
json: z.
|
|
31
|
+
json: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
32
32
|
};
|
|
33
33
|
out: {
|
|
34
34
|
json: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
@@ -36,7 +36,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes ?
|
|
|
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> ? {
|
|
38
38
|
in: {
|
|
39
|
-
form: z.
|
|
39
|
+
form: z.input<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
40
40
|
};
|
|
41
41
|
out: {
|
|
42
42
|
form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
@@ -55,19 +55,36 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
55
55
|
error: ZodError;
|
|
56
56
|
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void;
|
|
57
57
|
type ConvertPathType<T extends string> = T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${ConvertPathType<Rest>}` : T;
|
|
58
|
-
type
|
|
58
|
+
type HandlerTypedResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
|
+
type HandlerAllResponse<O> = Response | Promise<Response> | TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
60
|
type OpenAPIHonoOptions<E extends Env> = {
|
|
60
61
|
defaultHook?: Hook<any, E, any, any>;
|
|
61
62
|
};
|
|
62
63
|
type HonoInit<E extends Env> = ConstructorParameters<typeof Hono>[0] & OpenAPIHonoOptions<E>;
|
|
63
|
-
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,
|
|
64
|
+
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, R extends {
|
|
65
|
+
responses: {
|
|
66
|
+
[statusCode: string]: {
|
|
67
|
+
content: {
|
|
68
|
+
[mediaType: string]: ZodMediaTypeObject;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
} ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>;
|
|
64
73
|
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>>;
|
|
65
74
|
type OpenAPIObjectConfigure<E extends Env, P extends string> = OpenAPIObjectConfig | ((context: Context<E, P>) => OpenAPIObjectConfig);
|
|
66
75
|
declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
|
|
67
76
|
openAPIRegistry: OpenAPIRegistry;
|
|
68
77
|
defaultHook?: OpenAPIHonoOptions<E>['defaultHook'];
|
|
69
78
|
constructor(init?: HonoInit<E>);
|
|
70
|
-
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,
|
|
79
|
+
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, R extends {
|
|
80
|
+
responses: {
|
|
81
|
+
[statusCode: string]: {
|
|
82
|
+
content: {
|
|
83
|
+
[mediaType: string]: ZodMediaTypeObject;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
} ? HandlerTypedResponse<OutputType<R>> : HandlerAllResponse<OutputType<R>>>, hook?: Hook<I, E, P, OutputType<R>> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
|
|
71
88
|
getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
|
|
72
89
|
getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
|
|
73
90
|
doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/zod-openapi",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "A wrapper class of Hono which supports OpenAPI.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "vitest run",
|
|
12
|
+
"test": "vitest run && vitest typecheck --run --passWithNoTests",
|
|
13
13
|
"build": "tsup ./src/index.ts --format esm,cjs --dts",
|
|
14
14
|
"publint": "publint",
|
|
15
15
|
"release": "yarn build && yarn test && yarn publint && yarn publish"
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/honojs/middleware",
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"hono": ">=3.
|
|
41
|
+
"hono": ">=3.11.1",
|
|
42
42
|
"zod": "3.*"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@hono/zod-validator": "^0.1.11",
|
|
46
|
-
"hono": "^3.
|
|
46
|
+
"hono": "^3.11.1",
|
|
47
47
|
"zod": "^3.22.1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=16.0.0"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|