hono-takibi 0.9.983 → 0.9.992

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.
Files changed (33) hide show
  1. package/README.md +168 -157
  2. package/dist/config/index.d.ts +25 -228
  3. package/dist/config/index.js +23 -87
  4. package/dist/core/docs/index.d.ts +1 -1
  5. package/dist/core/docs/index.js +2 -25
  6. package/dist/core/rpc/index.d.ts +2 -2
  7. package/dist/core/rpc/index.js +6 -11
  8. package/dist/core/svelte-query/index.d.ts +2 -2
  9. package/dist/core/svelte-query/index.js +7 -5
  10. package/dist/core/swr/index.d.ts +2 -2
  11. package/dist/core/swr/index.js +6 -5
  12. package/dist/core/tanstack-query/index.d.ts +2 -2
  13. package/dist/core/tanstack-query/index.js +12 -5
  14. package/dist/core/type/index.d.ts +1 -1
  15. package/dist/core/type/index.js +5 -7
  16. package/dist/core/vue-query/index.d.ts +2 -2
  17. package/dist/core/vue-query/index.js +7 -6
  18. package/dist/{core-BV2z-qh-.js → core-BlUaJE2n.js} +2 -5
  19. package/dist/{docs-BIq3fefq.js → docs-Da_MOdAe.js} +31 -13
  20. package/dist/{fsp-BpSlEc1j.js → fsp-Bv1yR6UV.js} +8 -3
  21. package/dist/generator/zod-openapi-hono/openapi/index.d.ts +2 -2
  22. package/dist/generator/zod-openapi-hono/openapi/index.js +2 -20
  23. package/dist/{guard-sR2aJ5o7.js → guard-BabA4f3q.js} +15 -2
  24. package/dist/{hono-rpc-DC-G2VEi.js → hono-rpc-BOLdCVD_.js} +2 -11
  25. package/dist/{index-Dirud7Xt.d.ts → index-C0mJiFsw.d.ts} +14 -0
  26. package/dist/index.js +5 -8
  27. package/dist/{openapi-BJs8PKfI.js → openapi-BNsdBSpS.js} +174 -151
  28. package/dist/{webhooks-Bpm9Djut.js → openapi-ySW4cz2Q.js} +308 -175
  29. package/dist/query-CArUJxE4.js +617 -0
  30. package/dist/{utils-Bfda9ORl.js → utils-B9bUHU9P.js} +36 -43
  31. package/dist/vite-plugin/index.js +7 -9
  32. package/package.json +19 -20
  33. package/dist/query-B-cMeoTm.js +0 -444
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,30 +78,62 @@ 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
94
  .object({
95
- message: z.string().openapi({ example: "Hono Takibi🔥" }),
95
+ message: z.string().openapi({ example: 'Hono Takibi🔥' }),
96
96
  })
97
- .openapi({ required: ["message"] }),
97
+ .openapi({ required: ['message'] }),
98
98
  },
99
99
  },
100
100
  },
101
101
  },
102
- });
102
+ })
103
103
  ```
104
104
 
105
+ ## Custom Validation Error Messages
106
+
107
+ Use `x-*` vendor extensions to customize Zod error messages:
108
+
109
+ ```yaml
110
+ name:
111
+ type: string
112
+ minLength: 1
113
+ x-error-message: 'Name is required'
114
+ x-minimum-message: 'Name cannot be empty'
115
+ ```
116
+
117
+ ```ts
118
+ // Generated output
119
+ z.string({ error: 'Name is required' }).min(1, { error: 'Name cannot be empty' })
120
+ ```
121
+
122
+ | Extension | Applies to |
123
+ | ----------------------------- | ----------------------------------------------------------------- |
124
+ | `x-error-message` | Schema constructor (`z.string()`, `z.number()`, `z.enum()`, etc.) |
125
+ | `x-minimum-message` | `.min()`, `.gte()` |
126
+ | `x-maximum-message` | `.max()`, `.lte()` |
127
+ | `x-size-message` | `.length()` |
128
+ | `x-pattern-message` | `.regex()` |
129
+ | `x-multipleOf-message` | `.multipleOf()` |
130
+ | `x-enum-error-messages` | Per-value enum messages (`{ "value": "message" }`) |
131
+ | `x-anyOf-message` | `anyOf` |
132
+ | `x-oneOf-message` | `oneOf` |
133
+ | `x-not-message` | `not` |
134
+ | `x-propertyNames-message` | `propertyNames` |
135
+ | `x-dependentRequired-message` | `dependentRequired` |
136
+
105
137
  ## Vite Plugin
106
138
 
107
139
  Watches your OpenAPI spec and `hono-takibi.config.ts` for changes, then auto-regenerates code on save.
@@ -110,12 +142,12 @@ Requires `hono-takibi.config.ts` in your project root.
110
142
 
111
143
  ```ts
