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 +108 -57
- package/dist/vite-plugin/index.d.ts +1 -1
- package/dist/vite-plugin/index.js +1 -1
- package/package.json +1 -1
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
|
-
##
|
|
115
|
+
## Configuration File (`hono-takibi.config.ts`)
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
Config used by both the CLI and the Vite plugin.
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
## Essentials
|
|
120
120
|
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
130
|
+
---
|
|
128
131
|
|
|
129
|
-
|
|
132
|
+
## Single‑file
|
|
130
133
|
|
|
131
|
-
|
|
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
|
-
|
|
136
|
+
```ts
|
|
137
|
+
import { defineConfig } from 'hono-takibi/config'
|
|
136
138
|
|
|
137
|
-
|
|
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
|
-
|
|
140
|
-
- @typespec/rest
|
|
141
|
-
- ...other
|
|
149
|
+
---
|
|
142
150
|
|
|
143
|
-
|
|
151
|
+
## Schemas & Routes
|
|
144
152
|
|
|
145
|
-
`
|
|
153
|
+
Define **both** `schema` and `route` (don’t set top‑level `output`).
|
|
146
154
|
|
|
147
155
|
```ts
|
|
148
|
-
import { defineConfig } from '
|
|
149
|
-
import { HonoTakibiVite } from 'hono-takibi/vite-plugin'
|
|
156
|
+
import { defineConfig } from 'hono-takibi/config'
|
|
150
157
|
|
|
151
158
|
export default defineConfig({
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
172
|
+
---
|
|
164
173
|
|
|
165
|
-
|
|
174
|
+
## RPC (optional)
|
|
166
175
|
|
|
176
|
+
Works with either pattern.
|
|
167
177
|
|
|
168
|
-
|
|
178
|
+
* `split: true` → `output` is a **directory**; many files + `index.ts`.
|
|
179
|
+
* `split` **omitted** or `false` → `output` is **one `*.ts` file**.
|
|
169
180
|
|
|
170
|
-
|
|
181
|
+
**Example (split: true)**
|
|
171
182
|
|
|
172
|
-
|
|
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
|
-
|
|
193
|
+
**Example (single file; split omitted/false)**
|
|
175
194
|
|
|
176
|
-
```
|
|
177
|
-
|
|
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
|
+

|
|
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
|
-
##
|
|
184
|
-
- Look **only** inside `#/components/schemas/`. Ignore everything else.
|
|
185
|
-
- `$ref` must also point inside that section.
|
|
234
|
+
## AI Prompt Example
|
|
186
235
|
|
|
187
|
-
|
|
188
|
-
|
|
236
|
+
```sh
|
|
237
|
+
Generate one **OpenAPI 3.x+** YAML (prefer **3.1.0**).
|
|
189
238
|
|
|
190
|
-
|
|
191
|
-
-
|
|
192
|
-
-
|
|
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
|
-
|
|
195
|
-
-
|
|
196
|
-
-
|
|
197
|
-
-
|
|
247
|
+
Fill, then generate:
|
|
248
|
+
- title / version / tags
|
|
249
|
+
- resources & fields
|
|
250
|
+
- ops per resource: create / get / search / update / delete
|
|
198
251
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
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
|
|
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 () => {
|