hono-takibi 0.9.70 → 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 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-type export TypeScript type aliases
99
- --export-schema export Zod schema objects
100
- --template generate app file and handler stubs
101
- --test generate empty *.test.ts files
102
- --base-path <path> api prefix (default: /)
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-type --export-schema --template --base-path '/api/v1'
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
- ## Essentials
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).
126
+ ### Config Reference
129
127
 
130
- ---
131
-
132
- ## Single‑file
133
-
134
- One file. Set top‑level `output` (don’t define `schema`/`route`).
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
- exportSchema: true,
144
- exportType: true,
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
- ## Schemas & Routes
229
+ ## Single‑file
152
230
 
153
- Define **both** `schema` and `route` (dont set top‑level `output`).
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
- // 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' },
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', exportSchema: true, exportType: true },
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`)
@@ -40,9 +40,9 @@ const isValidIdent = (s) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s);
40
40
  *
41
41
  * Rules:
42
42
  * - '/' -> '.index'
43
- * - Single segment with valid identifier -> dot notation: '/pet' -> '.pet'
44
- * - All other cases -> each segment becomes bracket access: '/files/upload' -> "['files']['upload']"
45
- * - Path params converted: '/files/{fileId}' -> "['files'][':fileId']"
43
+ * - Valid identifiers use dot notation: '/users' -> '.users'
44
+ * - Invalid identifiers use bracket notation: '/:id' -> "[':id']"
45
+ * - Path params converted: '/files/{fileId}' -> ".files[':fileId']"
46
46
  */
47
47
  const formatPath = (p) => {
48
48
  if (p === '/')
@@ -50,12 +50,8 @@ const formatPath = (p) => {
50
50
  const segs = p.replace(/^\/+/, '').split('/').filter(Boolean);
51
51
  // Convert {param} to :param
52
52
  const honoSegs = segs.map((seg) => seg.startsWith('{') && seg.endsWith('}') ? `:${seg.slice(1, -1)}` : seg);
53
- // Single segment with valid identifier: use dot notation
54
- if (honoSegs.length === 1 && isValidIdent(honoSegs[0])) {
55
- return `.${honoSegs[0]}`;
56
- }
57
- // All other cases: each segment becomes separate bracket access
58
- return honoSegs.map((seg) => `['${esc(seg)}']`).join('');
53
+ // Use dot notation for valid identifiers, bracket for others
54
+ return honoSegs.map((seg) => (isValidIdent(seg) ? `.${seg}` : `['${esc(seg)}']`)).join('');
59
55
  };
60
56
  const isRefObject = (v) => isRecord(v) && typeof v.$ref === 'string';
61
57
  const isParameterObject = (v) => {
@@ -354,18 +350,19 @@ const generateOperationCode = (pathStr, method, item, deps) => {
354
350
  headerParams.length > 0 ||
355
351
  cookieParams.length > 0 ||
356
352
  hasBody;
357
- // Use unified path format for both type and runtime
358
- const hasBracket = pathAccess.includes('[');
359
- const methodAccess = hasBracket ? `['$${method}']` : `.$${method}`;
353
+ // Always use dot notation for method access
354
+ const methodAccess = `.$${method}`;
360
355
  // Generate argument type directly from OpenAPI instead of using InferRequestType
361
356
  const argType = generateArgType(pathParams, queryParams, headerParams, cookieParams, allBodyInfo, deps.componentsSchemas);
362
357
  // options is always a separate parameter
363
358
  // If there are required args (params, query, body, etc.), args is required
364
- // If no args, use args?: {} | undefined
359
+ // If no args, omit args parameter entirely
365
360
  const argSig = hasArgs
366
361
  ? `args: ${argType}, options?: ClientRequestOptions`
367
- : 'args?: {} | undefined, options?: ClientRequestOptions';
368
- const call = `${deps.client}${pathAccess}${methodAccess}(args, options)`;
362
+ : 'options?: ClientRequestOptions';
363
+ const call = hasArgs
364
+ ? `${deps.client}${pathAccess}${methodAccess}(args, options)`
365
+ : `${deps.client}${pathAccess}${methodAccess}(undefined, options)`;
369
366
  const summary = typeof op.summary === 'string' ? op.summary : '';
370
367
  const description = typeof op.description === 'string' ? op.description : '';
371
368
  const docs = [
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.70",
4
+ "version": "0.9.71",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [