@hono/zod-openapi 0.7.1 → 0.7.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.js +47 -24
- package/dist/{index.cjs → index.mjs} +24 -47
- package/package.json +9 -3
- /package/dist/{index.d.cts → index.d.mts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,38 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
1
20
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
OpenAPIHono: () => OpenAPIHono,
|
|
24
|
+
createRoute: () => createRoute,
|
|
25
|
+
z: () => import_zod.z
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi");
|
|
29
|
+
var import_zod_to_openapi2 = require("@asteasolutions/zod-to-openapi");
|
|
30
|
+
var import_zod_validator = require("@hono/zod-validator");
|
|
31
|
+
var import_hono = require("hono");
|
|
32
|
+
var import_zod = require("zod");
|
|
33
|
+
var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
12
34
|
openAPIRegistry;
|
|
13
35
|
defaultHook;
|
|
14
36
|
constructor(init) {
|
|
15
37
|
super(init);
|
|
16
|
-
this.openAPIRegistry = new OpenAPIRegistry();
|
|
38
|
+
this.openAPIRegistry = new import_zod_to_openapi.OpenAPIRegistry();
|
|
17
39
|
this.defaultHook = init?.defaultHook;
|
|
18
40
|
}
|
|
19
41
|
openapi = (route, handler, hook = this.defaultHook) => {
|
|
20
42
|
this.openAPIRegistry.registerPath(route);
|
|
21
43
|
const validators = [];
|
|
22
44
|
if (route.request?.query) {
|
|
23
|
-
const validator = zValidator("query", route.request.query, hook);
|
|
45
|
+
const validator = (0, import_zod_validator.zValidator)("query", route.request.query, hook);
|
|
24
46
|
validators.push(validator);
|
|
25
47
|
}
|
|
26
48
|
if (route.request?.params) {
|
|
27
|
-
const validator = zValidator("param", route.request.params, hook);
|
|
49
|
+
const validator = (0, import_zod_validator.zValidator)("param", route.request.params, hook);
|
|
28
50
|
validators.push(validator);
|
|
29
51
|
}
|
|
30
52
|
if (route.request?.headers) {
|
|
31
|
-
const validator = zValidator("header", route.request.headers, hook);
|
|
53
|
+
const validator = (0, import_zod_validator.zValidator)("header", route.request.headers, hook);
|
|
32
54
|
validators.push(validator);
|
|
33
55
|
}
|
|
34
56
|
if (route.request?.cookies) {
|
|
35
|
-
const validator = zValidator("cookie", route.request.cookies, hook);
|
|
57
|
+
const validator = (0, import_zod_validator.zValidator)("cookie", route.request.cookies, hook);
|
|
36
58
|
validators.push(validator);
|
|
37
59
|
}
|
|
38
60
|
const bodyContent = route.request?.body?.content;
|
|
@@ -40,15 +62,15 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
40
62
|
for (const mediaType of Object.keys(bodyContent)) {
|
|
41
63
|
if (mediaType.startsWith("application/json")) {
|
|
42
64
|
const schema = bodyContent[mediaType]["schema"];
|
|
43
|
-
if (schema instanceof ZodType) {
|
|
44
|
-
const validator = zValidator("json", schema, hook);
|
|
65
|
+
if (schema instanceof import_zod.ZodType) {
|
|
66
|
+
const validator = (0, import_zod_validator.zValidator)("json", schema, hook);
|
|
45
67
|
validators.push(validator);
|
|
46
68
|
}
|
|
47
69
|
}
|
|
48
70
|
if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
|
|
49
71
|
const schema = bodyContent[mediaType]["schema"];
|
|
50
|
-
if (schema instanceof ZodType) {
|
|
51
|
-
const validator = zValidator("form", schema, hook);
|
|
72
|
+
if (schema instanceof import_zod.ZodType) {
|
|
73
|
+
const validator = (0, import_zod_validator.zValidator)("form", schema, hook);
|
|
52
74
|
validators.push(validator);
|
|
53
75
|
}
|
|
54
76
|
}
|
|
@@ -58,12 +80,12 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
58
80
|
return this;
|
|
59
81
|
};
|
|
60
82
|
getOpenAPIDocument = (config) => {
|
|
61
|
-
const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions);
|
|
83
|
+
const generator = new import_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions);
|
|
62
84
|
const document = generator.generateDocument(config);
|
|
63
85
|
return document;
|
|
64
86
|
};
|
|
65
87
|
getOpenAPI31Document = (config) => {
|
|
66
|
-
const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions);
|
|
88
|
+
const generator = new import_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions);
|
|
67
89
|
const document = generator.generateDocument(config);
|
|
68
90
|
return document;
|
|
69
91
|
};
|
|
@@ -125,9 +147,10 @@ var createRoute = (routeConfig) => {
|
|
|
125
147
|
}
|
|
126
148
|
};
|
|
127
149
|
};
|
|
128
|
-
extendZodWithOpenApi(z);
|
|
129
|
-
export
|
|
150
|
+
(0, import_zod_to_openapi2.extendZodWithOpenApi)(import_zod.z);
|
|
151
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
+
0 && (module.exports = {
|
|
130
153
|
OpenAPIHono,
|
|
131
154
|
createRoute,
|
|
132
155
|
z
|
|
133
|
-
};
|
|
156
|
+
});
|
|
@@ -1,60 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
1
|
// src/index.ts
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var import_hono = require("hono");
|
|
32
|
-
var import_zod = require("zod");
|
|
33
|
-
var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
2
|
+
import {
|
|
3
|
+
OpenApiGeneratorV3,
|
|
4
|
+
OpenApiGeneratorV31,
|
|
5
|
+
OpenAPIRegistry
|
|
6
|
+
} from "@asteasolutions/zod-to-openapi";
|
|
7
|
+
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
8
|
+
import { zValidator } from "@hono/zod-validator";
|
|
9
|
+
import { Hono } from "hono";
|
|
10
|
+
import { z, ZodType } from "zod";
|
|
11
|
+
var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
34
12
|
openAPIRegistry;
|
|
35
13
|
defaultHook;
|
|
36
14
|
constructor(init) {
|
|
37
15
|
super(init);
|
|
38
|
-
this.openAPIRegistry = new
|
|
16
|
+
this.openAPIRegistry = new OpenAPIRegistry();
|
|
39
17
|
this.defaultHook = init?.defaultHook;
|
|
40
18
|
}
|
|
41
19
|
openapi = (route, handler, hook = this.defaultHook) => {
|
|
42
20
|
this.openAPIRegistry.registerPath(route);
|
|
43
21
|
const validators = [];
|
|
44
22
|
if (route.request?.query) {
|
|
45
|
-
const validator =
|
|
23
|
+
const validator = zValidator("query", route.request.query, hook);
|
|
46
24
|
validators.push(validator);
|
|
47
25
|
}
|
|
48
26
|
if (route.request?.params) {
|
|
49
|
-
const validator =
|
|
27
|
+
const validator = zValidator("param", route.request.params, hook);
|
|
50
28
|
validators.push(validator);
|
|
51
29
|
}
|
|
52
30
|
if (route.request?.headers) {
|
|
53
|
-
const validator =
|
|
31
|
+
const validator = zValidator("header", route.request.headers, hook);
|
|
54
32
|
validators.push(validator);
|
|
55
33
|
}
|
|
56
34
|
if (route.request?.cookies) {
|
|
57
|
-
const validator =
|
|
35
|
+
const validator = zValidator("cookie", route.request.cookies, hook);
|
|
58
36
|
validators.push(validator);
|
|
59
37
|
}
|
|
60
38
|
const bodyContent = route.request?.body?.content;
|
|
@@ -62,15 +40,15 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
62
40
|
for (const mediaType of Object.keys(bodyContent)) {
|
|
63
41
|
if (mediaType.startsWith("application/json")) {
|
|
64
42
|
const schema = bodyContent[mediaType]["schema"];
|
|
65
|
-
if (schema instanceof
|
|
66
|
-
const validator =
|
|
43
|
+
if (schema instanceof ZodType) {
|
|
44
|
+
const validator = zValidator("json", schema, hook);
|
|
67
45
|
validators.push(validator);
|
|
68
46
|
}
|
|
69
47
|
}
|
|
70
48
|
if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
|
|
71
49
|
const schema = bodyContent[mediaType]["schema"];
|
|
72
|
-
if (schema instanceof
|
|
73
|
-
const validator =
|
|
50
|
+
if (schema instanceof ZodType) {
|
|
51
|
+
const validator = zValidator("form", schema, hook);
|
|
74
52
|
validators.push(validator);
|
|
75
53
|
}
|
|
76
54
|
}
|
|
@@ -80,12 +58,12 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
80
58
|
return this;
|
|
81
59
|
};
|
|
82
60
|
getOpenAPIDocument = (config) => {
|
|
83
|
-
const generator = new
|
|
61
|
+
const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions);
|
|
84
62
|
const document = generator.generateDocument(config);
|
|
85
63
|
return document;
|
|
86
64
|
};
|
|
87
65
|
getOpenAPI31Document = (config) => {
|
|
88
|
-
const generator = new
|
|
66
|
+
const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions);
|
|
89
67
|
const document = generator.generateDocument(config);
|
|
90
68
|
return document;
|
|
91
69
|
};
|
|
@@ -147,10 +125,9 @@ var createRoute = (routeConfig) => {
|
|
|
147
125
|
}
|
|
148
126
|
};
|
|
149
127
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
0 && (module.exports = {
|
|
128
|
+
extendZodWithOpenApi(z);
|
|
129
|
+
export {
|
|
153
130
|
OpenAPIHono,
|
|
154
131
|
createRoute,
|
|
155
132
|
z
|
|
156
|
-
}
|
|
133
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/zod-openapi",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "A wrapper class of Hono which supports OpenAPI.",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"main": "dist/index.js",
|
|
7
6
|
"module": "dist/index.mjs",
|
|
8
7
|
"types": "dist/index.d.ts",
|
|
@@ -15,6 +14,13 @@
|
|
|
15
14
|
"publint": "publint",
|
|
16
15
|
"release": "yarn build && yarn test && yarn publint && yarn publish"
|
|
17
16
|
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
18
24
|
"license": "MIT",
|
|
19
25
|
"private": false,
|
|
20
26
|
"publishConfig": {
|
|
@@ -42,4 +48,4 @@
|
|
|
42
48
|
"engines": {
|
|
43
49
|
"node": ">=16.0.0"
|
|
44
50
|
}
|
|
45
|
-
}
|
|
51
|
+
}
|
|
File without changes
|