112
144
  // vite.config.ts
113
- import { honoTakibiVite } from "hono-takibi/vite-plugin";
114
- import { defineConfig } from "vite";
145
+ import { honoTakibiVite } from 'hono-takibi/vite-plugin'
146
+ import { defineConfig } from 'vite'
115
147
 
116
148
  export default defineConfig({
117
149
  plugins: [honoTakibiVite()],
118
- });
150
+ })
119
151
  ```
120
152
 
121
153
  ![](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/vite/hono-takibi-vite.gif)
@@ -126,16 +158,16 @@ Generate a complete app structure with handler stubs and test files:
126
158
 
127
159
  ```ts
128
160
  export default defineConfig({
129
- input: "openapi.yaml",
130
- "zod-openapi": {
131
- output: "./src/routes.ts",
161
+ input: 'openapi.yaml',
162
+ 'zod-openapi': {
163
+ output: './src/routes.ts',
132
164
  template: {
133
165
  test: true,
134
- pathAlias: "@/",
135
- framework: "bun", // "vitest" (default) | "bun"
166
+ pathAlias: '@/',
167
+ framework: 'bun', // "vitest" (default) | "bun"
136
168
  },
137
169
  },
138
- });
170
+ })
139
171
  ```
140
172
 
141
173
  This generates:
@@ -156,26 +188,26 @@ Each handler creates its own sub-router and registers routes:
156
188
 
157
189
  ```ts
158
190
  // src/handlers/health.ts
159
- import { OpenAPIHono } from "@hono/zod-openapi";
160
- import { getHealthRoute } from "@/routes";
191
+ import { OpenAPIHono } from '@hono/zod-openapi'
192
+ import { getHealthRoute } from '@/routes'
161
193
 
162
- const app = new OpenAPIHono();
194
+ const app = new OpenAPIHono()
163
195
 
164
- export const healthHandler = app.openapi(getHealthRoute, (c) => {});
196
+ export const healthHandler = app.openapi(getHealthRoute, (c) => {})
165
197
  ```
166
198
 
167
199
  The app mounts handlers via `.route()`:
168
200
 
169
201
  ```ts
170
202
  // src/index.ts
171
- import { OpenAPIHono } from "@hono/zod-openapi";
172
- import { healthHandler } from "./handlers";
203
+ import { OpenAPIHono } from '@hono/zod-openapi'
204
+ import { healthHandler } from './handlers'
173
205
 
174
- const app = new OpenAPIHono();
206
+ const app = new OpenAPIHono()
175
207
 
176
- export const api = app.route("/", healthHandler);
208
+ export const api = app.route('/', healthHandler)
177
209
 
178
- export default app;
210
+ export default app
179
211
  ```
180
212
 
181
213
  #### `routeHandler: true`
@@ -184,18 +216,17 @@ Handlers export typed `RouteHandler` functions, and `index.ts` centralizes route
184
216
 
185
217
  ```ts
186
218
  // src/handlers/health.ts
187
- import type { RouteHandler } from "@hono/zod-openapi"
188
- import type { getHealthRoute } from "../routes"
219
+ import type { RouteHandler } from '@hono/zod-openapi'
220
+ import type { getHealthRoute } from '../routes'
189
221
 
190
- export const getHealthRouteHandler: RouteHandler<typeof getHealthRoute> =
191
- async (c) => {}
222
+ export const getHealthRouteHandler: RouteHandler<typeof getHealthRoute> = async (c) => {}
192
223
  ```
193
224
 
194
225
  ```ts
195
226
  // src/index.ts
196
- import { OpenAPIHono } from "@hono/zod-openapi"
197
- import { getHealthRoute } from "./routes"
198
- import { getHealthRouteHandler } from "./handlers"
227
+ import { OpenAPIHono } from '@hono/zod-openapi'
228
+ import { getHealthRoute } from './routes'
229
+ import { getHealthRouteHandler } from './handlers'
199
230
 
