hono-takibi 0.9.30 → 0.9.40

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
@@ -112,101 +112,152 @@ template
112
112
  npx hono-takibi path/to/input.{yaml,json,tsp} -o path/to/output.ts --export-type --export-schema --template --base-path '/api/v1'
113
113
  ```
114
114
 
115
- ## HonoTakibiVite
115
+ ## Configuration File (`hono-takibi.config.ts`)
116
116
 
117
- ### Automatic Code Regeneration & HMR
117
+ Config used by both the CLI and the Vite plugin.
118
118
 
119
- With **HonoTakibiVite**, saving your OpenAPI spec while the Vite dev server is running instantly regenerates the code.
119
+ ## Essentials
120
120
 
121
- ### OpenAPI Schema Requirements
121
+ * Put **`hono-takibi.config.ts`** at repo root.
122
+ * Default‑export with `defineConfig(...)`.
123
+ * `input`: **`openapi.yaml`** (recommended), or `*.json` / `*.tsp`.
122
124
 
123
- - Your OpenAPI definition must include **only the `#/components/schemas/` section**.
124
- - It must be fully compliant with **OpenAPI 3.0 or later (e.g., 3.0 or 3.1)**.
125
- - Do **not** include `paths`, `tags`, or any other OpenAPI sections.
125
+ > **About `split`**
126
+ >
127
+ > * `split: true` `output` is a **directory**; many files + `index.ts`.
128
+ > * `split` **omitted** or `false` → `output` is a **single `*.ts` file** (one file only).
126
129
 
127
- ### Supported Input Formats
130
+ ---
128
131
 
129
- You may specify the input file in one of the following formats:
132
+ ## Single‑file
130
133
 
131
- - `.yaml` OpenAPI YAML (schemas only)
132
- - `.json` — OpenAPI JSON (schemas only)
133
- - `.tsp` — TypeSpec source file
134
+ One file. Set top‑level `output` (don’t define `schema`/`route`).
134
135
 
135
- ### TypeSpec Setup (if using `.tsp`)
136
+ ```ts
137
+ import { defineConfig } from 'hono-takibi/config'
136
138
 
137
- If you use a `.tsp` TypeSpec file, you must set up the TypeSpec environment and install required libraries:
139
+ export default defineConfig({
140
+ input: 'openapi.yaml',
141
+ 'zod-openapi': {
142
+ output: './src/index.ts',
143
+ exportSchema: true,
144
+ exportType: true,
145
+ },
146
+ })
147
+ ```
138
148
 
139
- - @typespec/http
140
- - @typespec/rest
141
- - ...other
149
+ ---
142
150
 
143
- ### Example
151
+ ## Schemas & Routes
144
152
 
145
- `vite.config.ts`
153
+ Define **both** `schema` and `route` (don’t set top‑level `output`).
146
154
 
147
155
  ```ts
148
- import { defineConfig } from 'vite'
149
- import { HonoTakibiVite } from 'hono-takibi/vite-plugin'
156
+ import { defineConfig } from 'hono-takibi/config'
150
157
 
151
158
  export default defineConfig({
152
- plugins: [
153
- HonoTakibiVite({
154
- input: 'main.tsp',
155
- output: 'index.ts',
156
- exportType: true,
157
- exportSchema: true,
158
- }),
159
- ],
159
+ input: 'openapi.yaml',
160
+ 'zod-openapi': {
161
+ // split ON → outputs are directories
162
+ schema: { output: './src/schemas', split: true },
163
+ route: { output: './src/routes', import: '../schemas', split: true },
164
+
165
+ // split OFF example (one file each):
166
+ // schema: { output: './src/schemas/index.ts' },
167
+ // route: { output: './src/routes/index.ts', import: '../schemas' },
168
+ },
160
169
  })
161
170
  ```
162
171
 
163
- ### Demo
172
+ ---
164
173
 
165
- ![](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/vite/hono-takibi-vite.gif)
174
+ ## RPC (optional)
166
175
 
176
+ Works with either pattern.
167
177
 
168
- ## With AI Prompt
178
+ * `split: true` → `output` is a **directory**; many files + `index.ts`.
179
+ * `split` **omitted** or `false` → `output` is **one `*.ts` file**.
169
180
 
170
- ### Sample Prompt — Schemas-Only Extractor (OpenAPI 3+)
181
+ **Example (split: true)**
171
182
 
172
- A copy‑and‑paste prompt for **any LLM** that extracts **only** the contents of `#/components/schemas/` from an OpenAPI document.
183
+ ```ts
184
+ import { defineConfig } from 'hono-takibi/config'
185
+
186
+ export default defineConfig({
187
+ input: 'openapi.yaml',
188
+ 'zod-openapi': { output: './src/index.ts', exportSchema: true, exportType: true },
189
+ rpc: { output: './src/rpc', import: '../client', split: true },
190
+ })
191
+ ```
173
192
 
174
- ## Prompt Example
193
+ **Example (single file; split omitted/false)**
175
194
 
