hono-takibi 0.12.0 → 0.15.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/README.md CHANGED
@@ -4,32 +4,30 @@
4
4
 
5
5
  ![img](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/img/hono-takibi.png)
6
6
 
7
- **[Hono Takibi](https://www.npmjs.com/package/hono-takibi)** generates type-safe [Hono](https://hono.dev/) code from [OpenAPI](https://www.openapis.org/) / [TypeSpec](https://typespec.io/) specifications.
7
+ **[Hono Takibi](https://hono-takibi.dev/)** generates type-safe [Hono](https://hono.dev/) code from [OpenAPI](https://www.openapis.org/) / [TypeSpec](https://typespec.io/) specifications.
8
8
 
9
- - OpenAPI schemas to [Zod](https://zod.dev/) schemas
10
- - [@hono/zod-openapi](https://hono.dev/examples/zod-openapi) route definitions
11
- - App entry point + handler stubs + test files
12
- - Client library hooks (SWR, TanStack Query, Preact Query, Solid Query, Vue Query, Svelte Query, Angular Query)
13
- - RPC client, mock server, TypeScript types
14
- - API reference docs with [hono-cli](https://github.com/honojs/cli) commands
9
+ From one document it can generate:
15
10
 
16
- ## Quick Start
11
+ - [Zod](https://zod.dev/) schemas and [@hono/zod-openapi](https://hono.dev/examples/zod-openapi) route definitions
12
+ - App entry, handler stubs and test files
13
+ - RPC client and hooks for SWR, TanStack Query, Preact / Solid / Vue / Svelte / Angular Query
14
+ - Mock server, TypeScript types and API reference docs
15
+
16
+ 📖 **Documentation: [hono-takibi.dev](https://hono-takibi.dev/)** · 🔥 **[Playground](https://hono-takibi.dev/playground)**
17
17
 
18
- ### Installation
18
+ ## Quick Start
19
19
 
20
20
  ```bash
21
21
  npm install -D hono-takibi
22
22
  ```
23
23
 
24
- ### CLI
24
+ Pass an OpenAPI (`.yaml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
25
25
 
26
26
  ```bash
27
- npx hono-takibi path/to/input.{yaml,json,tsp} -o path/to/output.ts
27
+ npx hono-takibi openapi.yaml -o src/routes.ts
28
28
  ```
29
29
 
30
- ### Configuration File
31
-
32
- Create `hono-takibi.config.ts`:
30
+ For anything beyond a single routes file, create `hono-takibi.config.ts`:
33
31
 
34
32
  ```ts
35
33
  import { defineConfig } from 'hono-takibi'
@@ -44,999 +42,21 @@ export default defineConfig({
44
42
  npx hono-takibi
45
43
  ```
46
44
 
47
- ### CLI Reference
48
-
49
- `hono-takibi --help`:
50
-
51
- ```
52
- DESCRIPTION
53
- Generate @hono/zod-openapi code from OpenAPI or TypeSpec
54
-
55
- USAGE
56
- hono-takibi [flags] [<input>]
57
-
58
- ARGUMENTS
59
- input input.{yaml,json,tsp} OpenAPI (.yaml, .json) or TypeSpec (.tsp) document to generate from (optional)
60
-
61
- FLAGS
62
- --output, -o output.ts TypeScript file the generated routes are written to
63
- --config, -c file Config file to run (default: ./hono-takibi.config.ts)
64
- --watch, -w Rerun the config on every change to its documents or itself
65
-
66
- GLOBAL FLAGS
67
- --help, -h Show help information
68
- --version, -v Show version information
69
- --wizard Start wizard mode for a command
70
- --completions <bash|zsh|fish|sh> Print shell completion script (choices: bash, zsh, fish, sh)
71
- --log-level <all|trace|debug|info|warn|warning|error|fatal|none> Sets the minimum log level (choices: all, trace, debug, info, warn, warning, error, fatal, none)
72
-
73
- EXAMPLES
74
- # Generate a single routes file
75
- hono-takibi openapi.yaml -o src/routes.ts
76
-
77
- # Run every generator declared in ./hono-takibi.config.ts
78
- hono-takibi
79
-
80
- # Run a config file from another location
81
- hono-takibi --config config/api.config.ts
82
-
83
- # Rerun on every change to the input documents or the config
84
- hono-takibi --watch
85
- ```
86
-
87
- With an `<input>` the CLI writes a single routes file, and `-o` is required. With no
88
- `<input>` it runs the config file, which opts in the routes, components, webhooks,
89
- types, mock, docs, test and tanstack-query generators. Paths inside a config file
90
- resolve against the current directory, so `--config` names where the config lives, not
91
- where its outputs land.
92
-
93
- ### Watch mode
94
-
95
- ```bash
96
- npx hono-takibi --watch
97
- ```
98
-
99
- Reruns the config on every change to the input documents or to the config itself, and
100
- keeps watching when a run fails. Pairs with `template`: add an operation and its handler
101
- stub appears, while the code already written into the existing handlers stays put.
102
-
103
- The whole directory holding the input document is watched, so a TypeSpec entry that
104
- imports its siblings and an external `$ref` both trigger a rerun.
105
-
106
- ### Example
107
-
108
- input:
109
-
110
- ```yaml
111
- openapi: 3.1.0
112
- info:
113
- title: Hono Takibi API
114
- version: '1.0.0'
115
- paths:
116
- /:
117
- get:
118
- summary: Welcome
119
- description: Returns a welcome message from Hono Takibi.
120
- responses:
121
- '200':
122
- description: OK
123
- content:
124
- application/json:
125
- schema:
126
- type: object
127
- properties:
128
- message:
129
- type: string
130
- example: Hono Takibi🔥
131
- required:
132
- - message
133
- ```
134
-
135
- output:
136
-
137
- ```ts
138
- import { createRoute, z } from '@hono/zod-openapi'
139
-
140
- export const getRoute = createRoute({
141
- method: 'get',
142
- path: '/',
143
- summary: 'Welcome',
144
- description: 'Returns a welcome message from Hono Takibi.',
145
- responses: {
146
- 200: {
147
- description: 'OK',
148
- content: {
149
- 'application/json': {
150
- schema: z
151
- .object({
152
- message: z.string().openapi({ example: 'Hono Takibi🔥' }),
153
- })
154
- .openapi({ required: ['message'] }),
155
- },
156
- },
157
- },
158
- },
159
- })
160
- ```
161
-
162
- ## Vite Plugin
163
-
164
- Watches your OpenAPI spec and `hono-takibi.config.ts` for changes, then auto-regenerates code on save.
165
-
166
- Requires `hono-takibi.config.ts` in your project root.
167
-
168
- ```ts
169
- // vite.config.ts
170
- import { honoTakibiVite } from 'hono-takibi/vite-plugin'
171
- import { defineConfig } from 'vite'
172
-
173
- export default defineConfig({
174
- plugins: [honoTakibiVite()],
175
- })
176
- ```
177
-
178
- ![](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/vite/hono-takibi-vite.gif)
179
-
180
- ## Template & Test Generation
181
-
182
- Generate a complete app structure with handler stubs and test files:
183
-
184
- ```ts
185
- export default defineConfig({
186
- input: 'openapi.yaml',
187
- output: './src/routes.ts',
188
- template: {
189
- test: true,
190
- pathAlias: '@/',
191
- testFramework: 'bun', // "vitest" (default) | "vite-plus" | "bun"
192
- },
193
- })
194
- ```
195
-
196
- This generates:
197
-
198
- - `src/index.ts` - App entry point with route registrations
199
- - `src/handlers/*.ts` - Handler stubs, one file per tag (the first `tags` entry of each operation, lower camel case; the first path segment when an operation has no tag)
200
- - `src/handlers/*.test.ts` - Test files with `@faker-js/faker` mock data (imports from `vitest`, `vite-plus/test`, or `bun:test`)
201
-
202
- 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. The generator never deletes a file under `handlers/` and never re-stubs a handler that already exists in that directory: a handler you moved into another file (e.g. split by concern) is regenerated in place, files that hold no `*RouteHandler` export / `.openapi(xxxRoute)` registration / `*Route` export stay untouched, and their `export * from` lines in `handlers/index.ts` are kept. When a route leaves the spec, its handler declaration and route import are removed from whichever file holds them, but the file itself — and anything hand-written in it — remains; delete it by hand once nothing else is in it. Only top-level files in `handlers/` are scanned, not subdirectories.
203
-
204
- ### Handler Generation Modes
205
-
206
- #### `routeHandler: false` (default)
207
-
208
- Each handler creates its own sub-router and registers routes:
209
-
210
- ```ts
211
- // src/handlers/health.ts
212
- import { OpenAPIHono } from '@hono/zod-openapi'
213
- import { getHealthRoute } from '@/routes'
214
-
215
- const app = new OpenAPIHono()
216
-
217
- export const healthHandler = app.openapi(getHealthRoute, (c) => {})
218
- ```
219
-
220
- The app mounts handlers via `.route()`:
221
-
222
- ```ts
223
- // src/index.ts
224
- import { OpenAPIHono } from '@hono/zod-openapi'
225
- import { healthHandler } from './handlers'
226
-
227
- const app = new OpenAPIHono()
228
-
229
- export const api = app.route('/', healthHandler)
230
-
231
- export default app
232
- ```
233
-
234
- If you split routes into hand-written files in this mode, name each sub-router export `<fileBasename>Handler` (e.g. `export const sharesHandler = ...` in `shares.ts`) — that is the name the generator merges into and the app mounts.
235
-
236
- #### `routeHandler: true`
237
-
238
- Handlers export typed `RouteHandler` functions, and `index.ts` centralizes route registration:
239
-
240
- ```ts
241
- // src/handlers/health.ts
242
- import type { RouteHandler } from '@hono/zod-openapi'
243
- import type { getHealthRoute } from '../routes'
244
-
245
- export const getHealthRouteHandler: RouteHandler<typeof getHealthRoute> = async (c) => {}
246
- ```
247
-
248
- ```ts
249
- // src/index.ts
250
- import { OpenAPIHono } from '@hono/zod-openapi'
251
- import { getHealthRoute } from './routes'
252
- import { getHealthRouteHandler } from './handlers'
253
-
254
- const app = new OpenAPIHono()
255
-
256
- export const api = app.openapi(getHealthRoute, getHealthRouteHandler)
257
-
258
- export default app
259
- ```
260
-
261
- #### `define: true`
262
-
263
- ```ts
264
- export default defineConfig({
265
- input: 'openapi.yaml',
266
- template: { define: true },
267
- })
268
- ```
269
-
270
- ```ts
271
- // src/routes/users.ts
272
- export const getUsersIdRoute = defineOpenAPIRoute({
273
- route: createRoute({
274
- method: 'get',
275
- path: '/users/{id}',
276
- request: { params: z.object({ id: z.string() }) },
277
- responses: {
278
- 200: { description: 'ok', content: { 'application/json': { schema: UserSchema } } },
279
- },
280
- }),
281
- handler: async (c) => {},
282
- addRoute: true,
283
- })
284
- ```
285
-
286
- The app entry defaults to `src/index.ts` (override with `output`, which must be an `index.ts` path such as `./server/index.ts`). Route files always go to `routes/` next to the app entry, and component schemas to `components/index.ts` (override with `components.output`). When `output` is omitted, `components.output` also anchors the layout: `components: { output: './server/components/index.ts' }` puts the app entry at `server/index.ts` and routes at `server/routes/`.
287
-
288
- ## Client Library Integrations
289
-
290
- Supported: SWR, TanStack Query, Preact Query, Solid Query, Vue Query, Svelte Query, Angular Query, RPC Client.
291
-
292
- ```ts
293
- export default defineConfig({
294
- input: 'openapi.yaml',
295
- 'tanstack-query': {
296
- output: './src/tanstack-query',
297
- import: '../lib',
298
- split: true,
299
- client: 'client',
300
- },
301
- })
302
- ```
303
-
304
- ### Infinite Query (`x-pagination`)
305
-
306
- Set `x-pagination: true` on a GET operation to generate infinite query hooks.
307
-
308
- ```yaml
309
- paths:
310
- /posts:
311
- get:
312
- x-pagination: true
313
- ```
314
-
315
- ### Generated hooks
316
-
317
- Every GET operation yields a key getter, an options factory, and a hook; every other method yields a mutation key getter, a `mutationOptions` factory, and a mutation hook.
318
-
319
- ```ts
320
- getUsersKey() // ['users'] — one per path prefix
321
- getUsersIdQueryKey(args) // ['users', '/users/:id', args] — header params are left out
322
- getItemsInfiniteQueryKey(args) // ['items', '/items', 'infinite', args]
323
- getPostUsersMutationKey() // ['users', '/users', 'POST']
324
-
325
- useUsersId(args, { query: { staleTime: 1_000 }, options: { headers } }, queryClient)
326
- usePostUsers({ mutation: { mutationKey: ['custom'], onSuccess } }, queryClient)
327
- ```
328
-
329
- - `options.query` is the library's options type without `queryKey` / `queryFn` (the hook supplies both); `options.mutation` leaves out `mutationFn`, and a `mutationKey` you pass wins over the generated one.
330
- - Query hooks spread their options factory, so `useUsersId(args, { query })` is `useQuery({ ...getUsersIdQueryOptions(args), ...query })`. The factories take the hooks' `<TData, TError>` (and `TPageParam` for infinite queries) for that reason; leave them off and a direct `getUsersIdQueryOptions(args)` call keeps the default types, ready for `prefetchQuery` / `getQueryData`. Vue Query hooks keep the inline form instead.
331
- - `options.options` is Hono's `ClientRequestOptions` (headers, fetch, init).
332
- - The trailing argument is the framework's own: a `QueryClient` (an accessor of one in Solid and Svelte), or `{ injector }` in Angular.
333
- - Vue hooks accept `Ref` / getter arguments and re-key the query when they change.
334
- - SWR mutations revalidate only their own key; pass `swrKey: getGetUsersKey()` to revalidate the list instead.
335
-
336
- ## Test & Mock Generation
337
-
338
- ### Test Generation
339
-
340
- ```ts
341
- export default defineConfig({
342
- input: 'openapi.yaml',
343
- test: {
344
- output: './src/test.ts',
345
- import: '.',
346
- testFramework: 'bun', // "vitest" (default) | "vite-plus" | "bun"
347
- },
348
- })
349
- ```
350
-
351
- ### Mock Server Generation
352
-
353
- ```ts
354
- export default defineConfig({
355
- input: 'openapi.yaml',
356
- mock: {
357
- output: './src/mock.ts',
358
- },
359
- })
360
- ```
361
-
362
- Each route answers its success response by default. Like [Prism](https://stoplight.io/open-source/prism), a request can pick any response or named example the document declares with the `Prefer` header (or the `__code` / `__example` query):
363
-
364
- ```bash
365
- curl -H 'Prefer: code=404' http://localhost:3000/orders/1 # the 404 response
366
- curl -H 'Prefer: example=pending' http://localhost:3000/orders/1 # a named example
367
- curl -H 'Prefer: code=404, example=gone' http://localhost:3000/orders/1
368
- curl 'http://localhost:3000/orders/1?__code=503'
369
- ```
370
-
371
- A code falls back to its `4XX` range, then `default`. A code or example the operation does not declare answers `500` with an `application/problem+json` body saying what is missing.
372
-
373
- ## API Reference Docs
374
-
375
- Generate API reference Markdown with [hono-cli](https://github.com/honojs/cli) `hono request` commands:
376
-
377
- ```ts
378
- export default defineConfig({
379
- input: 'openapi.yaml',
380
- docs: {
381
- output: './docs/api.md',
382
- entry: 'src/index.ts',
383
- },
384
- })
385
- ```
386
-
387
- Set `curl: true` with `baseUrl` to generate `curl` commands for a running server:
388
-
389
- ```ts
390
- export default defineConfig({
391
- input: 'openapi.yaml',
392
- docs: {
393
- output: './docs/api.md',
394
- curl: true,
395
- baseUrl: 'http://localhost:3000',
396
- },
397
- })
398
- ```
399
-
400
- ## Full Config Reference
401
-
402
- Some options are mutually exclusive: `output` ↔ `routes`, `template.define` ↔ `routes`, `components.output` ↔ per-type components, `template.define` ↔ `routeHandler`.
403
-
404
- Every generator needs its own `output` path, and a `split` directory belongs to the
405
- generator — its `.ts` files are removed before each run, so keep hand-written code
406
- elsewhere. `basePath`, `client` and `import` are checked here because they are spliced
407
- into the generated code verbatim.
408
-
409
- ```ts
410
- import { defineConfig } from 'hono-takibi'
411
-
412
- export default defineConfig({
413
- input: 'openapi.yaml',
414
-
415
- output: './src/routes.ts', // single-file mode; with template.define, the app entry (an index.ts path, default ./src/index.ts)
416
- basePath: '/api',
417
- readonly: true,
418
- // format: {}, // oxfmt FormatConfig
419
-
420
- template: {
421
- test: true,
422
- routeHandler: false, // true: RouteHandler exports
423
- define: false, // true: defineOpenAPIRoute output
424
- pathAlias: '@/',
425
- testFramework: 'vitest', // "vitest" | "vite-plus" | "bun"
426
- },
427
-
428
- exportSchemas: true,
429
- exportSchemasTypes: true,
430
- exportResponses: true,
431
- exportParameters: true,
432
- exportParametersTypes: true,
433
- exportExamples: true,
434
- exportRequestBodies: true,
435
- exportHeaders: true,
436
- exportHeadersTypes: true,
437
- exportSecuritySchemes: true,
438
- exportLinks: true,
439
- exportCallbacks: true,
440
- exportPathItems: true,
441
- exportMediaTypes: true,
442
- exportMediaTypesTypes: true,
45
+ ## Documentation
443
46
 
444
- routes: {
445
- output: './src/routes',
446
- split: true,
447
- import: '@packages/routes',
448
- },
449
-
450
- webhooks: {
451
- output: './src/webhooks',
452
- split: true,
453
- import: '@packages/webhooks',
454
- },
455
-
456
- // `output` (single file) and the per-type fields below (split) are mutually exclusive.
457
- // `exportTypes` applies only to schemas / parameters / headers / mediaTypes.
458
- components: {
459
- output: './src/components/index.ts',
460
-
461
- schemas: {
462
- output: './src/schemas',
463
- exportTypes: true,
464
- split: true,
465
- import: '../schemas',
466
- },
467
- responses: {
468
- output: './src/responses',
469
- split: true,
470
- import: '../responses',
471
- },
472
- parameters: {
473
- output: './src/parameters',
474
- exportTypes: true,
475
- split: true,
476
- import: '../parameters',
477
- },
478
- examples: {
479
- output: './src/examples',
480
- split: true,
481
- import: '../examples',
482
- },
483
- requestBodies: {
484
- output: './src/requestBodies',
485
- split: true,
486
- import: '../requestBodies',
487
- },
488
- headers: {
489
- output: './src/headers',
490
- exportTypes: true,
491
- split: true,
492
- import: '../headers',
493
- },
494
- securitySchemes: {
495
- output: './src/securitySchemes',
496
- split: true,
497
- import: '../securitySchemes',
498
- },
499
- links: {
500
- output: './src/links',
501
- split: true,
502
- import: '../links',
503
- },
504
- callbacks: {
505
- output: './src/callbacks',
506
- split: true,
507
- import: '../callbacks',
508
- },
509
- pathItems: {
510
- output: './src/pathItems',
511
- split: true,
512
- import: '../pathItems',
513
- },
514
- mediaTypes: {
515
- output: './src/mediaTypes',
516
- exportTypes: true,
517
- split: true,
518
- import: '../mediaTypes',
519
- },
520
- },
521
-
522
- type: {
523
- output: './src/types.ts',
524
- readonly: true,
525
- },
526
-
527
- rpc: {
528
- output: './src/rpc',
529
- import: '../lib',
530
- split: true,
531
- client: 'client',
532
- parseResponse: true,
533
- docs: false, // operation summary/description as JSDoc
534
- },
535
-
536
- swr: {
537
- output: './src/swr',
538
- import: '../lib',
539
- split: true,
540
- client: 'client',
541
- },
542
- 'tanstack-query': {
543
- output: './src/tanstack-query',
544
- import: '../lib',
545
- split: true,
546
- client: 'client',
547
- },
548
- 'preact-query': {
549
- output: './src/preact-query',
550
- import: '../lib',
551
- split: true,
552
- client: 'client',
553
- },
554
- 'solid-query': {
555
- output: './src/solid-query',
556
- import: '../lib',
557
- split: true,
558
- client: 'client',
559
- },
560
- 'vue-query': {
561
- output: './src/vue-query',
562
- import: '../lib',
563
- split: true,
564
- client: 'client',
565
- },
566
- 'svelte-query': {
567
- output: './src/svelte-query',
568
- import: '../lib',
569
- split: true,
570
- client: 'client',
571
- },
572
- 'angular-query': {
573
- output: './src/angular-query',
574
- import: '../lib',
575
- split: true,
576
- client: 'client',
577
- },
578
-
579
- test: {
580
- output: './src/test.ts',
581
- import: '.',
582
- testFramework: 'vitest', // "vitest" | "vite-plus" | "bun"
583
- },
584
-
585
- mock: {
586
- output: './src/mock.ts',
587
- useExamples: true, // true: response examples | 'all': also schema/property examples | false
588
- locale: 'en',
589
- seed: 42, // optional: same body per route on every request (snapshot-friendly)
590
- delay: false,
591
- arrayMin: 1,
592
- arrayMax: 10,
593
- },
594
-
595
- docs: {
596
- output: './docs/api.md',
597
- entry: 'src/index.ts',
598
- curl: false, // true: curl commands (requires baseUrl); false: hono request
599
- baseUrl: 'http://localhost:3000',
600
- },
601
- })
602
- ```
603
-
604
- ## Vendor Extensions (x-\*)
605
-
606
- hono-takibi reads `x-*` vendor extensions on your OpenAPI / JSON Schema to customize the generated Zod. Each extension maps 1:1 to a Zod feature.
607
-
608
- ### Custom Validation Error Messages
609
-
610
- Use `x-*` vendor extensions to attach custom Zod error messages, with **one extension per JSON Schema keyword** (1:1 mapping). The extension name follows the pattern `x-<jsonSchemaKeyword>-message` (e.g. `x-minLength-message`, `x-pattern-message`), plus four generic forms: `x-error-message`, `x-required-message`, `x-const-message`, `x-enum-message`.
611
-
612
- ```yaml
613
- name:
614
- type: string
615
- minLength: 1
616
- maxLength: 50
617
- x-error-message: 'Name must be a string'
618
- x-minLength-message: 'Name cannot be empty'
619
- x-maxLength-message: 'Name must be at most 50 characters'
620
- ```
621
-
622
- ```ts
623
- z.string({ error: 'Name must be a string' })
624
- .min(1, { error: 'Name cannot be empty' })
625
- .max(50, { error: 'Name must be at most 50 characters' })
626
- ```
627
-
628
- All custom message extensions follow the `x-<keyword>-message` naming convention and map directly to Zod validator error messages.
629
-
630
- #### Common (any schema type)
631
-
632
- | Extension | Applies to |
633
- | -------------------- | -------------------------------------------------------------- |
634
- | `x-error-message` | All schemas (fallback when keyword-specific message is absent) |
635
- | `x-required-message` | Required properties |
636
- | `x-const-message` | `const` |
637
- | `x-enum-message` | `enum` |
638
-
639
- #### Numeric (number / integer)
640
-
641
- | Extension | Applies to |
642
- | ---------------------------- | ------------------ |
643
- | `x-minimum-message` | `minimum` |
644
- | `x-maximum-message` | `maximum` |
645
- | `x-exclusiveMinimum-message` | `exclusiveMinimum` |
646
- | `x-exclusiveMaximum-message` | `exclusiveMaximum` |
647
- | `x-multipleOf-message` | `multipleOf` |
648
-
649
- #### String
650
-
651
- | Extension | Applies to |
652
- | --------------------- | ------------------------------------------ |
653
- | `x-minLength-message` | `minLength` |
654
- | `x-maxLength-message` | `maxLength` |
655
- | `x-pattern-message` | `pattern` |
656
- | `x-length-message` | Exact length (`minLength` === `maxLength`) |
657
-
658
- #### Array
659
-
660
- | Extension | Applies to |
661
- | ----------------------- | ------------- |
662
- | `x-minItems-message` | `minItems` |
663
- | `x-maxItems-message` | `maxItems` |
664
- | `x-uniqueItems-message` | `uniqueItems` |
665
- | `x-contains-message` | `contains` |
666
- | `x-minContains-message` | `minContains` |
667
- | `x-maxContains-message` | `maxContains` |
668
-
669
- #### Object
670
-
671
- | Extension | Applies to |
672
- | -------------------------------- | ---------------------- |
673
- | `x-minProperties-message` | `minProperties` |
674
- | `x-maxProperties-message` | `maxProperties` |
675
- | `x-additionalProperties-message` | `additionalProperties` |
676
- | `x-propertyNames-message` | `propertyNames` |
677
- | `x-patternProperties-message` | `patternProperties` |
678
- | `x-dependentRequired-message` | `dependentRequired` |
679
- | `x-dependentSchemas-message` | `dependentSchemas` |
680
-
681
- #### Combinators
682
-
683
- | Extension | Applies to |
684
- | ----------------------- | ---------------------------------------------------------------------------------------------------------------- |
685
- | `x-allOf-message` | `allOf` |
686
- | `x-anyOf-message` | `anyOf` |
687
- | `x-oneOf-message` | `oneOf` |
688
- | `x-not-message` | `not` |
689
- | `x-implication-message` | Implication pattern (`A → B`) encoded as `anyOf:[{not:A},{required:B}]`; takes precedence over `x-anyOf-message` |
690
-
691
- #### Conditional
692
-
693
- | Extension | Applies to |
694
- | ---------------- | ---------- |
695
- | `x-if-message` | `if` |
696
- | `x-then-message` | `then` |
697
- | `x-else-message` | `else` |
698
-
699
- #### Typeless / Array Applicator
700
-
701
- | Extension | Applies to |
702
- | --------------------------------- | ------------------------------- |
703
- | `x-properties-message` | `properties` (typeless schemas) |
704
- | `x-prefixItems-message` | `prefixItems` |
705
- | `x-items-message` | `items` |
706
- | `x-unevaluatedProperties-message` | `unevaluatedProperties` |
707
- | `x-unevaluatedItems-message` | `unevaluatedItems` |
708
-
709
- ### Behavior Extensions
710
-
711
- #### String Pre-validation Transforms
712
-
713
- | Extension | Generated | Value |
714
- | --------------- | ----------------------------- | --------------------------------------- |
715
- | `x-trim` | `z.string().trim()` | `true` |
716
- | `x-toLowerCase` | `z.string().toLowerCase()` | `true` |
717
- | `x-toUpperCase` | `z.string().toUpperCase()` | `true` |
718
- | `x-normalize` | `z.string().normalize('NFC')` | `'NFC'` / `'NFD'` / `'NFKC'` / `'NFKD'` |
719
-
720
- ```yaml
721
- homepage:
722
- type: string
723
- format: url
724
- x-trim: true
725
- ```
726
-
727
- ```ts
728
- z.string().trim().pipe(z.url())
729
- ```
730
-
731
- #### String Validation Checks
732
-
733
- | Extension | Generated | Value |
734
- | ------------- | ------------------------ | ------ |
735
- | `x-lowercase` | `z.string().lowercase()` | `true` |
736
- | `x-uppercase` | `z.string().uppercase()` | `true` |
737
-
738
- ```yaml
739
- slug:
740
- type: string
741
- x-lowercase: true
742
- ```
743
-
744
- ```ts
745
- z.string().lowercase()
746
- ```
747
-
748
- #### Preprocess
749
-
750
- **`x-preprocess`**
751
-
752
- ```yaml
753
- username:
754
- type: string
755
- x-preprocess: 'z.preprocess((val) => typeof val === "string" ? val.trim() : val, z.string())'
756
- ```
757
-
758
- ```ts
759
- z.preprocess((val) => (typeof val === 'string' ? val.trim() : val), z.string())
760
- ```
761
-
762
- #### Type Coercion
763
-
764
- **`x-coerce`**
765
-
766
- ```yaml
767
- asNumber:
768
- type: number
769
- x-coerce: true
770
- asDate:
771
- type: string
772
- format: date-time
773
- x-coerce: true
774
- ```
775
-
776
- ```ts
777
- z.coerce.number()
778
- z.coerce.date()
779
- ```
780
-
781
- **`x-stringbool`**
782
-
783
- ```yaml
784
- notify:
785
- type: boolean
786
- x-stringbool: true
787
- ```
788
-
789
- ```ts
790
- z.stringbool()
791
- ```
792
-
793
- ```yaml
794
- notify:
795
- type: boolean
796
- x-stringbool:
797
- truthy: ['yes', 'on']
798
- falsy: ['no', 'off']
799
- case: 'sensitive'
800
- ```
801
-
802
- ```ts
803
- z.stringbool({ truthy: ['yes', 'on'], falsy: ['no', 'off'], case: 'sensitive' })
804
- ```
805
-
806
- #### Codec
807
-
808
- **`x-codec`**
809
-
810
- ```yaml
811
- updatedAt:
812
- type: string
813
- format: date-time
814
- x-codec: 'z.codec(z.iso.datetime(), z.date(), { decode: (isoString) => new Date(isoString), encode: (date) => date.toISOString() })'
815
- ```
816
-
817
- ```ts
818
- z.codec(z.iso.datetime(), z.date(), {
819
- decode: (isoString) => new Date(isoString),
820
- encode: (date) => date.toISOString(),
821
- })
822
- ```
823
-
824
- #### Custom Validation
825
-
826
- **`x-refine`**
827
-
828
- ```yaml
829
- password:
830
- type: string
831
- x-refine: '.refine((val) => val.length >= 8, { message: "Password must be at least 8 characters" }).refine((val) => /[A-Z]/.test(val), { message: "Password must contain an uppercase letter" })'
832
- ```
833
-
834
- ```ts
835
- z.string()
836
- .refine((val) => val.length >= 8, { message: 'Password must be at least 8 characters' })
837
- .refine((val) => /[A-Z]/.test(val), { message: 'Password must contain an uppercase letter' })
838
- ```
839
-
840
- **`x-superRefine`**
841
-
842
- ```yaml
843
- normalizedEmail:
844
- type: string
845
- format: email
846
- x-superRefine: '.superRefine((val, ctx) => { if (val.endsWith("@blocked.example")) ctx.addIssue({ code: "custom", message: "Blocked domain" }) })'
847
- ```
848
-
849
- ```ts
850
- z.email().superRefine((val, ctx) => {
851
- if (val.endsWith('@blocked.example')) {
852
- ctx.addIssue({ code: 'custom', message: 'Blocked domain' })
853
- }
854
- })
855
- ```
856
-
857
- #### Transform & Pipe
858
-
859
- **`x-transform`**
860
-
861
- ```yaml
862
- code:
863
- type: string
864
- x-transform: 'z.string().transform((val) => val.toUpperCase())'
865
- ```
866
-
867
- ```ts
868
- z.string().transform((val) => val.toUpperCase())
869
- ```
870
-
871
- **`x-pipe`**
872
-
873
- ```yaml
874
- port:
875
- type: string
876
- x-pipe: 'z.string().pipe(z.number().int().positive())'
877
- ```
878
-
879
- ```ts
880
- z.string().pipe(z.number().int().positive())
881
- ```
882
-
883
- #### Default & Fallback Values
884
-
885
- **`x-prefault`**
886
-
887
- ```yaml
888
- greeting:
889
- type: string
890
- x-prefault: 'hello'
891
- ```
892
-
893
- ```ts
894
- z.string().prefault('hello')
895
- ```
896
-
897
- **`x-catch`**
898
-
899
- ```yaml
900
- retries:
901
- type: integer
902
- x-catch: 0
903
- ```
904
-
905
- ```ts
906
- z.int().catch(0)
907
- ```
908
-
909
- #### Immutability
910
-
911
- **`x-readonly`**
912
-
913
- ```yaml
914
- config:
915
- type: object
916
- properties:
917
- name:
918
- type: string
919
- x-readonly: true
920
- ```
921
-
922
- ```ts
923
- z.object({ name: z.string() }).readonly()
924
- ```
925
-
926
- #### String Content Checks
927
-
928
- **`x-startsWith` / `x-endsWith` / `x-includes`**
929
-
930
- ```yaml
931
- url:
932
- type: string
933
- x-startsWith: 'https://'
934
- x-endsWith: '.com'
935
- path:
936
- type: string
937
- x-includes: '/api/'
938
- ```
939
-
940
- ```ts
941
- z.string().startsWith('https://').endsWith('.com')
942
- z.string().includes('/api/')
943
- ```
944
-
945
- #### Format-Specific Options
946
-
947
- ```yaml
948
- htmlEmail:
949
- type: string
950
- format: email
951
- x-emailPattern: 'html5' # email pattern preset
952
- uuidV7:
953
- type: string
954
- format: uuid
955
- x-uuidVersion: v7 # uuid version
956
- httpsUrl:
957
- type: string
958
- format: uri
959
- x-urlProtocol: '^https$' # url protocol regex
960
- x-urlNormalize: true
961
- preciseDatetime:
962
- type: string
963
- format: date-time
964
- x-isoPrecision: 3 # iso datetime precision / offset / local
965
- x-isoOffset: true
966
- ```
967
-
968
- | Extension | Maps to | Values |
969
- | ---------------- | ------------------------------- | ----------------------------------------------------- |
970
- | `x-emailPattern` | `z.email({ pattern })` | `html5` / `rfc5322` / `unicode` |
971
- | `x-emailRegex` | `z.email({ pattern: /.../ })` | custom regex string |
972
- | `x-uuidVersion` | `z.uuid({ version })` | `v1` / `v2` / `v3` / `v4` / `v5` / `v6` / `v7` / `v8` |
973
- | `x-urlProtocol` | `z.url({ protocol: /.../ })` | regex string |
974
- | `x-urlHostname` | `z.url({ hostname: /.../ })` | regex string |
975
- | `x-urlNormalize` | `z.url({ normalize })` | `true` / `false` |
976
- | `x-isoPrecision` | `z.iso.datetime({ precision })` | fractional second digits |
977
- | `x-isoOffset` | `z.iso.datetime({ offset })` | `true` / `false` |
978
- | `x-isoLocal` | `z.iso.datetime({ local })` | `true` / `false` |
979
- | `x-macDelimiter` | `z.mac({ delimiter })` | `:` / `-` / `.` |
980
- | `x-jwtAlg` | `z.jwt({ alg })` | `HS256` etc. |
981
- | `x-hashAlg` | `z.hash(alg, ...)` | `sha256` etc. |
982
- | `x-hashEnc` | `z.hash(alg, { enc })` | `hex` / `base64` / `base64url` |
983
-
984
- ### Branded Types (x-brand)
985
-
986
- Use the `x-brand` vendor extension to generate [Zod branded types](https://zod.dev/api?id=branded-types), creating nominal types that are structurally identical but semantically distinct:
987
-
988
- ```yaml
989
- components:
990
- schemas:
991
- Cat:
992
- type: object
993
- properties:
994
- name:
995
- type: string
996
- required:
997
- - name
998
- x-brand: Cat
999
- Dog:
1000
- type: object
1001
- properties:
1002
- name:
1003
- type: string
1004
- required:
1005
- - name
1006
- x-brand: Dog
1007
- ```
1008
-
1009
- ```ts
1010
- // Generated output
1011
- const CatSchema = z.object({ name: z.string() }).brand<'Cat'>().openapi('Cat')
1012
-
1013
- const DogSchema = z.object({ name: z.string() }).brand<'Dog'>().openapi('Dog')
1014
- ```
47
+ - [Getting Started](https://hono-takibi.dev/docs)
48
+ - [Configuration](https://hono-takibi.dev/docs/guides/config)
49
+ - [Template](https://hono-takibi.dev/docs/guides/template)
50
+ - [Client](https://hono-takibi.dev/docs/guides/client)
51
+ - [Test & Mock](https://hono-takibi.dev/docs/guides/test-mock)
52
+ - [API Docs](https://hono-takibi.dev/docs/guides/api-docs)
53
+ - [Vendor Extensions](https://hono-takibi.dev/docs/guides/vendor)
54
+ - [Vite Plugin](https://hono-takibi.dev/docs/guides/vite-plugin)
1015
55
 
1016
56
  ## Projects Using Hono Takibi
1017
57
 
1018
58
  - **[resend-local](https://github.com/y-hiraoka/resend-local)** — A local emulator for the Resend email API.
1019
59
 
1020
- ## Contributing
1021
-
1022
- We welcome feedback and contributions to improve the tool!
1023
-
1024
- If you find any issues with the generated code or have suggestions for improvements, please:
1025
-
1026
- - Open an issue at [GitHub Issues](https://github.com/nakita628/hono-takibi/issues)
1027
- - Submit a pull request with your improvements
1028
-
1029
- Lint and tests run from the repo root:
1030
-
1031
- ```bash
1032
- pnpm check # format, lint, type checks, then `pnpm lint`
1033
- pnpm lint # what the Lint workflow runs
1034
- pnpm lint:actions # actionlint (syntax) and zizmor (security) over .github/workflows, when installed
1035
- pnpm test # unit tests, then the generated cases under test/
1036
- ```
1037
-
1038
- `actionlint` and `zizmor` are not npm packages: install them with `pipx install actionlint-py` and `pipx install zizmor` to run them locally; without them the script only prints a note. The Lint workflow always runs both.
1039
-
1040
60
  ## License
1041
61
 
1042
62
  Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hono-takibi?tab=MIT-1-ov-file) for more information.