hono-takibi 0.9.61 → 0.9.71
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 +112 -76
- package/dist/cli/index.d.ts +27 -22
- package/dist/cli/index.js +168 -85
- package/dist/config/index.d.ts +71 -10
- package/dist/config/index.js +226 -4
- package/dist/core/components/callbacks.d.ts +34 -0
- package/dist/core/components/callbacks.js +55 -0
- package/dist/core/components/examples.d.ts +34 -0
- package/dist/core/components/examples.js +55 -0
- package/dist/core/components/headers.d.ts +44 -0
- package/dist/core/components/headers.js +76 -0
- package/dist/core/components/index.d.ts +16 -0
- package/dist/core/components/index.js +18 -0
- package/dist/core/components/links.d.ts +34 -0
- package/dist/core/components/links.js +55 -0
- package/dist/core/components/parameters.d.ts +44 -0
- package/dist/core/components/parameters.js +76 -0
- package/dist/core/components/requestBodies.d.ts +41 -0
- package/dist/core/components/requestBodies.js +73 -0
- package/dist/core/components/responses.d.ts +41 -0
- package/dist/core/components/responses.js +73 -0
- package/dist/core/components/schemas.d.ts +37 -0
- package/dist/core/components/schemas.js +75 -0
- package/dist/core/components/securitySchemes.d.ts +34 -0
- package/dist/core/components/securitySchemes.js +55 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +11 -0
- package/dist/core/route/index.d.ts +55 -0
- package/dist/core/route/index.js +103 -0
- package/dist/core/rpc/index.d.ts +8 -0
- package/dist/core/rpc/index.js +491 -0
- package/dist/core/{takibi.d.ts → takibi/index.d.ts} +16 -11
- package/dist/core/takibi/index.js +71 -0
- package/dist/core/type/index.d.ts +39 -0
- package/dist/core/{type.js → type/index.js} +72 -24
- package/dist/format/index.d.ts +1 -7
- package/dist/format/index.js +11 -19
- package/dist/generator/zod-openapi-hono/app/index.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/app/index.js +18 -13
- package/dist/generator/zod-openapi-hono/openapi/components/callbacks.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/callbacks.js +19 -0
- package/dist/generator/zod-openapi-hono/openapi/components/examples.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/examples.js +11 -0
- package/dist/generator/zod-openapi-hono/openapi/components/headers.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/headers.js +30 -0
- package/dist/generator/zod-openapi-hono/openapi/components/index.d.ts +16 -3
- package/dist/generator/zod-openapi-hono/openapi/components/index.js +26 -29
- package/dist/generator/zod-openapi-hono/openapi/components/links.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/links.js +12 -0
- package/dist/generator/zod-openapi-hono/openapi/components/parameters.d.ts +10 -0
- package/dist/generator/zod-openapi-hono/openapi/components/parameters.js +40 -0
- package/dist/generator/zod-openapi-hono/openapi/components/request-bodies.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/request-bodies.js +12 -0
- package/dist/generator/zod-openapi-hono/openapi/components/responses.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/responses.js +9 -0
- package/dist/generator/zod-openapi-hono/openapi/components/schemas.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/schemas.js +19 -0
- package/dist/generator/zod-openapi-hono/openapi/components/securitySchemes.d.ts +2 -0
- package/dist/generator/zod-openapi-hono/openapi/components/securitySchemes.js +11 -0
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +64 -4
- package/dist/generator/zod-openapi-hono/openapi/index.js +36 -9
- package/dist/generator/zod-openapi-hono/openapi/{route/route.d.ts → routes/create-route.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/routes/create-route.js +37 -0
- package/dist/generator/zod-openapi-hono/openapi/routes/index.d.ts +5 -0
- package/dist/generator/zod-openapi-hono/openapi/routes/index.js +42 -0
- package/dist/generator/zod-to-openapi/index.d.ts +46 -2
- package/dist/generator/zod-to-openapi/index.js +189 -73
- package/dist/generator/zod-to-openapi/type/index.d.ts +2 -0
- package/dist/generator/zod-to-openapi/type/index.js +17 -0
- package/dist/generator/zod-to-openapi/z/enum.js +24 -9
- package/dist/generator/zod-to-openapi/z/index.d.ts +0 -1
- package/dist/generator/zod-to-openapi/z/index.js +0 -1
- package/dist/generator/zod-to-openapi/z/object.js +10 -1
- package/dist/generator/zod-to-openapi/z/string.d.ts +1 -1
- package/dist/generator/zod-to-openapi/z/string.js +9 -4
- package/dist/helper/ast.d.ts +96 -0
- package/dist/helper/ast.js +297 -0
- package/dist/helper/barell.d.ts +3 -0
- package/dist/helper/barell.js +7 -0
- package/dist/helper/code.d.ts +27 -0
- package/dist/helper/code.js +68 -0
- package/dist/helper/core.d.ts +41 -0
- package/dist/helper/core.js +63 -0
- package/dist/helper/exports.d.ts +9 -0
- package/dist/helper/exports.js +29 -0
- package/dist/helper/handler.d.ts +16 -0
- package/dist/helper/handler.js +101 -0
- package/dist/helper/index.d.ts +9 -4
- package/dist/helper/index.js +8 -4
- package/dist/helper/openapi.d.ts +135 -0
- package/dist/helper/openapi.js +505 -0
- package/dist/helper/schema.d.ts +20 -0
- package/dist/helper/schema.js +66 -0
- package/dist/helper/type.d.ts +3 -0
- package/dist/helper/type.js +147 -0
- package/dist/helper/wrap.d.ts +58 -2
- package/dist/helper/wrap.js +163 -20
- package/dist/openapi/index.d.ts +372 -152
- package/dist/openapi/index.js +66 -27
- package/dist/utils/index.d.ts +70 -135
- package/dist/utils/index.js +117 -244
- package/dist/vite-plugin/index.d.ts +41 -0
- package/dist/vite-plugin/index.js +356 -324
- package/package.json +17 -13
- package/dist/core/route.d.ts +0 -7
- package/dist/core/route.js +0 -98
- package/dist/core/rpc.d.ts +0 -13
- package/dist/core/rpc.js +0 -339
- package/dist/core/schema.d.ts +0 -27
- package/dist/core/schema.js +0 -115
- package/dist/core/takibi.js +0 -183
- package/dist/core/type.d.ts +0 -7
- package/dist/generator/zod-openapi-hono/openapi/route/index.d.ts +0 -2
- package/dist/generator/zod-openapi-hono/openapi/route/index.js +0 -47
- package/dist/generator/zod-openapi-hono/openapi/route/params/index.d.ts +0 -3
- package/dist/generator/zod-openapi-hono/openapi/route/params/index.js +0 -3
- package/dist/generator/zod-openapi-hono/openapi/route/params/params-object.d.ts +0 -17
- package/dist/generator/zod-openapi-hono/openapi/route/params/params-object.js +0 -33
- package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.d.ts +0 -14
- package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.js +0 -24
- package/dist/generator/zod-openapi-hono/openapi/route/params/request-parameter.d.ts +0 -14
- package/dist/generator/zod-openapi-hono/openapi/route/params/request-parameter.js +0 -48
- package/dist/generator/zod-openapi-hono/openapi/route/request/body/index.d.ts +0 -10
- package/dist/generator/zod-openapi-hono/openapi/route/request/body/index.js +0 -22
- package/dist/generator/zod-openapi-hono/openapi/route/response/index.d.ts +0 -14
- package/dist/generator/zod-openapi-hono/openapi/route/response/index.js +0 -50
- package/dist/generator/zod-openapi-hono/openapi/route/route.js +0 -34
- package/dist/generator/zod-to-openapi/z/array.d.ts +0 -50
- package/dist/generator/zod-to-openapi/z/array.js +0 -68
- package/dist/helper/docs.d.ts +0 -14
- package/dist/helper/docs.js +0 -15
- package/dist/helper/properties-schema.d.ts +0 -46
- package/dist/helper/properties-schema.js +0 -61
- package/dist/helper/resolve-schemas-dependencies.d.ts +0 -13
- package/dist/helper/resolve-schemas-dependencies.js +0 -57
- package/dist/helper/zod-to-openapi-schema.d.ts +0 -14
- package/dist/helper/zod-to-openapi-schema.js +0 -30
- package/dist/typespec/index.d.ts +0 -33
- package/dist/typespec/index.js +0 -52
package/README.md
CHANGED
|
@@ -91,66 +91,144 @@ export const getRoute = createRoute({
|
|
|
91
91
|
|
|
92
92
|
### Options
|
|
93
93
|
|
|
94
|
-
basic
|
|
95
|
-
|
|
96
94
|
```bash
|
|
97
95
|
Options:
|
|
98
|
-
--export-
|
|
99
|
-
--export-
|
|
100
|
-
--
|
|
101
|
-
--
|
|
102
|
-
--
|
|
96
|
+
--export-schemas-types export schemas types
|
|
97
|
+
--export-schemas export schemas
|
|
98
|
+
--export-parameters-types export parameters types
|
|
99
|
+
--export-parameters export parameters
|
|
100
|
+
--export-security-schemes export securitySchemes
|
|
101
|
+
--export-request-bodies export requestBodies
|
|
102
|
+
--export-responses export responses
|
|
103
|
+
--export-headers-types export headers types
|
|
104
|
+
--export-headers export headers
|
|
105
|
+
--export-examples export examples
|
|
106
|
+
--export-links export links
|
|
107
|
+
--export-callbacks export callbacks
|
|
108
|
+
--template generate app file and handler stubs
|
|
109
|
+
--test generate empty *.test.ts files
|
|
110
|
+
--base-path <path> api prefix (default: /)
|
|
111
|
+
-h, --help display help for command
|
|
103
112
|
```
|
|
104
113
|
|
|
105
|
-
template
|
|
106
|
-
|
|
107
|
-
> **⚠️** When using the `--template` option, you must specify a valid directory path. Ensure the directory exists before executing the
|
|
114
|
+
> **⚠️** When using the `--template` option, you must specify a valid directory path. Ensure the directory exists before executing.
|
|
108
115
|
|
|
109
116
|
### Example
|
|
110
117
|
|
|
111
118
|
```bash
|
|
112
|
-
npx hono-takibi path/to/input.{yaml,json,tsp} -o path/to/output.ts --export-
|
|
119
|
+
npx hono-takibi path/to/input.{yaml,json,tsp} -o path/to/output.ts --export-schemas --export-schemas-types --template --base-path '/api/v1'
|
|
113
120
|
```
|
|
114
121
|
|
|
115
122
|
## Configuration File (`hono-takibi.config.ts`)
|
|
116
123
|
|
|
117
124
|
Config used by both the CLI and the Vite plugin.
|
|
118
125
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* Put **`hono-takibi.config.ts`** at repo root.
|
|
122
|
-
* Default‑export with `defineConfig(...)`.
|
|
123
|
-
* `input`: **`openapi.yaml`** (recommended), or `*.json` / `*.tsp`.
|
|
124
|
-
|
|
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).
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## Single‑file
|
|
126
|
+
### Config Reference
|
|
133
127
|
|
|
134
|
-
|
|
128
|
+
All available options are shown below. In practice, use only the options you need.
|
|
135
129
|
|
|
136
130
|
```ts
|
|
131
|
+
// hono-takibi.config.ts
|
|
137
132
|
import { defineConfig } from 'hono-takibi/config'
|
|
138
133
|
|
|
139
134
|
export default defineConfig({
|
|
140
135
|
input: 'openapi.yaml',
|
|
141
136
|
'zod-openapi': {
|
|
142
137
|
output: './src/index.ts',
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
exportSchemas: true,
|
|
139
|
+
exportSchemasTypes: true,
|
|
140
|
+
exportParameters: true,
|
|
141
|
+
exportParametersTypes: true,
|
|
142
|
+
exportSecuritySchemes: true,
|
|
143
|
+
exportRequestBodies: true,
|
|
144
|
+
exportResponses: true,
|
|
145
|
+
exportHeaders: true,
|
|
146
|
+
exportHeadersTypes: true,
|
|
147
|
+
exportExamples: true,
|
|
148
|
+
exportLinks: true,
|
|
149
|
+
exportCallbacks: true,
|
|
150
|
+
routes: {
|
|
151
|
+
output: './src/routes',
|
|
152
|
+
split: true,
|
|
153
|
+
},
|
|
154
|
+
components: {
|
|
155
|
+
schemas: {
|
|
156
|
+
output: './src/schemas',
|
|
157
|
+
exportTypes: true,
|
|
158
|
+
split: true,
|
|
159
|
+
import: '../schemas',
|
|
160
|
+
},
|
|
161
|
+
parameters: {
|
|
162
|
+
output: './src/parameters',
|
|
163
|
+
exportTypes: true,
|
|
164
|
+
split: true,
|
|
165
|
+
import: '../parameters',
|
|
166
|
+
},
|
|
167
|
+
securitySchemes: {
|
|
168
|
+
output: './src/securitySchemes',
|
|
169
|
+
split: true,
|
|
170
|
+
import: '../securitySchemes',
|
|
171
|
+
},
|
|
172
|
+
requestBodies: {
|
|
173
|
+
output: './src/requestBodies',
|
|
174
|
+
split: true,
|
|
175
|
+
import: '../requestBodies',
|
|
176
|
+
},
|
|
177
|
+
responses: {
|
|
178
|
+
output: './src/responses',
|
|
179
|
+
split: true,
|
|
180
|
+
import: '../responses',
|
|
181
|
+
},
|
|
182
|
+
headers: {
|
|
183
|
+
output: './src/headers',
|
|
184
|
+
exportTypes: true,
|
|
185
|
+
split: true,
|
|
186
|
+
import: '../headers',
|
|
187
|
+
},
|
|
188
|
+
examples: {
|
|
189
|
+
output: './src/examples',
|
|
190
|
+
split: true,
|
|
191
|
+
import: '../examples',
|
|
192
|
+
},
|
|
193
|
+
links: {
|
|
194
|
+
output: './src/links',
|
|
195
|
+
split: true,
|
|
196
|
+
import: '../links',
|
|
197
|
+
},
|
|
198
|
+
callbacks: {
|
|
199
|
+
output: './src/callbacks',
|
|
200
|
+
split: true,
|
|
201
|
+
import: '../callbacks',
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
type: {
|
|
206
|
+
output: './src/types.ts',
|
|
207
|
+
},
|
|
208
|
+
rpc: {
|
|
209
|
+
output: './src/rpc',
|
|
210
|
+
import: '../client',
|
|
211
|
+
split: true,
|
|
145
212
|
},
|
|
146
213
|
})
|
|
147
214
|
```
|
|
148
215
|
|
|
216
|
+
## Essentials
|
|
217
|
+
|
|
218
|
+
* Put **`hono-takibi.config.ts`** at repo root.
|
|
219
|
+
* Default‑export with `defineConfig(...)`.
|
|
220
|
+
* `input`: **`openapi.yaml`** (recommended), or `*.json` / `*.tsp`.
|
|
221
|
+
|
|
222
|
+
> **About `split`**
|
|
223
|
+
>
|
|
224
|
+
> * `split: true` → `output` is a **directory**; many files + `index.ts`.
|
|
225
|
+
> * `split` **omitted** or `false` → `output` is a **single `*.ts` file** (one file only).
|
|
226
|
+
|
|
149
227
|
---
|
|
150
228
|
|
|
151
|
-
##
|
|
229
|
+
## Single‑file
|
|
152
230
|
|
|
153
|
-
|
|
231
|
+
One file. Set top‑level `output` (don't define `components`/`routes`).
|
|
154
232
|
|
|
155
233
|
```ts
|
|
156
234
|
import { defineConfig } from 'hono-takibi/config'
|
|
@@ -158,13 +236,9 @@ import { defineConfig } from 'hono-takibi/config'
|
|
|
158
236
|
export default defineConfig({
|
|
159
237
|
input: 'openapi.yaml',
|
|
160
238
|
'zod-openapi': {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// split OFF example (one file each):
|
|
166
|
-
// schema: { output: './src/schemas/index.ts' },
|
|
167
|
-
// route: { output: './src/routes/index.ts', import: '../schemas' },
|
|
239
|
+
output: './src/index.ts',
|
|
240
|
+
exportSchemas: true,
|
|
241
|
+
exportSchemasTypes: true,
|
|
168
242
|
},
|
|
169
243
|
})
|
|
170
244
|
```
|
|
@@ -178,30 +252,16 @@ Works with either pattern.
|
|
|
178
252
|
* `split: true` → `output` is a **directory**; many files + `index.ts`.
|
|
179
253
|
* `split` **omitted** or `false` → `output` is **one `*.ts` file**.
|
|
180
254
|
|
|
181
|
-
**Example (split: true)**
|
|
182
|
-
|
|
183
255
|
```ts
|
|
184
256
|
import { defineConfig } from 'hono-takibi/config'
|
|
185
257
|
|
|
186
258
|
export default defineConfig({
|
|
187
259
|
input: 'openapi.yaml',
|
|
188
|
-
'zod-openapi': { output: './src/index.ts',
|
|
260
|
+
'zod-openapi': { output: './src/index.ts', exportSchemas: true, exportSchemasTypes: true },
|
|
189
261
|
rpc: { output: './src/rpc', import: '../client', split: true },
|
|
190
262
|
})
|
|
191
263
|
```
|
|
192
264
|
|
|
193
|
-
**Example (single file; split omitted/false)**
|
|
194
|
-
|
|
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
265
|
---
|
|
206
266
|
|
|
207
267
|
## Vite Plugin (`honoTakibiVite`)
|
|
@@ -230,30 +290,6 @@ That’s it — set `input`, choose one of the two patterns, and (optionally) ad
|
|
|
230
290
|
|
|
231
291
|

|
|
232
292
|
|
|
233
|
-
|
|
234
|
-
## AI Prompt Example
|
|
235
|
-
|
|
236
|
-
```sh
|
|
237
|
-
Generate one **OpenAPI 3.x+** YAML (prefer **3.1.0**).
|
|
238
|
-
|
|
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`.
|
|
246
|
-
|
|
247
|
-
Fill, then generate:
|
|
248
|
-
- title / version / tags
|
|
249
|
-
- resources & fields
|
|
250
|
-
- ops per resource: create / get / search / update / delete
|
|
251
|
-
|
|
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.
|
|
255
|
-
```
|
|
256
|
-
|
|
257
293
|
### ⚠️ WARNING: Potential Breaking Changes Without Notice
|
|
258
294
|
|
|
259
295
|
**This package is in active development and may introduce breaking changes without prior notice.**
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CLI entry point for
|
|
2
|
+
* Main CLI entry point for hono-takibi.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Processes command-line arguments or config file to generate TypeScript
|
|
5
|
+
* code from OpenAPI specifications. Supports both CLI mode and config file mode.
|
|
5
6
|
*
|
|
6
7
|
* ```mermaid
|
|
7
8
|
* flowchart TD
|
|
8
|
-
* A["Start
|
|
9
|
-
* B
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* H --> I
|
|
16
|
-
*
|
|
17
|
-
*
|
|
9
|
+
* A["Start"] --> B{"Args: --help/-h?"}
|
|
10
|
+
* B -->|Yes| C["Return help text"]
|
|
11
|
+
* B -->|No| D{"Config file exists?"}
|
|
12
|
+
* D -->|No| E["CLI Mode"]
|
|
13
|
+
* D -->|Yes| F["Config Mode"]
|
|
14
|
+
* E --> G["parseCli(args)"]
|
|
15
|
+
* G --> H["parseOpenAPI(input)"]
|
|
16
|
+
* H --> I["takibi(openAPI, ...)"]
|
|
17
|
+
* F --> J["config()"]
|
|
18
|
+
* J --> K["parseOpenAPI(config.input)"]
|
|
19
|
+
* K --> L["Generate all components"]
|
|
20
|
+
* L --> M["Return results"]
|
|
21
|
+
* I --> M
|
|
18
22
|
* ```
|
|
19
23
|
*
|
|
20
|
-
*
|
|
21
|
-
* - `--export-type` Export TypeScript type aliases
|
|
22
|
-
* - `--export-schema` Export Zod schema objects
|
|
23
|
-
* - `--template` Generate app file and handler stubs
|
|
24
|
-
* - `--test` Generate empty `*.test.ts` files
|
|
25
|
-
* - `--base-path <path>` API prefix (default: `/`)
|
|
26
|
-
* - `-h, --help` Show help and exit
|
|
24
|
+
* @returns Promise resolving to success with output message or error
|
|
27
25
|
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // CLI usage
|
|
29
|
+
* const result = await honoTakibi()
|
|
30
|
+
* if (result.ok) {
|
|
31
|
+
* console.log(result.value) // "Generated code written to routes.ts"
|
|
32
|
+
* } else {
|
|
33
|
+
* console.error(result.error)
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
31
36
|
*/
|
|
32
37
|
export declare function honoTakibi(): Promise<{
|
|
33
38
|
readonly ok: true;
|
package/dist/cli/index.js
CHANGED
|
@@ -1,123 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI module for hono-takibi.
|
|
3
|
+
*
|
|
4
|
+
* Provides the main entry point for the CLI tool that converts OpenAPI
|
|
5
|
+
* specifications to Hono routes with Zod validation.
|
|
6
|
+
*
|
|
7
|
+
* ```mermaid
|
|
8
|
+
* flowchart TD
|
|
9
|
+
* A["honoTakibi()"] --> B{"--help or -h?"}
|
|
10
|
+
* B -->|Yes| C["Return HELP_TEXT"]
|
|
11
|
+
* B -->|No| D{"hono-takibi.config.ts exists?"}
|
|
12
|
+
* D -->|No| E["Parse CLI args"]
|
|
13
|
+
* D -->|Yes| F["Load config file"]
|
|
14
|
+
* E --> G["parseOpenAPI(input)"]
|
|
15
|
+
* F --> G
|
|
16
|
+
* G --> H["takibi() + components"]
|
|
17
|
+
* H --> I["Return success/error"]
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @module cli
|
|
21
|
+
*/
|
|
1
22
|
import { existsSync } from 'node:fs';
|
|
2
23
|
import { resolve } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import { route } from '../core/
|
|
5
|
-
import {
|
|
6
|
-
import { schema } from '../core/schema.js';
|
|
7
|
-
import { takibi } from '../core/takibi.js';
|
|
8
|
-
import { type } from '../core/type.js';
|
|
9
|
-
// import { honoRpcWithSWR } from '../generator/swr/index.js'
|
|
24
|
+
import { loadConfig } from '../config/index.js';
|
|
25
|
+
import { callbacks, examples, headers, links, parameters, requestBodies, responses, route, rpc, schemas, securitySchemes, takibi, type, } from '../core/index.js';
|
|
26
|
+
import { parseOpenAPI } from '../openapi/index.js';
|
|
10
27
|
import { parseCli } from '../utils/index.js';
|
|
11
|
-
/**
|
|
12
|
-
* CLI usage help text shown when `-h`/`--help` is provided.
|
|
13
|
-
* Kept as a single template for easy updates and snapshot stability.
|
|
14
|
-
*/
|
|
15
28
|
const HELP_TEXT = `Usage: hono-takibi <input.{yaml,json,tsp}> -o <routes.ts> [options]
|
|
16
29
|
|
|
17
30
|
Options:
|
|
18
|
-
--export-
|
|
19
|
-
--export-
|
|
20
|
-
--
|
|
21
|
-
--
|
|
22
|
-
--
|
|
23
|
-
-
|
|
31
|
+
--export-schemas-types export schemas types
|
|
32
|
+
--export-schemas export schemas
|
|
33
|
+
--export-parameters-types export parameters types
|
|
34
|
+
--export-parameters export parameters
|
|
35
|
+
--export-security-schemes export securitySchemes
|
|
36
|
+
--export-request-bodies export requestBodies
|
|
37
|
+
--export-responses export responses
|
|
38
|
+
--export-headers-types export headers types
|
|
39
|
+
--export-headers export headers
|
|
40
|
+
--export-examples export examples
|
|
41
|
+
--export-links export links
|
|
42
|
+
--export-callbacks export callbacks
|
|
43
|
+
--template generate app file and handler stubs
|
|
44
|
+
--test generate empty *.test.ts files
|
|
45
|
+
--base-path <path> api prefix (default: /)
|
|
46
|
+
-h, --help display help for command`;
|
|
24
47
|
/**
|
|
25
|
-
* CLI entry point for
|
|
48
|
+
* Main CLI entry point for hono-takibi.
|
|
26
49
|
*
|
|
27
|
-
*
|
|
50
|
+
* Processes command-line arguments or config file to generate TypeScript
|
|
51
|
+
* code from OpenAPI specifications. Supports both CLI mode and config file mode.
|
|
28
52
|
*
|
|
29
53
|
* ```mermaid
|
|
30
54
|
* flowchart TD
|
|
31
|
-
* A["Start
|
|
32
|
-
* B
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* H --> I
|
|
39
|
-
*
|
|
40
|
-
*
|
|
55
|
+
* A["Start"] --> B{"Args: --help/-h?"}
|
|
56
|
+
* B -->|Yes| C["Return help text"]
|
|
57
|
+
* B -->|No| D{"Config file exists?"}
|
|
58
|
+
* D -->|No| E["CLI Mode"]
|
|
59
|
+
* D -->|Yes| F["Config Mode"]
|
|
60
|
+
* E --> G["parseCli(args)"]
|
|
61
|
+
* G --> H["parseOpenAPI(input)"]
|
|
62
|
+
* H --> I["takibi(openAPI, ...)"]
|
|
63
|
+
* F --> J["config()"]
|
|
64
|
+
* J --> K["parseOpenAPI(config.input)"]
|
|
65
|
+
* K --> L["Generate all components"]
|
|
66
|
+
* L --> M["Return results"]
|
|
67
|
+
* I --> M
|
|
41
68
|
* ```
|
|
42
69
|
*
|
|
43
|
-
*
|
|
44
|
-
* - `--export-type` Export TypeScript type aliases
|
|
45
|
-
* - `--export-schema` Export Zod schema objects
|
|
46
|
-
* - `--template` Generate app file and handler stubs
|
|
47
|
-
* - `--test` Generate empty `*.test.ts` files
|
|
48
|
-
* - `--base-path <path>` API prefix (default: `/`)
|
|
49
|
-
* - `-h, --help` Show help and exit
|
|
70
|
+
* @returns Promise resolving to success with output message or error
|
|
50
71
|
*
|
|
51
|
-
* @
|
|
52
|
-
*
|
|
53
|
-
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // CLI usage
|
|
75
|
+
* const result = await honoTakibi()
|
|
76
|
+
* if (result.ok) {
|
|
77
|
+
* console.log(result.value) // "Generated code written to routes.ts"
|
|
78
|
+
* } else {
|
|
79
|
+
* console.error(result.error)
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
54
82
|
*/
|
|
55
83
|
export async function honoTakibi() {
|
|
56
|
-
/** Slice the arguments to remove the first two (node and script path) */
|
|
57
84
|
const args = process.argv.slice(2);
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
};
|
|
61
|
-
/** help */
|
|
62
|
-
if (isHelpRequested(args)) {
|
|
63
|
-
return {
|
|
64
|
-
ok: true,
|
|
65
|
-
value: HELP_TEXT,
|
|
66
|
-
};
|
|
85
|
+
if (args.length === 1 && (args[0] === '--help' || args[0] === '-h')) {
|
|
86
|
+
return { ok: true, value: HELP_TEXT };
|
|
67
87
|
}
|
|
68
88
|
const abs = resolve(process.cwd(), 'hono-takibi.config.ts');
|
|
69
|
-
/** If config file does not exist, parse CLI arguments */
|
|
70
89
|
if (!existsSync(abs)) {
|
|
71
90
|
const cliResult = parseCli(args);
|
|
72
91
|
if (!cliResult.ok)
|
|
73
92
|
return { ok: false, error: cliResult.error };
|
|
74
93
|
const cli = cliResult.value;
|
|
75
|
-
const
|
|
94
|
+
const { input, output, template, test, basePath, componentsOptions } = cli;
|
|
95
|
+
const openAPIResult = await parseOpenAPI(input);
|
|
96
|
+
if (!openAPIResult.ok)
|
|
97
|
+
return { ok: false, error: openAPIResult.error };
|
|
98
|
+
const openAPI = openAPIResult.value;
|
|
99
|
+
const takibiResult = await takibi(openAPI, output, template, test, basePath, componentsOptions);
|
|
76
100
|
if (!takibiResult.ok)
|
|
77
101
|
return { ok: false, error: takibiResult.error };
|
|
78
|
-
return {
|
|
79
|
-
ok: true,
|
|
80
|
-
value: takibiResult.value,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/** If config file exists, parse config file */
|
|
84
|
-
const configResult = await config();
|
|
85
|
-
if (!configResult.ok) {
|
|
86
|
-
return { ok: false, error: configResult.error };
|
|
102
|
+
return { ok: true, value: takibiResult.value };
|
|
87
103
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
const loadConfigResult = await loadConfig();
|
|
105
|
+
if (!loadConfigResult.ok)
|
|
106
|
+
return { ok: false, error: loadConfigResult.error };
|
|
107
|
+
const config = loadConfigResult.value;
|
|
108
|
+
const openAPIResult = await parseOpenAPI(config.input);
|
|
109
|
+
if (!openAPIResult.ok)
|
|
110
|
+
return { ok: false, error: openAPIResult.error };
|
|
111
|
+
const openAPI = openAPIResult.value;
|
|
112
|
+
const [takibiResult, schemaResult, parameterResult, headersResult, examplesResult, linksResult, callbacksResult, securitySchemesResult, requestBodiesResult, responsesResult, routeResult, typeResult, rpcResult,] = await Promise.all([
|
|
113
|
+
config['zod-openapi']?.output
|
|
114
|
+
? takibi(openAPI, config['zod-openapi'].output, false, false, '/', {
|
|
115
|
+
exportSchemasTypes: config['zod-openapi'].exportSchemasTypes ?? false,
|
|
116
|
+
exportSchemas: config['zod-openapi'].exportSchemas ?? false,
|
|
117
|
+
exportParametersTypes: config['zod-openapi'].exportParametersTypes ?? false,
|
|
118
|
+
exportParameters: config['zod-openapi'].exportParameters ?? false,
|
|
119
|
+
exportSecuritySchemes: config['zod-openapi'].exportSecuritySchemes ?? false,
|
|
120
|
+
exportRequestBodies: config['zod-openapi'].exportRequestBodies ?? false,
|
|
121
|
+
exportResponses: config['zod-openapi'].exportResponses ?? false,
|
|
122
|
+
exportHeadersTypes: config['zod-openapi'].exportHeadersTypes ?? false,
|
|
123
|
+
exportHeaders: config['zod-openapi'].exportHeaders ?? false,
|
|
124
|
+
exportExamples: config['zod-openapi'].exportExamples ?? false,
|
|
125
|
+
exportLinks: config['zod-openapi'].exportLinks ?? false,
|
|
126
|
+
exportCallbacks: config['zod-openapi'].exportCallbacks ?? false,
|
|
127
|
+
})
|
|
128
|
+
: Promise.resolve(undefined),
|
|
129
|
+
config['zod-openapi']?.components?.schemas
|
|
130
|
+
? schemas(openAPI.components?.schemas, config['zod-openapi']?.components?.schemas?.output, config['zod-openapi']?.components?.schemas?.split ?? false, config['zod-openapi']?.components?.schemas?.exportTypes ?? false)
|
|
131
|
+
: Promise.resolve(undefined),
|
|
132
|
+
config['zod-openapi']?.components?.parameters
|
|
133
|
+
? parameters(openAPI.components?.parameters, config['zod-openapi']?.components?.parameters?.output, config['zod-openapi']?.components?.parameters?.split ?? false, config['zod-openapi']?.components?.parameters?.exportTypes ?? false, config['zod-openapi']?.components)
|
|
134
|
+
: Promise.resolve(undefined),
|
|
135
|
+
config['zod-openapi']?.components?.headers
|
|
136
|
+
? headers(openAPI.components?.headers, config['zod-openapi']?.components?.headers?.output, config['zod-openapi']?.components?.headers?.split ?? false, config['zod-openapi']?.components?.headers?.exportTypes ?? false, config['zod-openapi']?.components)
|
|
137
|
+
: Promise.resolve(undefined),
|
|
138
|
+
config['zod-openapi']?.components?.examples
|
|
139
|
+
? examples(openAPI.components?.examples, config['zod-openapi']?.components?.examples?.output, config['zod-openapi']?.components?.examples?.split ?? false)
|
|
140
|
+
: Promise.resolve(undefined),
|
|
141
|
+
config['zod-openapi']?.components?.links
|
|
142
|
+
? links(openAPI.components?.links, config['zod-openapi']?.components?.links?.output, config['zod-openapi']?.components?.links?.split ?? false)
|
|
143
|
+
: Promise.resolve(undefined),
|
|
144
|
+
config['zod-openapi']?.components?.callbacks
|
|
145
|
+
? callbacks(openAPI.components?.callbacks, config['zod-openapi']?.components?.callbacks?.output, config['zod-openapi']?.components?.callbacks?.split ?? false)
|
|
146
|
+
: Promise.resolve(undefined),
|
|
147
|
+
config['zod-openapi']?.components?.securitySchemes
|
|
148
|
+
? securitySchemes(openAPI.components?.securitySchemes, config['zod-openapi']?.components?.securitySchemes?.output, config['zod-openapi']?.components?.securitySchemes?.split ?? false)
|
|
149
|
+
: Promise.resolve(undefined),
|
|
150
|
+
config['zod-openapi']?.components?.requestBodies
|
|
151
|
+
? requestBodies(openAPI.components?.requestBodies, config['zod-openapi']?.components?.requestBodies?.output, config['zod-openapi']?.components?.requestBodies?.split ?? false, config['zod-openapi']?.components)
|
|
152
|
+
: Promise.resolve(undefined),
|
|
153
|
+
config['zod-openapi']?.components?.responses
|
|
154
|
+
? responses(openAPI.components?.responses, config['zod-openapi']?.components?.responses?.output, config['zod-openapi']?.components?.responses?.split ?? false, config['zod-openapi']?.components)
|
|
155
|
+
: Promise.resolve(undefined),
|
|
156
|
+
config['zod-openapi']?.routes
|
|
157
|
+
? route(openAPI, config['zod-openapi'].routes, config['zod-openapi'].components)
|
|
158
|
+
: Promise.resolve(undefined),
|
|
159
|
+
config.type ? type(openAPI, config.type.output) : Promise.resolve(undefined),
|
|
160
|
+
config.rpc
|
|
161
|
+
? rpc(openAPI, config.rpc.output, config.rpc.import, config.rpc.split ?? false)
|
|
162
|
+
: Promise.resolve(undefined),
|
|
163
|
+
]);
|
|
94
164
|
if (takibiResult && !takibiResult.ok)
|
|
95
165
|
return { ok: false, error: takibiResult.error };
|
|
96
|
-
/** schema */
|
|
97
|
-
const schemaResult = c['zod-openapi']?.schema
|
|
98
|
-
? await schema(c.input, c['zod-openapi'].schema.output, c['zod-openapi'].schema.exportType ?? false, c['zod-openapi']?.schema.split ?? false)
|
|
99
|
-
: undefined;
|
|
100
166
|
if (schemaResult && !schemaResult.ok)
|
|
101
167
|
return { ok: false, error: schemaResult.error };
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
:
|
|
168
|
+
if (parameterResult && !parameterResult.ok)
|
|
169
|
+
return { ok: false, error: parameterResult.error };
|
|
170
|
+
if (headersResult && !headersResult.ok)
|
|
171
|
+
return { ok: false, error: headersResult.error };
|
|
172
|
+
if (examplesResult && !examplesResult.ok)
|
|
173
|
+
return { ok: false, error: examplesResult.error };
|
|
174
|
+
if (linksResult && !linksResult.ok)
|
|
175
|
+
return { ok: false, error: linksResult.error };
|
|
176
|
+
if (callbacksResult && !callbacksResult.ok)
|
|
177
|
+
return { ok: false, error: callbacksResult.error };
|
|
178
|
+
if (securitySchemesResult && !securitySchemesResult.ok)
|
|
179
|
+
return { ok: false, error: securitySchemesResult.error };
|
|
180
|
+
if (requestBodiesResult && !requestBodiesResult.ok)
|
|
181
|
+
return { ok: false, error: requestBodiesResult.error };
|
|
182
|
+
if (responsesResult && !responsesResult.ok)
|
|
183
|
+
return { ok: false, error: responsesResult.error };
|
|
106
184
|
if (routeResult && !routeResult.ok)
|
|
107
185
|
return { ok: false, error: routeResult.error };
|
|
108
|
-
/** type */
|
|
109
|
-
const typeResult = c.type ? await type(c.input, c.type.output) : undefined;
|
|
110
186
|
if (typeResult && !typeResult.ok)
|
|
111
187
|
return { ok: false, error: typeResult.error };
|
|
112
|
-
/** rpc */
|
|
113
|
-
const rpcResult = c.rpc
|
|
114
|
-
? await rpc(c.input, c.rpc.output, c.rpc.import, c.rpc.split ?? false)
|
|
115
|
-
: undefined;
|
|
116
188
|
if (rpcResult && !rpcResult.ok)
|
|
117
189
|
return { ok: false, error: rpcResult.error };
|
|
118
|
-
const results = [
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
value
|
|
122
|
-
|
|
190
|
+
const results = [
|
|
191
|
+
takibiResult?.value,
|
|
192
|
+
schemaResult?.value,
|
|
193
|
+
parameterResult?.value,
|
|
194
|
+
headersResult?.value,
|
|
195
|
+
examplesResult?.value,
|
|
196
|
+
linksResult?.value,
|
|
197
|
+
callbacksResult?.value,
|
|
198
|
+
securitySchemesResult?.value,
|
|
199
|
+
requestBodiesResult?.value,
|
|
200
|
+
responsesResult?.value,
|
|
201
|
+
routeResult?.value,
|
|
202
|
+
typeResult?.value,
|
|
203
|
+
rpcResult?.value,
|
|
204
|
+
].filter((v) => v !== undefined);
|
|
205
|
+
return { ok: true, value: results.join('\n') };
|
|
123
206
|
}
|