200
231
  const app = new OpenAPIHono()
201
232
 
@@ -210,18 +241,18 @@ Supported: TanStack Query, SWR, Svelte Query, Vue Query, RPC Client.
210
241
 
211
242
  ```ts
212
243
  export default defineConfig({
213
- input: "openapi.yaml",
214
- "zod-openapi": {
215
- output: "./src/routes.ts",
244
+ input: 'openapi.yaml',
245
+ 'zod-openapi': {
246
+ output: './src/routes.ts',
216
247
  exportSchemas: true,
217
248
  },
218
- "tanstack-query": {
219
- output: "./src/tanstack-query",
220
- import: "../client",
249
+ 'tanstack-query': {
250
+ output: './src/tanstack-query',
251
+ import: '../client',
221
252
  split: true,
222
- client: "client",
253
+ client: 'client',
223
254
  },
224
- });
255
+ })
225
256
  ```
226
257
 
227
258
  ## Test & Mock Generation
@@ -230,31 +261,31 @@ export default defineConfig({
230
261
 
231
262
  ```ts
232
263
  export default defineConfig({
233
- input: "openapi.yaml",
234
- "zod-openapi": {
235
- output: "./src/routes.ts",
264
+ input: 'openapi.yaml',
265
+ 'zod-openapi': {
266
+ output: './src/routes.ts',
236
267
  },
237
268
  test: {
238
- output: "./src/test.ts",
239
- import: "../index",
240
- framework: "bun", // "vitest" (default) | "bun"
269
+ output: './src/test.ts',
270
+ import: '../index',
271
+ framework: 'bun', // "vitest" (default) | "bun"
241
272
  },
242
- });
273
+ })
243
274
  ```
244
275
 
245
276
  ### Mock Server Generation
246
277
 
247
278
  ```ts
248
279
  export default defineConfig({
249
- input: "openapi.yaml",
250
- "zod-openapi": {
251
- output: "./src/routes.ts",
280
+ input: 'openapi.yaml',
281
+ 'zod-openapi': {
282
+ output: './src/routes.ts',
252
283
  readonly: true,
253
284
  },
254
285
  mock: {
255
- output: "./src/mock.ts",
286
+ output: './src/mock.ts',
256
287
  },
257
- });
288
+ })
258
289
  ```
259
290
 
260
291
  ### API Reference Docs
@@ -263,36 +294,35 @@ Generate API reference Markdown with [hono-cli](https://github.com/honojs/cli) `
263
294
 
264
295
  ```ts
265
296
  export default defineConfig({
266
- input: "openapi.yaml",
267
- "zod-openapi": {
268
- output: "./src/routes.ts",
297
+ input: 'openapi.yaml',
298
+ 'zod-openapi': {
299
+ output: './src/routes.ts',
269
300
  readonly: true,
270
301
  },
271
302
  docs: {
272
- output: "./docs/api.md",
273
- entry: "src/index.ts",
303
+ output: './docs/api.md',
304
+ entry: 'src/index.ts',
274
305
  },
275
- });
306
+ })
276
307
  ```
277
308
 
278
309
  To generate `curl` commands instead of `hono request`:
279
310
 
280
311
  ```ts
281
312
  export default defineConfig({
282
- input: "openapi.yaml",
283
- "zod-openapi": {
284
- output: "./src/routes.ts",
313
+ input: 'openapi.yaml',
314
+ 'zod-openapi': {
315
+ output: './src/routes.ts',
285
316
  readonly: true,
286
317
  },
287
318
  docs: {
288
- output: "./docs/api.md",
319
+ output: './docs/api.md',
289
320
  curl: true,
290
- baseUrl: "http://localhost:3000",
321
+ baseUrl: 'http://localhost:3000',
291
322
  },
292
- });
323
+ })
293
324
  ```
294
325
 
295
-
296
326
  ## Full Config Reference
297
327
 
298
328
  > `split: true` - `output` is a **directory** (many files + `index.ts`).
@@ -301,50 +331,31 @@ export default defineConfig({
301
331
 
302
332
  ```ts
303
333
  // hono-takibi.config.ts
304
- import { defineConfig } from "hono-takibi/config";
334
+ import { defineConfig } from 'hono-takibi/config'
305
335
 
306
336
  export default defineConfig({
307
337
  // OpenAPI spec file (.yaml, .json, or .tsp)
308
- input: "openapi.yaml",
338
+ input: 'openapi.yaml',
309
339
 
310
340
  // Base path prefix for all routes
311
- basePath: "/api",
312
-
313
- // oxfmt format options for generated code
314
- format: {
315
- printWidth: 100,
316
- tabWidth: 2,
317
- useTabs: false,
318
- endOfLine: "lf",
319
- insertFinalNewline: true,
320
- semi: true,
321
- singleQuote: false,
322
- jsxSingleQuote: false,
323
- quoteProps: "as-needed",
324
- trailingComma: "all",
325
- bracketSpacing: true,
326
- bracketSameLine: false,
327
- objectWrap: "preserve",
328
- arrowParens: "always",
329
- singleAttributePerLine: false,
330
- proseWrap: "preserve",
331
- htmlWhitespaceSensitivity: "css",
332
- vueIndentScriptAndStyle: false,
333
- embeddedLanguageFormatting: "auto",
334
- },
341
+ basePath: '/api',
342
+
343
+ // oxfmt FormatOptions for generated code output
344
+ // @see https://www.npmjs.com/package/oxfmt
345
+ // format: {},
335
346
 
336
347
  // Main code generation (Zod + OpenAPI + Hono)
337
- "zod-openapi": {
348
+ 'zod-openapi': {
338
349
  // Output: use 'output' for single file, or 'routes' for split mode (mutually exclusive)
339
- output: "./src/routes.ts",
350
+ output: './src/routes.ts',
340
351
  readonly: true, // Add 'as const' to generated schemas
341
352
 
342
353
  // Template generation (app entry point + handler stubs + tests)
343
354
  template: {
344
355
  test: true, // Generate test files
345
356
  routeHandler: false, // false: inline .openapi() (default), true: RouteHandler exports
346
- pathAlias: "@/", // TypeScript path alias for imports
347
- framework: "vitest", // "vitest" (default) | "bun" — test import source
357
+ pathAlias: '@/', // TypeScript path alias for imports
358
+ framework: 'vitest', // "vitest" (default) | "bun" — test import source
348
359
  },
349
360
 
350
361
  // Export options (OpenAPI Components Object)
@@ -366,141 +377,141 @@ export default defineConfig({
366
377
 
367
378
  // Split routes into separate files
368
379
  routes: {
369
- output: "./src/routes",
380
+ output: './src/routes',
370
381
  split: true,
371
- import: "@packages/routes", // Custom import path (monorepo support)
382
+ import: '@packages/routes', // Custom import path (monorepo support)
372
383
  },
373
384
 
374
385
  // Split components into separate files
375
386
  components: {
376
387
  schemas: {
377
- output: "./src/schemas",
388
+ output: './src/schemas',
378
389
  exportTypes: true,
379
390
  split: true,
380
- import: "../schemas",
391
+ import: '../schemas',
381
392
  },
382
393
  responses: {
383
- output: "./src/responses",
394
+ output: './src/responses',
384
395
  split: true,
385
- import: "../responses",
396
+ import: '../responses',
386
397
  },
387
398
  parameters: {
388
- output: "./src/parameters",
399
+ output: './src/parameters',
389
400
  exportTypes: true,
390
401
  split: true,
391
- import: "../parameters",
402
+ import: '../parameters',
392
403
  },
393
404
  examples: {
394
- output: "./src/examples",
405
+ output: './src/examples',
395
406
  split: true,
396
- import: "../examples",
407
+ import: '../examples',
397
408
  },
398
409
  requestBodies: {
399
- output: "./src/requestBodies",
410
+ output: './src/requestBodies',
400
411
  split: true,
401
- import: "../requestBodies",
412
+ import: '../requestBodies',
402
413
  },
403
414
  headers: {
404
- output: "./src/headers",
415
+ output: './src/headers',
405
416
  exportTypes: true,
406
417
  split: true,
407
- import: "../headers",
418
+ import: '../headers',
408
419
  },
409
420
  securitySchemes: {
410
- output: "./src/securitySchemes",
421
+ output: './src/securitySchemes',
411
422
  split: true,
412
- import: "../securitySchemes",
423
+ import: '../securitySchemes',
413
424
  },
414
425
  links: {
415
- output: "./src/links",
426
+ output: './src/links',
416
427
  split: true,
417
- import: "../links",
428
+ import: '../links',
418
429
  },
419
430
  callbacks: {
420
- output: "./src/callbacks",
431
+ output: './src/callbacks',
421
432
  split: true,
422
- import: "../callbacks",
433
+ import: '../callbacks',
423
434
  },
424
435
  pathItems: {
425
- output: "./src/pathItems",
436
+ output: './src/pathItems',
426
437
  split: true,
427
- import: "../pathItems",
438
+ import: '../pathItems',
428
439
  },
429
440
  mediaTypes: {
430
- output: "./src/mediaTypes",
441
+ output: './src/mediaTypes',
431
442
  exportTypes: true,
432
443
  split: true,
433
- import: "../mediaTypes",
444
+ import: '../mediaTypes',
434
445
  },
435
446
  webhooks: {
436
- output: "./src/webhooks",
447
+ output: './src/webhooks',
437
448
  split: true,
438
- import: "../webhooks",
449
+ import: '../webhooks',
439
450
  },
440
451
  },
441
452
  },
442
453
 
443
454
  // TypeScript type generation
444
455
  type: {
445
- output: "./src/types.ts",
456
+ output: './src/types.ts',
446
457
  readonly: true,
447
458
  },
448
459
 
449
460
  // RPC client generation
450
461
  rpc: {
451
- output: "./src/rpc",
452
- import: "../client", // Import path for the Hono RPC client
462
+ output: './src/rpc',
463
+ import: '../client', // Import path for the Hono RPC client
453
464
  split: true,
454
- client: "client", // Export name of the client instance
465
+ client: 'client', // Export name of the client instance
455
466
  parseResponse: true, // Use parseResponse for type-safe responses
456
467
  },
457
468
 
458
469
  // Client library integrations (TanStack Query, SWR, Svelte Query, Vue Query)
459
- "tanstack-query": {
460
- output: "./src/tanstack-query",
461
- import: "../client",
470
+ 'tanstack-query': {
471
+ output: './src/tanstack-query',
472
+ import: '../client',
462
473
  split: true,
463
- client: "client",
474
+ client: 'client',
464
475
  },
465
- "svelte-query": {
466
- output: "./src/svelte-query",
467
- import: "../client",
476
+ 'svelte-query': {
477
+ output: './src/svelte-query',
478
+ import: '../client',
468
479
  split: true,
469
- client: "client",
480
+ client: 'client',
470
481
  },
471
482
  swr: {
472
- output: "./src/swr",
473
- import: "../client",
483
+ output: './src/swr',
484
+ import: '../client',
474
485
  split: true,
475
- client: "client",
486
+ client: 'client',
476
487
  },
477
- "vue-query": {
478
- output: "./src/vue-query",
479
- import: "../client",
488
+ 'vue-query': {
489
+ output: './src/vue-query',
490
+ import: '../client',
480
491
  split: true,
481
- client: "client",
492
+ client: 'client',
482
493
  },
483
494
 
484
495
  // Test generation
485
496
  test: {
486
- output: "./src/test.ts",
487
- import: "../index", // Import path for the app instance
488
- framework: "vitest", // "vitest" (default) | "bun" — test import source
497
+ output: './src/test.ts',
498
+ import: '../index', // Import path for the app instance
499
+ framework: 'vitest', // "vitest" (default) | "bun" — test import source
489
500
  },
490
501
 
491
502
  // Mock server generation
492
503
  mock: {
493
- output: "./src/mock.ts",
504
+ output: './src/mock.ts',
494
505
  },
495
506
 
496
507
  // API reference docs generation
497
508
  docs: {
498
- output: "./docs/api.md",
499
- entry: "src/index.ts", // App entry point for hono request commands
509
+ output: './docs/api.md',
510
+ entry: 'src/index.ts', // App entry point for hono request commands
500
511
  curl: false, // true: generate curl commands (requires baseUrl), false: hono request (default)
501
- baseUrl: "http://localhost:3000", // Base URL for curl commands (required when curl: true)
512
+ baseUrl: 'http://localhost:3000', // Base URL for curl commands (required when curl: true)
502
513
  },
503
- });
514
+ })
504
515
  ```
505
516
 
506
517
  ## Projects Using Hono Takibi
@@ -532,4 +543,4 @@ If you find any issues with the generated code or have suggestions for improveme
532
543
 
533
544
  ## License
534
545
 
535
- Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hono-takibi?tab=MIT-1-ov-file) for more information.
546
+ Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hono-takibi?tab=MIT-1-ov-file) for more information.