176
- ```md
177
- You are a **Schemas‑Only Extractor** for OpenAPI 3+.
195
+ ```ts
196
+ import { defineConfig } from 'hono-takibi/config'
197
+
198
+ export default defineConfig({
199
+ input: 'openapi.yaml',
200
+ 'zod-openapi': { output: './src/index.ts', exportSchema: true, exportType: true },
201
+ rpc: { output: './src/rpc/index.ts', import: '../client' },
202
+ })
203
+ ```
204
+
205
+ ---
206
+
207
+ ## Vite Plugin (`honoTakibiVite`)
208
+
209
+ Auto‑regenerates on changes and reloads dev server.
210
+
211
+ ```ts
212
+ // vite.config.ts
213
+ import { honoTakibiVite } from 'hono-takibi/vite-plugin'
214
+ import { defineConfig } from 'vite'
215
+
216
+ export default defineConfig({
217
+ plugins: [honoTakibiVite()],
218
+ })
219
+ ```
220
+
221
+ **What it does**
222
+
223
+ * **Watches**: the config, your `input`, and nearby `**/*.{yaml,json,tsp}`.
224
+ * **Generates** outputs per your config (single‑file or split, plus `rpc`).
225
+ * **Cleans** old generated files safely when paths or `split` change.
226
+
227
+ That’s it — set `input`, choose one of the two patterns, and (optionally) add `rpc`. ✅
228
+
229
+ ### Demo (Vite + HMR)
230
+
231
+ ![](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/vite/hono-takibi-vite.gif)
178
232
 
179
- ## 1. Version
180
- - Accept files that start with `openapi: "3.0.0"` or newer.
181
- - Otherwise reply with: `Unsupported OpenAPI version (must be 3.0+).`
182
233
 
183
- ## 2. Scope
184
- - Look **only** inside `#/components/schemas/`. Ignore everything else.
185
- - `$ref` must also point inside that section.
234
+ ## AI Prompt Example
186
235
 
187
- ## 3. Schemas section present?
188
- - If `components.schemas` is missing, reply with: `Missing '#/components/schemas/' section. Cannot proceed.`
236
+ ```sh
237
+ Generate one **OpenAPI 3.x+** YAML (prefer **3.1.0**).
189
238
 
190
- ## 4. File type
191
- - Accept **.yaml**, **.json**, or **.tsp** files.
192
- - Otherwise reply with: `Unsupported input file extension.`
239
+ Rules:
240
+ - Use only `components.schemas` (no other `components`).
241
+ - Never include `parameters:`.
242
+ - No path params; all inputs in `requestBody` (`application/json`) with `$ref: '#/components/schemas/*'`.
243
+ - All responses use `application/json` with `$ref: '#/components/schemas/*'`.
244
+ - POST-only action routes: `/resource/create|get|search|update|delete`.
245
+ - No inline schemas in `paths`.
193
246
 
194
- ## Format tips
195
- - `format: uuid` usually means **UUID v4**.
196
- - Other accepted identifiers include `uuidv6`, `uuidv7`, `ulid`, `cuid`, etc.
197
- - With **hono‑takibi**, you can generate **Zod schemas** directly from a custom OpenAPI file.
247
+ Fill, then generate:
248
+ - title / version / tags
249
+ - resources & fields
250
+ - ops per resource: create / get / search / update / delete
198
251
 
199
- ## What the LLM should do
200
- 1. Validate the file with the four rules above.
201
- 2. If it passes, output **only** the YAML/JSON fragment under `#/components/schemas/` (preserve indentation).
202
- 3. Otherwise, output the exact error message above—nothing more.
252
+ **Output format (strict):**
253
+ - Return a **single fenced code block** labeled `yaml` that contains **only** the YAML.
254
+ - No text before or after the code block.
203
255
  ```
204
256
 
205
257
  ### ⚠️ WARNING: Potential Breaking Changes Without Notice
206
258
 
207
259
  **This package is in active development and may introduce breaking changes without prior notice.**
208
260
  Specifically:
209
- - Query parameter coercion behavior may change
210
261
  - Schema generation logic might be updated
211
262
  - Output code structure could be modified
212
263
  - Example value handling might be altered
@@ -1 +1 @@
1
- export declare function HonoTakibiVite(): any;
1
+ export declare function honoTakibiVite(): any;
@@ -397,7 +397,7 @@ const outputDirsFromConf = (c) => {
397
397
  * Plugin (return `any`, no `let`)
398
398
  * ────────────────────────────────────────────────────────────── */
399
399
  // biome-ignore lint: plugin
400
- export function HonoTakibiVite() {
400
+ export function honoTakibiVite() {
401
401
  const state = { current: null };
402
402
  const absConfig = path.resolve(process.cwd(), 'hono-takibi.config.ts');
403
403
  const run = async () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
3
  "description": "Hono Takibi is a CLI tool that generates Hono routes from OpenAPI specifications.",
4
- "version": "0.9.30",
4
+ "version": "0.9.40",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [