Hono Takibi
Hono Takibi generates type-safe Hono code from OpenAPI / TypeSpec specifications.
From one document it can generate:
- Zod schemas and @hono/zod-openapi route definitions
- App entry and handler stubs
- RPC client and hooks for SWR, TanStack Query, Preact / Solid / Vue / Svelte / Angular Query
- Mock server, TypeScript types and API reference docs
Pre-1.0
Hono Takibi is under active development and has not reached a stable release yet. Until 1.0, minor releases (0.x → 0.y) may include breaking changes to the CLI, the config and the generated code. Patch releases are safe to update.
Installation
sh
npm install -D hono-takibish
yarn add -D hono-takibish
pnpm add -D hono-takibish
bun add -D hono-takibiUsage
Pass an OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document and an output file:
sh
npx hono-takibi openapi.yaml -o src/routes.tssh
yarn hono-takibi openapi.yaml -o src/routes.tssh
pnpm hono-takibi openapi.yaml -o src/routes.tssh
bunx hono-takibi openapi.yaml -o src/routes.tsFor anything beyond a single routes file, use a config file.
Example
input:
yaml
openapi: 3.1.0
info:
title: Hono Takibi API
version: '1.0.0'
paths:
/:
get:
summary: Welcome
description: Returns a welcome message from Hono Takibi.
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Hono Takibi🔥
required:
- messageoutput:
ts
import { createRoute, z } from '@hono/zod-openapi'
export const getRoute = createRoute({
method: 'get',
path: '/',
summary: 'Welcome',
description: 'Returns a welcome message from Hono Takibi.',
responses: {
200: {
description: 'OK',
content: {
'application/json': {
schema: z
.object({
message: z.string().openapi({ example: 'Hono Takibi🔥' }),
})
.openapi({ required: ['message'] }),
},
},
},
},
})Try it in the Playground.
CLI
hono-takibi --help:
DESCRIPTION
Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi
USAGE
hono-takibi [flags] [<input>]
ARGUMENTS
input input.{yaml,yml,json,tsp} OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document to generate from (optional)
FLAGS
--output, -o output.ts TypeScript file the generated routes are written to
--config, -c file Config file to run (default: ./hono-takibi.config.ts)
--watch, -w Rerun the config on every change to its documents or itself
GLOBAL FLAGS
--help, -h Show help information
--version, -v Show version information
--wizard Start wizard mode for a command
--completions <bash|zsh|fish|powershell|sh|pwsh> Print shell completion script (choices: bash, zsh, fish, powershell, sh, pwsh)
--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)
EXAMPLES
# Generate a single routes file
hono-takibi openapi.yaml -o src/routes.ts
# Run every generator declared in ./hono-takibi.config.ts
hono-takibi
# Run a config file from another location
hono-takibi --config config/api.config.ts
# Rerun on every change to the input documents or the config
hono-takibi --watch