@hono/zod-openapi 0.14.1 → 0.14.3
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 +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +3 -4
- package/dist/index.mjs +5 -5
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { MiddlewareHandler, TypedResponse, Env, Context, Input, Handler, Schema,
|
|
|
6
6
|
import { MergePath, MergeSchemaPath } from 'hono/types';
|
|
7
7
|
import { StatusCode, InfoStatusCode, SuccessStatusCode, RedirectStatusCode, ClientErrorStatusCode, ServerErrorStatusCode } from 'hono/utils/http-status';
|
|
8
8
|
import { RemoveBlankRecord } from 'hono/utils/types';
|
|
9
|
-
import { ZodError,
|
|
9
|
+
import { ZodError, ZodType, z, ZodSchema } from 'zod';
|
|
10
10
|
export { z } from 'zod';
|
|
11
11
|
|
|
12
12
|
type MaybePromise<T> = Promise<T> | T;
|
|
@@ -15,15 +15,15 @@ type RouteConfig = RouteConfig$1 & {
|
|
|
15
15
|
};
|
|
16
16
|
type RequestTypes = {
|
|
17
17
|
body?: ZodRequestBody;
|
|
18
|
-
params?:
|
|
19
|
-
query?:
|
|
20
|
-
cookies?:
|
|
21
|
-
headers?:
|
|
18
|
+
params?: ZodType;
|
|
19
|
+
query?: ZodType;
|
|
20
|
+
cookies?: ZodType;
|
|
21
|
+
headers?: ZodType | ZodType[];
|
|
22
22
|
};
|
|
23
23
|
type IsJson<T> = T extends string ? T extends `application/json${infer _Rest}` ? 'json' : never : never;
|
|
24
24
|
type IsForm<T> = T extends string ? T extends `multipart/form-data${infer _Rest}` | `application/x-www-form-urlencoded${infer _Rest}` ? 'form' : never : never;
|
|
25
25
|
type RequestPart<R extends RouteConfig, Part extends string> = Part extends keyof R['request'] ? R['request'][Part] : {};
|
|
26
|
-
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends
|
|
26
|
+
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends ZodType ? {
|
|
27
27
|
in: {
|
|
28
28
|
[K in Type]: z.input<RequestPart<R, Part>>;
|
|
29
29
|
};
|
|
@@ -124,7 +124,7 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
|
|
|
124
124
|
* }
|
|
125
125
|
*)
|
|
126
126
|
*/
|
|
127
|
-
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 {
|
|
127
|
+
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"]>>({ middleware: routeMiddleware, ...route }: R, handler: Handler<E, P, I, R extends {
|
|
128
128
|
responses: {
|
|
129
129
|
[statusCode: number]: {
|
|
130
130
|
content: {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { MiddlewareHandler, TypedResponse, Env, Context, Input, Handler, Schema,
|
|
|
6
6
|
import { MergePath, MergeSchemaPath } from 'hono/types';
|
|
7
7
|
import { StatusCode, InfoStatusCode, SuccessStatusCode, RedirectStatusCode, ClientErrorStatusCode, ServerErrorStatusCode } from 'hono/utils/http-status';
|
|
8
8
|
import { RemoveBlankRecord } from 'hono/utils/types';
|
|
9
|
-
import { ZodError,
|
|
9
|
+
import { ZodError, ZodType, z, ZodSchema } from 'zod';
|
|
10
10
|
export { z } from 'zod';
|
|
11
11
|
|
|
12
12
|
type MaybePromise<T> = Promise<T> | T;
|
|
@@ -15,15 +15,15 @@ type RouteConfig = RouteConfig$1 & {
|
|
|
15
15
|
};
|
|
16
16
|
type RequestTypes = {
|
|
17
17
|
body?: ZodRequestBody;
|
|
18
|
-
params?:
|
|
19
|
-
query?:
|
|
20
|
-
cookies?:
|
|
21
|
-
headers?:
|
|
18
|
+
params?: ZodType;
|
|
19
|
+
query?: ZodType;
|
|
20
|
+
cookies?: ZodType;
|
|
21
|
+
headers?: ZodType | ZodType[];
|
|
22
22
|
};
|
|
23
23
|
type IsJson<T> = T extends string ? T extends `application/json${infer _Rest}` ? 'json' : never : never;
|
|
24
24
|
type IsForm<T> = T extends string ? T extends `multipart/form-data${infer _Rest}` | `application/x-www-form-urlencoded${infer _Rest}` ? 'form' : never : never;
|
|
25
25
|
type RequestPart<R extends RouteConfig, Part extends string> = Part extends keyof R['request'] ? R['request'][Part] : {};
|
|
26
|
-
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends
|
|
26
|
+
type InputTypeBase<R extends RouteConfig, Part extends string, Type extends string> = R['request'] extends RequestTypes ? RequestPart<R, Part> extends ZodType ? {
|
|
27
27
|
in: {
|
|
28
28
|
[K in Type]: z.input<RequestPart<R, Part>>;
|
|
29
29
|
};
|
|
@@ -124,7 +124,7 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
|
|
|
124
124
|
* }
|
|
125
125
|
*)
|
|
126
126
|
*/
|
|
127
|
-
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 {
|
|
127
|
+
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"]>>({ middleware: routeMiddleware, ...route }: R, handler: Handler<E, P, I, R extends {
|
|
128
128
|
responses: {
|
|
129
129
|
[statusCode: number]: {
|
|
130
130
|
content: {
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,6 @@ __export(src_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi");
|
|
29
|
-
var import_zod_to_openapi2 = require("@asteasolutions/zod-to-openapi");
|
|
30
29
|
var import_zod_validator = require("@hono/zod-validator");
|
|
31
30
|
var import_hono = require("hono");
|
|
32
31
|
var import_url = require("hono/utils/url");
|
|
@@ -70,7 +69,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
70
69
|
* }
|
|
71
70
|
*)
|
|
72
71
|
*/
|
|
73
|
-
openapi = (route, handler, hook = this.defaultHook) => {
|
|
72
|
+
openapi = ({ middleware: routeMiddleware, ...route }, handler, hook = this.defaultHook) => {
|
|
74
73
|
this.openAPIRegistry.registerPath(route);
|
|
75
74
|
const validators = [];
|
|
76
75
|
if (route.request?.query) {
|
|
@@ -109,7 +108,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
const middleware =
|
|
111
|
+
const middleware = routeMiddleware ? Array.isArray(routeMiddleware) ? routeMiddleware : [routeMiddleware] : [];
|
|
113
112
|
this.on(
|
|
114
113
|
[route.method],
|
|
115
114
|
route.path.replaceAll(/\/{(.+?)}/g, "/:$1"),
|
|
@@ -199,7 +198,7 @@ var createRoute = (routeConfig) => {
|
|
|
199
198
|
};
|
|
200
199
|
return Object.defineProperty(route, "getRoutingPath", { enumerable: false });
|
|
201
200
|
};
|
|
202
|
-
(0,
|
|
201
|
+
(0, import_zod_to_openapi.extendZodWithOpenApi)(import_zod.z);
|
|
203
202
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
203
|
0 && (module.exports = {
|
|
205
204
|
OpenAPIHono,
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
+
OpenAPIRegistry,
|
|
3
4
|
OpenApiGeneratorV3,
|
|
4
5
|
OpenApiGeneratorV31,
|
|
5
|
-
|
|
6
|
+
extendZodWithOpenApi
|
|
6
7
|
} from "@asteasolutions/zod-to-openapi";
|
|
7
|
-
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
8
8
|
import { zValidator } from "@hono/zod-validator";
|
|
9
9
|
import { Hono } from "hono";
|
|
10
10
|
import { mergePath } from "hono/utils/url";
|
|
11
|
-
import {
|
|
11
|
+
import { ZodType, z } from "zod";
|
|
12
12
|
var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
13
13
|
openAPIRegistry;
|
|
14
14
|
defaultHook;
|
|
@@ -48,7 +48,7 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
48
48
|
* }
|
|
49
49
|
*)
|
|
50
50
|
*/
|
|
51
|
-
openapi = (route, handler, hook = this.defaultHook) => {
|
|
51
|
+
openapi = ({ middleware: routeMiddleware, ...route }, handler, hook = this.defaultHook) => {
|
|
52
52
|
this.openAPIRegistry.registerPath(route);
|
|
53
53
|
const validators = [];
|
|
54
54
|
if (route.request?.query) {
|
|
@@ -87,7 +87,7 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
const middleware =
|
|
90
|
+
const middleware = routeMiddleware ? Array.isArray(routeMiddleware) ? routeMiddleware : [routeMiddleware] : [];
|
|
91
91
|
this.on(
|
|
92
92
|
[route.method],
|
|
93
93
|
route.path.replaceAll(/\/{(.+?)}/g, "/:$1"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/zod-openapi",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "A wrapper class of Hono which supports OpenAPI.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"@cloudflare/workers-types": "^4.20240117.0",
|
|
45
45
|
"hono": "^4.3.6",
|
|
46
46
|
"jest": "^29.7.0",
|
|
47
|
-
"openapi3-ts": "^4.1.2",
|
|
48
47
|
"tsup": "^8.0.1",
|
|
49
48
|
"typescript": "^5.4.4",
|
|
50
49
|
"vitest": "^1.4.0",
|
|
50
|
+
"yaml": "^2.4.3",
|
|
51
51
|
"zod": "^3.22.1"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@asteasolutions/zod-to-openapi": "^7.0.0",
|
|
55
|
-
"@hono/zod-validator": "0.2.
|
|
55
|
+
"@hono/zod-validator": "0.2.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=16.0.0"
|