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 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 'hono-takibi/config'
35
+ import { defineConfig } from "hono-takibi/config";
36
36
 
37
37
  export default defineConfig({
38
- input: 'openapi.yaml',
39
- 'zod-openapi': {
40
- output: './src/routes.ts',
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 '@hono/zod-openapi'
81
+ import { createRoute, z } from "@hono/zod-openapi";
82
82
 
83
83
  export const getRoute = createRoute({
84
- method: 'get',
85
- path: '/',
86
- summary: 'Welcome',
87
- description: 'Returns a welcome message from Hono Takibi.',
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: 'OK',
90
+ description: "OK",
91
91
  content: {
92
- 'application/json': {
92
+ "application/json": {
93
93
  schema: z
94
- .object({ message: z.string().openapi({ example: 'Hono Takibi🔥' }) })
95
- .openapi({ required: ['message'] }),
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
- Auto-regenerate on file changes:
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 'hono-takibi/vite-plugin'
110
- import { defineConfig } from 'vite'
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
  ![](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/vite/hono-takibi-vite.gif)
@@ -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: 'openapi.yaml',
126
- 'zod-openapi': {
127
- output: './src/routes.ts',
128
- pathAlias: '@/',
129
- template: true,
130
- test: true,
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
- When you update your OpenAPI spec and re-run, existing handler implementations and test customizations are preserved. Only new routes are added and removed routes are cleaned up automatically.
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: 'openapi.yaml',
150
- 'zod-openapi': { output: './src/routes.ts', pathAlias: '@/', exportSchemas: true },
151
- 'tanstack-query': { output: './src/tanstack-query', import: '../client', split: true, client: 'client' },
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: 'openapi.yaml',
162
- 'zod-openapi': { output: './src/routes.ts', pathAlias: '@/' },
163
- test: { output: './src/test.ts', import: '../index' },
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: 'openapi.yaml',
172
- 'zod-openapi': { output: './src/routes.ts', pathAlias: '@/', readonly: true },
173
- mock: { output: './src/mock.ts' },
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: 'openapi.yaml',
184
- 'zod-openapi': { output: './src/routes.ts', pathAlias: '@/', readonly: true },
185
- docs: { output: './docs/api.md', entry: 'src/index.ts' },
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 'hono-takibi/config'
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: 'openapi.yaml',
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: 'lf',
314
+ endOfLine: "lf",
210
315
  insertFinalNewline: true,
211
316
  semi: true,
212
317
  singleQuote: false,
213
318
  jsxSingleQuote: false,
214
- quoteProps: 'as-needed',
215
- trailingComma: 'all',
319
+ quoteProps: "as-needed",
320
+ trailingComma: "all",
216
321
  bracketSpacing: true,
217
322
  bracketSameLine: false,
218
- objectWrap: 'preserve',
219
- arrowParens: 'always',
323
+ objectWrap: "preserve",
324
+ arrowParens: "always",
220
325
  singleAttributePerLine: false,
221
- proseWrap: 'preserve',
222
- htmlWhitespaceSensitivity: 'css',
326
+ proseWrap: "preserve",
327
+ htmlWhitespaceSensitivity: "css",
223
328
  vueIndentScriptAndStyle: false,
224
- embeddedLanguageFormatting: 'auto',
329
+ embeddedLanguageFormatting: "auto",
225
330
  },
226
331
 
227
332
  // Main code generation (Zod + OpenAPI + Hono)
228
- 'zod-openapi': {
333
+ "zod-openapi": {
229
334
  // Output: use 'output' for single file, or 'routes' for split mode (mutually exclusive)
230
- output: './src/routes.ts',
231
- readonly: true, // Add 'as const' to generated schemas
232
- template: true, // Generate app entry point + handler stubs
233
- test: true, // Generate test files (requires template: true)
234
- basePath: '/api', // Base path prefix for all routes
235
- pathAlias: '@/', // TypeScript path alias for imports
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: './src/routes',
364
+ output: "./src/routes",
257
365
  split: true,
258
- import: '@packages/routes', // Custom import path (monorepo support)
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: { output: './src/schemas', exportTypes: true, split: true, import: '../schemas' },
264
- responses: { output: './src/responses', split: true, import: '../responses' },
265
- parameters: { output: './src/parameters', exportTypes: true, split: true, import: '../parameters' },
266
- examples: { output: './src/examples', split: true, import: '../examples' },
267
- requestBodies: { output: './src/requestBodies', split: true, import: '../requestBodies' },
268
- headers: { output: './src/headers', exportTypes: true, split: true, import: '../headers' },
269
- securitySchemes: { output: './src/securitySchemes', split: true, import: '../securitySchemes' },
270
- links: { output: './src/links', split: true, import: '../links' },
271
- callbacks: { output: './src/callbacks', split: true, import: '../callbacks' },
272
- pathItems: { output: './src/pathItems', split: true, import: '../pathItems' },
273
- mediaTypes: { output: './src/mediaTypes', exportTypes: true, split: true, import: '../mediaTypes' },
274
- webhooks: { output: './src/webhooks', split: true, import: '../webhooks' },
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: './src/types.ts',
440
+ output: "./src/types.ts",
281
441
  readonly: true,
282
442
  },
283
443
 
284
444
  // RPC client generation
285
445
  rpc: {
286
- output: './src/rpc',
287
- import: '../client', // Import path for the Hono RPC client
446
+ output: "./src/rpc",
447
+ import: "../client", // Import path for the Hono RPC client
288
448
  split: true,
289
- client: 'client', // Export name of the client instance
290
- parseResponse: true, // Use parseResponse for type-safe responses
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
- 'tanstack-query': {
295
- output: './src/tanstack-query',
296
- import: '../client',
454
+ "tanstack-query": {
455
+ output: "./src/tanstack-query",
456
+ import: "../client",
297
457
  split: true,
298
- client: 'client',
458
+ client: "client",
299
459
  },
300
- 'svelte-query': {
301
- output: './src/svelte-query',
302
- import: '../client',
460
+ "svelte-query": {
461
+ output: "./src/svelte-query",
462
+ import: "../client",
303
463
  split: true,
304
- client: 'client',
464
+ client: "client",
305
465
  },
306
466
  swr: {
307
- output: './src/swr',
308
- import: '../client',
467
+ output: "./src/swr",
468
+ import: "../client",
309
469
  split: true,
310
- client: 'client',
470
+ client: "client",
311
471
  },
312
- 'vue-query': {
313
- output: './src/vue-query',
314
- import: '../client',
472
+ "vue-query": {
473
+ output: "./src/vue-query",
474
+ import: "../client",
315
475
  split: true,
316
- client: 'client',
476
+ client: "client",
317
477
  },
318
478
 
319
479
  // Test generation
320
480
  test: {
321
- output: './src/test.ts',
322
- import: '../index', // Import path for the app instance
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: './src/mock.ts',
487
+ output: "./src/mock.ts",
328
488
  },
329
489
 
330
490
  // API reference docs generation
331
491
  docs: {
332
- output: './docs/api.md',
333
- entry: 'src/index.ts', // App entry point for hono request commands
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
- - Complex schemas might not convert correctly
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: