hono-takibi 0.9.96 → 0.9.98
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/README.md +263 -101
- package/dist/config/index.d.ts +217 -14
- package/dist/config/index.js +10 -6
- package/dist/core/docs/index.d.ts +2 -2
- package/dist/core/docs/index.js +3 -3
- package/dist/core/rpc/index.d.ts +3 -1
- package/dist/core/rpc/index.js +11 -8
- package/dist/core/svelte-query/index.js +1 -1
- package/dist/core/swr/index.js +1 -1
- package/dist/core/tanstack-query/index.js +1 -1
- package/dist/core/type/index.js +1 -1
- package/dist/core/vue-query/index.js +1 -1
- package/dist/{docs-nEYNzslr.js → docs-EJtBjiC0.js} +98 -44
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hono-rpc-If6X3RMO.js → hono-rpc-DC-G2VEi.js} +24 -8
- package/dist/index.js +16 -12
- package/dist/{openapi-BA5WgoAT.js → openapi-GQ5RidiS.js} +219 -61
- package/dist/{query-BtS4FyJa.js → query-B-cMeoTm.js} +2 -2
- package/dist/{utils-BxBFZB4U.js → utils-Bfda9ORl.js} +2 -1
- package/dist/vite-plugin/index.js +20 -7
- package/dist/{webhooks-CqouetXd.js → webhooks-Bpm9Djut.js} +40 -31
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,14 +32,14 @@ npx hono-takibi path/to/input.{yaml,json,tsp} -o path/to/output.ts
|
|
|
32
32
|
Create `hono-takibi.config.ts`:
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
|
-
import { defineConfig } from
|
|
35
|
+
import { defineConfig } from "hono-takibi/config";
|
|
36
36
|
|
|
37
37
|
export default defineConfig({
|
|
38
|
-
input:
|
|
39
|
-
|
|
40
|
-
output:
|
|
38
|
+
input: "openapi.yaml",
|
|
39
|
+
"zod-openapi": {
|
|
40
|
+
output: "./src/routes.ts",
|
|
41
41
|
},
|
|
42
|
-
})
|
|
42
|
+
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
```bash
|
|
@@ -78,40 +78,44 @@ paths:
|
|
|
78
78
|
output:
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
|
-
import { createRoute, z } from
|
|
81
|
+
import { createRoute, z } from "@hono/zod-openapi";
|
|
82
82
|
|
|
83
83
|
export const getRoute = createRoute({
|
|
84
|
-
method:
|
|
85
|
-
path:
|
|
86
|
-
summary:
|
|
87
|
-
description:
|
|
84
|
+
method: "get",
|
|
85
|
+
path: "/",
|
|
86
|
+
summary: "Welcome",
|
|
87
|
+
description: "Returns a welcome message from Hono Takibi.",
|
|
88
88
|
responses: {
|
|
89
89
|
200: {
|
|
90
|
-
description:
|
|
90
|
+
description: "OK",
|
|
91
91
|
content: {
|
|
92
|
-
|
|
92
|
+
"application/json": {
|
|
93
93
|
schema: z
|
|
94
|
-
.object({
|
|
95
|
-
|
|
94
|
+
.object({
|
|
95
|
+
message: z.string().openapi({ example: "Hono Takibi🔥" }),
|
|
96
|
+
})
|
|
97
|
+
.openapi({ required: ["message"] }),
|
|
96
98
|
},
|
|
97
99
|
},
|
|
98
100
|
},
|
|
99
101
|
},
|
|
100
|
-
})
|
|
102
|
+
});
|
|
101
103
|
```
|
|
102
104
|
|
|
103
105
|
## Vite Plugin
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
Watches your OpenAPI spec and `hono-takibi.config.ts` for changes, then auto-regenerates code on save.
|
|
108
|
+
|
|
109
|
+
Requires `hono-takibi.config.ts` in your project root.
|
|
106
110
|
|
|
107
111
|
```ts
|
|
108
112
|
// vite.config.ts
|
|
109
|
-
import { honoTakibiVite } from
|
|
110
|
-
import { defineConfig } from
|
|
113
|
+
import { honoTakibiVite } from "hono-takibi/vite-plugin";
|
|
114
|
+
import { defineConfig } from "vite";
|
|
111
115
|
|
|
112
116
|
export default defineConfig({
|
|
113
117
|
plugins: [honoTakibiVite()],
|
|
114
|
-
})
|
|
118
|
+
});
|
|
115
119
|
```
|
|
116
120
|
|
|
117
121
|

|
|
@@ -122,14 +126,15 @@ Generate a complete app structure with handler stubs and test files:
|
|
|
122
126
|
|
|
123
127
|
```ts
|
|
124
128
|
export default defineConfig({
|
|
125
|
-
input:
|
|
126
|
-
|
|
127
|
-
output:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
input: "openapi.yaml",
|
|
130
|
+
"zod-openapi": {
|
|
131
|
+
output: "./src/routes.ts",
|
|
132
|
+
template: {
|
|
133
|
+
test: true,
|
|
134
|
+
pathAlias: "@/",
|
|
135
|
+
},
|
|
131
136
|
},
|
|
132
|
-
})
|
|
137
|
+
});
|
|
133
138
|
```
|
|
134
139
|
|
|
135
140
|
This generates:
|
|
@@ -138,7 +143,63 @@ This generates:
|
|
|
138
143
|
- `src/handlers/*.ts` - Handler stubs for each resource
|
|
139
144
|
- `src/handlers/*.test.ts` - Vitest test files with `@faker-js/faker` mock data
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
Re-running after updating your OpenAPI spec is safe — your hand-written handler logic and test customizations are preserved. Only new routes are added as stubs.
|
|
147
|
+
|
|
148
|
+
> **Note:** If you remove a path from your OpenAPI spec and re-run, the corresponding handler and test files will be deleted. Make sure to back up or migrate any custom logic before removing API definitions.
|
|
149
|
+
|
|
150
|
+
### Handler Generation Modes
|
|
151
|
+
|
|
152
|
+
#### `routeHandler: false` (default)
|
|
153
|
+
|
|
154
|
+
Handlers import the app and register routes inline:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
// src/handlers/health.ts
|
|
158
|
+
import { getHealthRoute } from "@/routes";
|
|
159
|
+
import app from "@";
|
|
160
|
+
|
|
161
|
+
export const healthHandler = app.openapi(getHealthRoute, (c) => {});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The app mounts handlers via `.route()`:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// src/index.ts
|
|
168
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
169
|
+
import { healthHandler } from "./handlers/health";
|
|
170
|
+
|
|
171
|
+
const app = new OpenAPIHono();
|
|
172
|
+
|
|
173
|
+
export const api = app.route("/", healthHandler);
|
|
174
|
+
|
|
175
|
+
export default app;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### `routeHandler: true`
|
|
179
|
+
|
|
180
|
+
Handlers export typed `RouteHandler` functions, and `index.ts` centralizes route registration:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
// src/handlers/health.ts
|
|
184
|
+
import type { RouteHandler } from "@hono/zod-openapi"
|
|
185
|
+
import type { getHealthRoute } from "../routes"
|
|
186
|
+
|
|
187
|
+
export const getHealthRouteHandler: RouteHandler<typeof getHealthRoute> =
|
|
188
|
+
async (c) => {}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
// src/index.ts
|
|
193
|
+
import { OpenAPIHono } from "@hono/zod-openapi"
|
|
194
|
+
import { getHealthRoute } from "./routes"
|
|
195
|
+
import { getHealthRouteHandler } from "./handlers"
|
|
196
|
+
|
|
197
|
+
const app = new OpenAPIHono()
|
|
198
|
+
|
|
199
|
+
export const api = app.openapi(getHealthRoute, getHealthRouteHandler)
|
|
200
|
+
|
|
201
|
+
export default app
|
|
202
|
+
```
|
|
142
203
|
|
|
143
204
|
## Client Library Integrations
|
|
144
205
|
|
|
@@ -146,10 +207,18 @@ Supported: TanStack Query, SWR, Svelte Query, Vue Query, RPC Client.
|
|
|
146
207
|
|
|
147
208
|
```ts
|
|
148
209
|
export default defineConfig({
|
|
149
|
-
input:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
210
|
+
input: "openapi.yaml",
|
|
211
|
+
"zod-openapi": {
|
|
212
|
+
output: "./src/routes.ts",
|
|
213
|
+
exportSchemas: true,
|
|
214
|
+
},
|
|
215
|
+
"tanstack-query": {
|
|
216
|
+
output: "./src/tanstack-query",
|
|
217
|
+
import: "../client",
|
|
218
|
+
split: true,
|
|
219
|
+
client: "client",
|
|
220
|
+
},
|
|
221
|
+
});
|
|
153
222
|
```
|
|
154
223
|
|
|
155
224
|
## Test & Mock Generation
|
|
@@ -158,20 +227,30 @@ export default defineConfig({
|
|
|
158
227
|
|
|
159
228
|
```ts
|
|
160
229
|
export default defineConfig({
|
|
161
|
-
input:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
230
|
+
input: "openapi.yaml",
|
|
231
|
+
"zod-openapi": {
|
|
232
|
+
output: "./src/routes.ts",
|
|
233
|
+
},
|
|
234
|
+
test: {
|
|
235
|
+
output: "./src/test.ts",
|
|
236
|
+
import: "../index",
|
|
237
|
+
},
|
|
238
|
+
});
|
|
165
239
|
```
|
|
166
240
|
|
|
167
241
|
### Mock Server Generation
|
|
168
242
|
|
|
169
243
|
```ts
|
|
170
244
|
export default defineConfig({
|
|
171
|
-
input:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
245
|
+
input: "openapi.yaml",
|
|
246
|
+
"zod-openapi": {
|
|
247
|
+
output: "./src/routes.ts",
|
|
248
|
+
readonly: true,
|
|
249
|
+
},
|
|
250
|
+
mock: {
|
|
251
|
+
output: "./src/mock.ts",
|
|
252
|
+
},
|
|
253
|
+
});
|
|
175
254
|
```
|
|
176
255
|
|
|
177
256
|
### API Reference Docs
|
|
@@ -180,10 +259,33 @@ Generate API reference Markdown with [hono-cli](https://github.com/honojs/cli) `
|
|
|
180
259
|
|
|
181
260
|
```ts
|
|
182
261
|
export default defineConfig({
|
|
183
|
-
input:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
262
|
+
input: "openapi.yaml",
|
|
263
|
+
"zod-openapi": {
|
|
264
|
+
output: "./src/routes.ts",
|
|
265
|
+
readonly: true,
|
|
266
|
+
},
|
|
267
|
+
docs: {
|
|
268
|
+
output: "./docs/api.md",
|
|
269
|
+
entry: "src/index.ts",
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
To generate `curl` commands instead of `hono request`:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
export default defineConfig({
|
|
278
|
+
input: "openapi.yaml",
|
|
279
|
+
"zod-openapi": {
|
|
280
|
+
output: "./src/routes.ts",
|
|
281
|
+
readonly: true,
|
|
282
|
+
},
|
|
283
|
+
docs: {
|
|
284
|
+
output: "./docs/api.md",
|
|
285
|
+
curl: true,
|
|
286
|
+
baseUrl: "http://localhost:3000",
|
|
287
|
+
},
|
|
288
|
+
});
|
|
187
289
|
```
|
|
188
290
|
|
|
189
291
|
|
|
@@ -195,44 +297,50 @@ export default defineConfig({
|
|
|
195
297
|
|
|
196
298
|
```ts
|
|
197
299
|
// hono-takibi.config.ts
|
|
198
|
-
import { defineConfig } from
|
|
300
|
+
import { defineConfig } from "hono-takibi/config";
|
|
199
301
|
|
|
200
302
|
export default defineConfig({
|
|
201
303
|
// OpenAPI spec file (.yaml, .json, or .tsp)
|
|
202
|
-
input:
|
|
304
|
+
input: "openapi.yaml",
|
|
305
|
+
|
|
306
|
+
// Base path prefix for all routes
|
|
307
|
+
basePath: "/api",
|
|
203
308
|
|
|
204
309
|
// oxfmt format options for generated code
|
|
205
310
|
format: {
|
|
206
311
|
printWidth: 100,
|
|
207
312
|
tabWidth: 2,
|
|
208
313
|
useTabs: false,
|
|
209
|
-
endOfLine:
|
|
314
|
+
endOfLine: "lf",
|
|
210
315
|
insertFinalNewline: true,
|
|
211
316
|
semi: true,
|
|
212
317
|
singleQuote: false,
|
|
213
318
|
jsxSingleQuote: false,
|
|
214
|
-
quoteProps:
|
|
215
|
-
trailingComma:
|
|
319
|
+
quoteProps: "as-needed",
|
|
320
|
+
trailingComma: "all",
|
|
216
321
|
bracketSpacing: true,
|
|
217
322
|
bracketSameLine: false,
|
|
218
|
-
objectWrap:
|
|
219
|
-
arrowParens:
|
|
323
|
+
objectWrap: "preserve",
|
|
324
|
+
arrowParens: "always",
|
|
220
325
|
singleAttributePerLine: false,
|
|
221
|
-
proseWrap:
|
|
222
|
-
htmlWhitespaceSensitivity:
|
|
326
|
+
proseWrap: "preserve",
|
|
327
|
+
htmlWhitespaceSensitivity: "css",
|
|
223
328
|
vueIndentScriptAndStyle: false,
|
|
224
|
-
embeddedLanguageFormatting:
|
|
329
|
+
embeddedLanguageFormatting: "auto",
|
|
225
330
|
},
|
|
226
331
|
|
|
227
332
|
// Main code generation (Zod + OpenAPI + Hono)
|
|
228
|
-
|
|
333
|
+
"zod-openapi": {
|
|
229
334
|
// Output: use 'output' for single file, or 'routes' for split mode (mutually exclusive)
|
|
230
|
-
output:
|
|
231
|
-
readonly: true,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
335
|
+
output: "./src/routes.ts",
|
|
336
|
+
readonly: true, // Add 'as const' to generated schemas
|
|
337
|
+
|
|
338
|
+
// Template generation (app entry point + handler stubs + tests)
|
|
339
|
+
template: {
|
|
340
|
+
test: true, // Generate test files
|
|
341
|
+
routeHandler: false, // false: inline .openapi() (default), true: RouteHandler exports
|
|
342
|
+
pathAlias: "@/", // TypeScript path alias for imports
|
|
343
|
+
},
|
|
236
344
|
|
|
237
345
|
// Export options (OpenAPI Components Object)
|
|
238
346
|
exportSchemas: true,
|
|
@@ -253,86 +361,140 @@ export default defineConfig({
|
|
|
253
361
|
|
|
254
362
|
// Split routes into separate files
|
|
255
363
|
routes: {
|
|
256
|
-
output:
|
|
364
|
+
output: "./src/routes",
|
|
257
365
|
split: true,
|
|
258
|
-
import:
|
|
366
|
+
import: "@packages/routes", // Custom import path (monorepo support)
|
|
259
367
|
},
|
|
260
368
|
|
|
261
369
|
// Split components into separate files
|
|
262
370
|
components: {
|
|
263
|
-
schemas:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
371
|
+
schemas: {
|
|
372
|
+
output: "./src/schemas",
|
|
373
|
+
exportTypes: true,
|
|
374
|
+
split: true,
|
|
375
|
+
import: "../schemas",
|
|
376
|
+
},
|
|
377
|
+
responses: {
|
|
378
|
+
output: "./src/responses",
|
|
379
|
+
split: true,
|
|
380
|
+
import: "../responses",
|
|
381
|
+
},
|
|
382
|
+
parameters: {
|
|
383
|
+
output: "./src/parameters",
|
|
384
|
+
exportTypes: true,
|
|
385
|
+
split: true,
|
|
386
|
+
import: "../parameters",
|
|
387
|
+
},
|
|
388
|
+
examples: {
|
|
389
|
+
output: "./src/examples",
|
|
390
|
+
split: true,
|
|
391
|
+
import: "../examples",
|
|
392
|
+
},
|
|
393
|
+
requestBodies: {
|
|
394
|
+
output: "./src/requestBodies",
|
|
395
|
+
split: true,
|
|
396
|
+
import: "../requestBodies",
|
|
397
|
+
},
|
|
398
|
+
headers: {
|
|
399
|
+
output: "./src/headers",
|
|
400
|
+
exportTypes: true,
|
|
401
|
+
split: true,
|
|
402
|
+
import: "../headers",
|
|
403
|
+
},
|
|
404
|
+
securitySchemes: {
|
|
405
|
+
output: "./src/securitySchemes",
|
|
406
|
+
split: true,
|
|
407
|
+
import: "../securitySchemes",
|
|
408
|
+
},
|
|
409
|
+
links: {
|
|
410
|
+
output: "./src/links",
|
|
411
|
+
split: true,
|
|
412
|
+
import: "../links",
|
|
413
|
+
},
|
|
414
|
+
callbacks: {
|
|
415
|
+
output: "./src/callbacks",
|
|
416
|
+
split: true,
|
|
417
|
+
import: "../callbacks",
|
|
418
|
+
},
|
|
419
|
+
pathItems: {
|
|
420
|
+
output: "./src/pathItems",
|
|
421
|
+
split: true,
|
|
422
|
+
import: "../pathItems",
|
|
423
|
+
},
|
|
424
|
+
mediaTypes: {
|
|
425
|
+
output: "./src/mediaTypes",
|
|
426
|
+
exportTypes: true,
|
|
427
|
+
split: true,
|
|
428
|
+
import: "../mediaTypes",
|
|
429
|
+
},
|
|
430
|
+
webhooks: {
|
|
431
|
+
output: "./src/webhooks",
|
|
432
|
+
split: true,
|
|
433
|
+
import: "../webhooks",
|
|
434
|
+
},
|
|
275
435
|
},
|
|
276
436
|
},
|
|
277
437
|
|
|
278
438
|
// TypeScript type generation
|
|
279
439
|
type: {
|
|
280
|
-
output:
|
|
440
|
+
output: "./src/types.ts",
|
|
281
441
|
readonly: true,
|
|
282
442
|
},
|
|
283
443
|
|
|
284
444
|
// RPC client generation
|
|
285
445
|
rpc: {
|
|
286
|
-
output:
|
|
287
|
-
import:
|
|
446
|
+
output: "./src/rpc",
|
|
447
|
+
import: "../client", // Import path for the Hono RPC client
|
|
288
448
|
split: true,
|
|
289
|
-
client:
|
|
290
|
-
parseResponse: true,
|
|
449
|
+
client: "client", // Export name of the client instance
|
|
450
|
+
parseResponse: true, // Use parseResponse for type-safe responses
|
|
291
451
|
},
|
|
292
452
|
|
|
293
453
|
// Client library integrations (TanStack Query, SWR, Svelte Query, Vue Query)
|
|
294
|
-
|
|
295
|
-
output:
|
|
296
|
-
import:
|
|
454
|
+
"tanstack-query": {
|
|
455
|
+
output: "./src/tanstack-query",
|
|
456
|
+
import: "../client",
|
|
297
457
|
split: true,
|
|
298
|
-
client:
|
|
458
|
+
client: "client",
|
|
299
459
|
},
|
|
300
|
-
|
|
301
|
-
output:
|
|
302
|
-
import:
|
|
460
|
+
"svelte-query": {
|
|
461
|
+
output: "./src/svelte-query",
|
|
462
|
+
import: "../client",
|
|
303
463
|
split: true,
|
|
304
|
-
client:
|
|
464
|
+
client: "client",
|
|
305
465
|
},
|
|
306
466
|
swr: {
|
|
307
|
-
output:
|
|
308
|
-
import:
|
|
467
|
+
output: "./src/swr",
|
|
468
|
+
import: "../client",
|
|
309
469
|
split: true,
|
|
310
|
-
client:
|
|
470
|
+
client: "client",
|
|
311
471
|
},
|
|
312
|
-
|
|
313
|
-
output:
|
|
314
|
-
import:
|
|
472
|
+
"vue-query": {
|
|
473
|
+
output: "./src/vue-query",
|
|
474
|
+
import: "../client",
|
|
315
475
|
split: true,
|
|
316
|
-
client:
|
|
476
|
+
client: "client",
|
|
317
477
|
},
|
|
318
478
|
|
|
319
479
|
// Test generation
|
|
320
480
|
test: {
|
|
321
|
-
output:
|
|
322
|
-
import:
|
|
481
|
+
output: "./src/test.ts",
|
|
482
|
+
import: "../index", // Import path for the app instance
|
|
323
483
|
},
|
|
324
484
|
|
|
325
485
|
// Mock server generation
|
|
326
486
|
mock: {
|
|
327
|
-
output:
|
|
487
|
+
output: "./src/mock.ts",
|
|
328
488
|
},
|
|
329
489
|
|
|
330
490
|
// API reference docs generation
|
|
331
491
|
docs: {
|
|
332
|
-
output:
|
|
333
|
-
entry:
|
|
492
|
+
output: "./docs/api.md",
|
|
493
|
+
entry: "src/index.ts", // App entry point for hono request commands
|
|
494
|
+
curl: false, // true: generate curl commands (requires baseUrl), false: hono request (default)
|
|
495
|
+
baseUrl: "http://localhost:3000", // Base URL for curl commands (required when curl: true)
|
|
334
496
|
},
|
|
335
|
-
})
|
|
497
|
+
});
|
|
336
498
|
```
|
|
337
499
|
|
|
338
500
|
## Limitations
|
|
@@ -340,7 +502,7 @@ export default defineConfig({
|
|
|
340
502
|
**This package is in active development and may introduce breaking changes without prior notice.**
|
|
341
503
|
|
|
342
504
|
- Not all OpenAPI features are supported
|
|
343
|
-
-
|
|
505
|
+
- Circular references through `allOf` may cause stack overflow in type generation
|
|
344
506
|
- Some OpenAPI validations may not be perfectly converted to Zod
|
|
345
507
|
|
|
346
508
|
We strongly recommend:
|