@hono/zod-openapi 1.1.5 → 1.2.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/CHANGELOG.md +12 -0
- package/README.md +23 -0
- package/dist/index.cjs +248 -263
- package/dist/index.d.cts +192 -184
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +192 -184
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +219 -243
- package/dist/index.js.map +1 -0
- package/package.json +9 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @hono/zod-openapi
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1639](https://github.com/honojs/middleware/pull/1639) [`32bc133a58c2a3a79fe386f542eb71fdc5722931`](https://github.com/honojs/middleware/commit/32bc133a58c2a3a79fe386f542eb71fdc5722931) Thanks [@yusukebe](https://github.com/yusukebe)! - feat: introduce `$` and `HonoToOpenAPIHono`
|
|
8
|
+
|
|
9
|
+
## 1.1.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1637](https://github.com/honojs/middleware/pull/1637) [`64cc1d9b103194d826e8d559104c1191672741a1`](https://github.com/honojs/middleware/commit/64cc1d9b103194d826e8d559104c1191672741a1) Thanks [@yusukebe](https://github.com/yusukebe)! - fix: return `OpenAPIHono` from onError and onNotFound
|
|
14
|
+
|
|
3
15
|
## 1.1.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -400,6 +400,29 @@ const client = hc<typeof appRoutes>('http://localhost:8787/')
|
|
|
400
400
|
|
|
401
401
|
## Tips
|
|
402
402
|
|
|
403
|
+
### Type utilities
|
|
404
|
+
|
|
405
|
+
Methods like `get()`, `post()`, `use()`, etc. return `Hono` type instead of `OpenAPIHono`. This can cause issues when you need the `OpenAPIHono` type. Use the `$()` function to convert the instance back to `OpenAPIHono` type:
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
import { OpenAPIHono, $ } from '@hono/zod-openapi'
|
|
409
|
+
|
|
410
|
+
const app = $(new OpenAPIHono().use(middleware))
|
|
411
|
+
app.openapi(route, handler)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
You can also use the `HonoToOpenAPIHono` utility type to convert the return type at the type level:
|
|
415
|
+
|
|
416
|
+
```ts
|
|
417
|
+
import type { HonoToOpenAPIHono } from '@hono/zod-openapi'
|
|
418
|
+
|
|
419
|
+
const app = new OpenAPIHono()
|
|
420
|
+
const result = app.get('/hello', (c) => c.json({ message: 'Hello' }))
|
|
421
|
+
|
|
422
|
+
// `result` is Hono type, convert it to OpenAPIHono
|
|
423
|
+
type MyApp = HonoToOpenAPIHono<typeof result>
|
|
424
|
+
```
|
|
425
|
+
|
|
403
426
|
### How to register components
|
|
404
427
|
|
|
405
428
|
You can register components to the registry as follows:
|
package/dist/index.cjs
CHANGED
|
@@ -1,284 +1,269 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
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
8
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var import_hono = require("hono");
|
|
32
|
-
var import_url = require("hono/utils/url");
|
|
33
|
-
var import_zod = require("zod");
|
|
23
|
+
//#endregion
|
|
24
|
+
let __asteasolutions_zod_to_openapi = require("@asteasolutions/zod-to-openapi");
|
|
25
|
+
__asteasolutions_zod_to_openapi = __toESM(__asteasolutions_zod_to_openapi);
|
|
26
|
+
let __hono_zod_validator = require("@hono/zod-validator");
|
|
27
|
+
__hono_zod_validator = __toESM(__hono_zod_validator);
|
|
28
|
+
let hono = require("hono");
|
|
29
|
+
hono = __toESM(hono);
|
|
30
|
+
let hono_utils_url = require("hono/utils/url");
|
|
31
|
+
hono_utils_url = __toESM(hono_utils_url);
|
|
32
|
+
let zod = require("zod");
|
|
33
|
+
zod = __toESM(zod);
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
//#region src/zod-typeguard.ts
|
|
36
36
|
function isObject(x) {
|
|
37
|
-
|
|
37
|
+
return typeof x === "object" && x !== null;
|
|
38
38
|
}
|
|
39
39
|
function isZod(x) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (!x) return false;
|
|
41
|
+
if (!isObject(x)) return false;
|
|
42
|
+
return typeof x.parse === "function" && typeof x.safeParse === "function" && typeof x.parseAsync === "function" && typeof x.safeParseAsync === "function";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return this.openAPIRegistry.registerParameter(
|
|
237
|
-
(0, import_zod_to_openapi.getOpenApiMetadata)(def.schema)._internal?.refId,
|
|
238
|
-
def.schema
|
|
239
|
-
);
|
|
240
|
-
default: {
|
|
241
|
-
const errorIfNotExhaustive = def;
|
|
242
|
-
throw new Error(`Unknown registry type: ${errorIfNotExhaustive}`);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
basePath(path) {
|
|
249
|
-
return new _OpenAPIHono({ ...super.basePath(path), defaultHook: this.defaultHook });
|
|
250
|
-
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/index.ts
|
|
47
|
+
/**
|
|
48
|
+
* Converts a Hono instance to OpenAPIHono type.
|
|
49
|
+
* Use this function to restore the OpenAPIHono type after chaining methods like `get`, `post`, `use`, etc.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { OpenAPIHono, $ } from '@hono/zod-openapi'
|
|
53
|
+
*
|
|
54
|
+
* const app = $(
|
|
55
|
+
* new OpenAPIHono().use(middleware)
|
|
56
|
+
* )
|
|
57
|
+
* app.openapi(route, handler)
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
const $ = (app) => {
|
|
61
|
+
return app;
|
|
62
|
+
};
|
|
63
|
+
var OpenAPIHono = class OpenAPIHono extends hono.Hono {
|
|
64
|
+
openAPIRegistry;
|
|
65
|
+
defaultHook;
|
|
66
|
+
constructor(init) {
|
|
67
|
+
super(init);
|
|
68
|
+
this.openAPIRegistry = new __asteasolutions_zod_to_openapi.OpenAPIRegistry();
|
|
69
|
+
this.defaultHook = init === null || init === void 0 ? void 0 : init.defaultHook;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param {RouteConfig} route - The route definition which you create with `createRoute()`.
|
|
74
|
+
* @param {Handler} handler - The handler. If you want to return a JSON object, you should specify the status code with `c.json()`.
|
|
75
|
+
* @param {Hook} hook - Optional. The hook method defines what it should do after validation.
|
|
76
|
+
* @example
|
|
77
|
+
* app.openapi(
|
|
78
|
+
* route,
|
|
79
|
+
* (c) => {
|
|
80
|
+
* // ...
|
|
81
|
+
* return c.json(
|
|
82
|
+
* {
|
|
83
|
+
* age: 20,
|
|
84
|
+
* name: 'Young man',
|
|
85
|
+
* },
|
|
86
|
+
* 200 // You should specify the status code even if it's 200.
|
|
87
|
+
* )
|
|
88
|
+
* },
|
|
89
|
+
* (result, c) => {
|
|
90
|
+
* if (!result.success) {
|
|
91
|
+
* return c.json(
|
|
92
|
+
* {
|
|
93
|
+
* code: 400,
|
|
94
|
+
* message: 'Custom Message',
|
|
95
|
+
* },
|
|
96
|
+
* 400
|
|
97
|
+
* )
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
*)
|
|
101
|
+
*/
|
|
102
|
+
openapi = ({ middleware: routeMiddleware, hide,...route }, handler, hook = this.defaultHook) => {
|
|
103
|
+
var _route$request, _route$request2, _route$request3, _route$request4, _route$request5;
|
|
104
|
+
if (!hide) this.openAPIRegistry.registerPath(route);
|
|
105
|
+
const validators = [];
|
|
106
|
+
if ((_route$request = route.request) === null || _route$request === void 0 ? void 0 : _route$request.query) {
|
|
107
|
+
const validator = (0, __hono_zod_validator.zValidator)("query", route.request.query, hook);
|
|
108
|
+
validators.push(validator);
|
|
109
|
+
}
|
|
110
|
+
if ((_route$request2 = route.request) === null || _route$request2 === void 0 ? void 0 : _route$request2.params) {
|
|
111
|
+
const validator = (0, __hono_zod_validator.zValidator)("param", route.request.params, hook);
|
|
112
|
+
validators.push(validator);
|
|
113
|
+
}
|
|
114
|
+
if ((_route$request3 = route.request) === null || _route$request3 === void 0 ? void 0 : _route$request3.headers) {
|
|
115
|
+
const validator = (0, __hono_zod_validator.zValidator)("header", route.request.headers, hook);
|
|
116
|
+
validators.push(validator);
|
|
117
|
+
}
|
|
118
|
+
if ((_route$request4 = route.request) === null || _route$request4 === void 0 ? void 0 : _route$request4.cookies) {
|
|
119
|
+
const validator = (0, __hono_zod_validator.zValidator)("cookie", route.request.cookies, hook);
|
|
120
|
+
validators.push(validator);
|
|
121
|
+
}
|
|
122
|
+
const bodyContent = (_route$request5 = route.request) === null || _route$request5 === void 0 || (_route$request5 = _route$request5.body) === null || _route$request5 === void 0 ? void 0 : _route$request5.content;
|
|
123
|
+
if (bodyContent) for (const mediaType of Object.keys(bodyContent)) {
|
|
124
|
+
if (!bodyContent[mediaType]) continue;
|
|
125
|
+
const schema = bodyContent[mediaType]["schema"];
|
|
126
|
+
if (!isZod(schema)) continue;
|
|
127
|
+
if (isJSONContentType(mediaType)) {
|
|
128
|
+
var _route$request6;
|
|
129
|
+
const validator = (0, __hono_zod_validator.zValidator)("json", schema, hook);
|
|
130
|
+
if ((_route$request6 = route.request) === null || _route$request6 === void 0 || (_route$request6 = _route$request6.body) === null || _route$request6 === void 0 ? void 0 : _route$request6.required) validators.push(validator);
|
|
131
|
+
else {
|
|
132
|
+
const mw = async (c, next) => {
|
|
133
|
+
if (c.req.header("content-type")) {
|
|
134
|
+
if (isJSONContentType(c.req.header("content-type"))) return await validator(c, next);
|
|
135
|
+
}
|
|
136
|
+
c.req.addValidatedData("json", {});
|
|
137
|
+
await next();
|
|
138
|
+
};
|
|
139
|
+
validators.push(mw);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (isFormContentType(mediaType)) {
|
|
143
|
+
var _route$request7;
|
|
144
|
+
const validator = (0, __hono_zod_validator.zValidator)("form", schema, hook);
|
|
145
|
+
if ((_route$request7 = route.request) === null || _route$request7 === void 0 || (_route$request7 = _route$request7.body) === null || _route$request7 === void 0 ? void 0 : _route$request7.required) validators.push(validator);
|
|
146
|
+
else {
|
|
147
|
+
const mw = async (c, next) => {
|
|
148
|
+
if (c.req.header("content-type")) {
|
|
149
|
+
if (isFormContentType(c.req.header("content-type"))) {
|
|
150
|
+
await validator(c, next);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
c.req.addValidatedData("form", {});
|
|
155
|
+
await next();
|
|
156
|
+
};
|
|
157
|
+
validators.push(mw);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const middleware = routeMiddleware ? Array.isArray(routeMiddleware) ? routeMiddleware : [routeMiddleware] : [];
|
|
162
|
+
this.on([route.method], [route.path.replaceAll(/\/{(.+?)}/g, "/:$1")], ...middleware, ...validators, handler);
|
|
163
|
+
return this;
|
|
164
|
+
};
|
|
165
|
+
getOpenAPIDocument = (objectConfig, generatorConfig) => {
|
|
166
|
+
const document = new __asteasolutions_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions, generatorConfig).generateDocument(objectConfig);
|
|
167
|
+
return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
|
|
168
|
+
};
|
|
169
|
+
getOpenAPI31Document = (objectConfig, generatorConfig) => {
|
|
170
|
+
const document = new __asteasolutions_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions, generatorConfig).generateDocument(objectConfig);
|
|
171
|
+
return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
|
|
172
|
+
};
|
|
173
|
+
doc = (path, configureObject, configureGenerator) => {
|
|
174
|
+
return this.get(path, (c) => {
|
|
175
|
+
const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
|
|
176
|
+
const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
|
|
177
|
+
try {
|
|
178
|
+
const document = this.getOpenAPIDocument(objectConfig, generatorConfig);
|
|
179
|
+
return c.json(document);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
return c.json(e, 500);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
doc31 = (path, configureObject, configureGenerator) => {
|
|
186
|
+
return this.get(path, (c) => {
|
|
187
|
+
const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
|
|
188
|
+
const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
|
|
189
|
+
try {
|
|
190
|
+
const document = this.getOpenAPI31Document(objectConfig, generatorConfig);
|
|
191
|
+
return c.json(document);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
return c.json(e, 500);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
route(path, app) {
|
|
198
|
+
const pathForOpenAPI = path.replaceAll(/:([^\/]+)/g, "{$1}");
|
|
199
|
+
super.route(path, app);
|
|
200
|
+
if (!(app instanceof OpenAPIHono)) return this;
|
|
201
|
+
app.openAPIRegistry.definitions.forEach((def) => {
|
|
202
|
+
switch (def.type) {
|
|
203
|
+
case "component": return this.openAPIRegistry.registerComponent(def.componentType, def.name, def.component);
|
|
204
|
+
case "route":
|
|
205
|
+
this.openAPIRegistry.registerPath({
|
|
206
|
+
...def.route,
|
|
207
|
+
path: (0, hono_utils_url.mergePath)(pathForOpenAPI, app._basePath.replaceAll(/:([^\/]+)/g, "{$1}"), def.route.path)
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
case "webhook":
|
|
211
|
+
this.openAPIRegistry.registerWebhook({
|
|
212
|
+
...def.webhook,
|
|
213
|
+
path: (0, hono_utils_url.mergePath)(pathForOpenAPI, app._basePath.replaceAll(/:([^\/]+)/g, "{$1}"), def.webhook.path)
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
case "schema":
|
|
217
|
+
var _getOpenApiMetadata$_;
|
|
218
|
+
return this.openAPIRegistry.register((_getOpenApiMetadata$_ = (0, __asteasolutions_zod_to_openapi.getOpenApiMetadata)(def.schema)._internal) === null || _getOpenApiMetadata$_ === void 0 ? void 0 : _getOpenApiMetadata$_.refId, def.schema);
|
|
219
|
+
case "parameter":
|
|
220
|
+
var _getOpenApiMetadata$_2;
|
|
221
|
+
return this.openAPIRegistry.registerParameter((_getOpenApiMetadata$_2 = (0, __asteasolutions_zod_to_openapi.getOpenApiMetadata)(def.schema)._internal) === null || _getOpenApiMetadata$_2 === void 0 ? void 0 : _getOpenApiMetadata$_2.refId, def.schema);
|
|
222
|
+
default: {
|
|
223
|
+
const errorIfNotExhaustive = def;
|
|
224
|
+
throw new Error(`Unknown registry type: ${errorIfNotExhaustive}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
basePath(path) {
|
|
231
|
+
return new OpenAPIHono({
|
|
232
|
+
...super.basePath(path),
|
|
233
|
+
defaultHook: this.defaultHook
|
|
234
|
+
});
|
|
235
|
+
}
|
|
251
236
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
237
|
+
const createRoute = (routeConfig) => {
|
|
238
|
+
const route = {
|
|
239
|
+
...routeConfig,
|
|
240
|
+
getRoutingPath() {
|
|
241
|
+
return routeConfig.path.replaceAll(/\/{(.+?)}/g, "/:$1");
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
return Object.defineProperty(route, "getRoutingPath", { enumerable: false });
|
|
260
245
|
};
|
|
261
|
-
(0,
|
|
246
|
+
(0, __asteasolutions_zod_to_openapi.extendZodWithOpenApi)(zod.z);
|
|
262
247
|
function addBasePathToDocument(document, basePath) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
248
|
+
const updatedPaths = {};
|
|
249
|
+
Object.keys(document.paths).forEach((path) => {
|
|
250
|
+
updatedPaths[(0, hono_utils_url.mergePath)(basePath.replaceAll(/:([^\/]+)/g, "{$1}"), path)] = document.paths[path];
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
...document,
|
|
254
|
+
paths: updatedPaths
|
|
255
|
+
};
|
|
271
256
|
}
|
|
272
257
|
function isJSONContentType(contentType) {
|
|
273
|
-
|
|
258
|
+
return /^application\/([a-z-\.]+\+)?json/.test(contentType);
|
|
274
259
|
}
|
|
275
260
|
function isFormContentType(contentType) {
|
|
276
|
-
|
|
261
|
+
return contentType.startsWith("multipart/form-data") || contentType.startsWith("application/x-www-form-urlencoded");
|
|
277
262
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
exports.$ = $;
|
|
266
|
+
exports.OpenAPIHono = OpenAPIHono;
|
|
267
|
+
exports.createRoute = createRoute;
|
|
268
|
+
exports.extendZodWithOpenApi = __asteasolutions_zod_to_openapi.extendZodWithOpenApi;
|
|
269
|
+
exports.z = zod.z;
|