hono-takibi 0.9.74 → 0.9.75

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/dist/cli/index.js CHANGED
@@ -128,18 +128,18 @@ function parseCli(args) {
128
128
  test: args.includes('--test'),
129
129
  basePath: getFlagValue(args, '--base-path') ?? '/', // default: /
130
130
  componentsOptions: {
131
- exportSchemas: args.includes('--export-schemas') ?? false,
132
- exportSchemasTypes: args.includes('--export-schemas-types') ?? false,
133
- exportParameters: args.includes('--export-parameters') ?? false,
134
- exportParametersTypes: args.includes('--export-parameters-types') ?? false,
135
- exportSecuritySchemes: args.includes('--export-security-schemes') ?? false,
136
- exportRequestBodies: args.includes('--export-request-bodies') ?? false,
137
- exportResponses: args.includes('--export-responses') ?? false,
138
- exportHeaders: args.includes('--export-headers') ?? false,
139
- exportHeadersTypes: args.includes('--export-headers-types') ?? false,
140
- exportExamples: args.includes('--export-examples') ?? false,
141
- exportLinks: args.includes('--export-links') ?? false,
142
- exportCallbacks: args.includes('--export-callbacks') ?? false,
131
+ exportSchemas: args.includes('--export-schemas'),
132
+ exportSchemasTypes: args.includes('--export-schemas-types'),
133
+ exportParameters: args.includes('--export-parameters'),
134
+ exportParametersTypes: args.includes('--export-parameters-types'),
135
+ exportSecuritySchemes: args.includes('--export-security-schemes'),
136
+ exportRequestBodies: args.includes('--export-request-bodies'),
137
+ exportResponses: args.includes('--export-responses'),
138
+ exportHeaders: args.includes('--export-headers'),
139
+ exportHeadersTypes: args.includes('--export-headers-types'),
140
+ exportExamples: args.includes('--export-examples'),
141
+ exportLinks: args.includes('--export-links'),
142
+ exportCallbacks: args.includes('--export-callbacks'),
143
143
  },
144
144
  },
145
145
  };
@@ -1,10 +1,16 @@
1
1
  import type { OpenAPI } from '../../../openapi/index.js';
2
2
  /**
3
- * Generates a Hono app with OpenAPI and Swagger UI integration.
3
+ * Generates a Hono app with OpenAPI integration.
4
4
  *
5
5
  * @param openapi - The OpenAPI specification.
6
6
  * @param output - The output file name (e.g., 'user.ts').
7
7
  * @param basePath - Optional base path for the app.
8
8
  * @returns The generated application code as a string.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const code = app(openapiSpec, 'routes.ts', '/api')
13
+ * // Returns generated Hono app code with route handlers
14
+ * ```
9
15
  */
10
16
  export declare function app(openapi: OpenAPI, output: `${string}.ts`, basePath: string): string;
@@ -1,11 +1,17 @@
1
- import { isHttpMethod, methodPath, registerComponent } from '../../../utils/index.js';
1
+ import { isHttpMethod, methodPath } from '../../../utils/index.js';
2
2
  /**
3
- * Generates a Hono app with OpenAPI and Swagger UI integration.
3
+ * Generates a Hono app with OpenAPI integration.
4
4
  *
5
5
  * @param openapi - The OpenAPI specification.
6
6
  * @param output - The output file name (e.g., 'user.ts').
7
7
  * @param basePath - Optional base path for the app.
8
8
  * @returns The generated application code as a string.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const code = app(openapiSpec, 'routes.ts', '/api')
13
+ * // Returns generated Hono app code with route handlers
14
+ * ```
9
15
  */
10
16
  export function app(openapi, output, basePath) {
11
17
  const getRouteMaps = (openapi) => {
@@ -24,27 +30,12 @@ export function app(openapi, output, basePath) {
24
30
  return routeMappings;
25
31
  };
26
32
  const routeMappings = getRouteMaps(openapi);
27
- const handlerNames = Array.from(new Set(routeMappings.map((m) => m.handlerName))).sort();
28
- const handlerImport = handlerNames.length > 0 ? `import{${handlerNames.join(',')}}from'./handlers'` : '';
29
- const routeNames = Array.from(new Set(routeMappings.map((m) => m.routeName))).sort();
33
+ const routeNames = [...new Set(routeMappings.map((m) => m.routeName))];
30
34
  const routeModule = `./${output.replace(/^.*\//, '').replace(/\.ts$/, '')}`;
31
35
  const routesImport = routeNames.length > 0 ? `import{${routeNames.join(',')}}from'${routeModule}'` : '';
32
- const path = basePath === '/' ? '/doc' : `${basePath}/doc`;
33
- const registerComponentCode = openapi.components?.securitySchemes
34
- ? registerComponent(openapi.components.securitySchemes)
35
- : '';
36
- const versionStr = String(openapi.openapi ?? '').trim();
37
- const [majStr, minStr] = versionStr.split('.', 3);
38
- const major = Number.isFinite(Number(majStr)) ? Number(majStr) : 0;
39
- const minor = Number.isFinite(Number(minStr)) ? Number(minStr) : 0;
40
- const is31Plus = major > 3 || (major === 3 && minor >= 1);
41
- const doc = is31Plus ? 'doc31' : 'doc';
42
- const importSection = [
43
- `import{swaggerUI}from'@hono/swagger-ui'`,
44
- `import{OpenAPIHono}from'@hono/zod-openapi'`,
45
- handlerImport,
46
- routesImport,
47
- ]
36
+ const handlerNames = [...new Set(routeMappings.map((m) => m.handlerName))];
37
+ const handlerImport = handlerNames.length > 0 ? `import{${handlerNames.join(',')}}from'./handlers'` : '';
38
+ const importSection = [`import{OpenAPIHono}from'@hono/zod-openapi'`, routesImport, handlerImport]
48
39
  .filter(Boolean)
49
40
  .join('\n');
50
41
  const appInit = basePath !== '/'
@@ -54,23 +45,10 @@ export function app(openapi, output, basePath) {
54
45
  routeMappings
55
46
  .map(({ routeName, handlerName }) => `.openapi(${routeName},${handlerName})`)
56
47
  .join('\n');
57
- const docs = Object.fromEntries(Object.entries({
58
- openapi: openapi.openapi,
59
- info: openapi.info,
60
- servers: openapi.servers,
61
- tags: openapi.tags,
62
- externalDocs: openapi.externalDocs,
63
- }).filter(([, v]) => v !== undefined));
64
- const swagger = `if(process.env.NODE_ENV === 'development'){` +
65
- `${registerComponentCode}\n` +
66
- `app.${doc}('/doc',${JSON.stringify(docs)})` +
67
- `.get('/ui',swaggerUI({url:'${path}'}))` +
68
- '}';
69
48
  return [
70
49
  importSection,
71
50
  appInit,
72
51
  apiInit,
73
- swagger,
74
52
  'export type AddType=typeof api',
75
53
  'export default app',
76
54
  ].join('\n\n');
@@ -1,9 +1,25 @@
1
1
  import type { Schema } from '../../../openapi/index.js';
2
2
  /**
3
3
  * Generates a Zod schema for integer types based on OpenAPI schema.
4
- * Supports int32, int64, and bigint formats.
4
+ *
5
+ * Supports int32, int64, and bigint formats with min/max constraints.
5
6
  *
6
7
  * @param schema - The OpenAPI schema object
7
8
  * @returns The Zod schema string
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Basic integer
13
+ * integer({ type: 'integer' })
14
+ * // → 'z.int()'
15
+ *
16
+ * // int64 with constraints
17
+ * integer({ type: 'integer', format: 'int64', minimum: 0, maximum: 100 })
18
+ * // → 'z.int64().min(0n).max(100n)'
19
+ *
20
+ * // Exclusive minimum (greater than)
21
+ * integer({ type: 'integer', exclusiveMinimum: 0 })
22
+ * // → 'z.int().positive()'
23
+ * ```
8
24
  */
9
25
  export declare function integer(schema: Schema): string;
@@ -1,9 +1,25 @@
1
1
  /**
2
2
  * Generates a Zod schema for integer types based on OpenAPI schema.
3
- * Supports int32, int64, and bigint formats.
3
+ *
4
+ * Supports int32, int64, and bigint formats with min/max constraints.
4
5
  *
5
6
  * @param schema - The OpenAPI schema object
6
7
  * @returns The Zod schema string
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Basic integer
12
+ * integer({ type: 'integer' })
13
+ * // → 'z.int()'
14
+ *
15
+ * // int64 with constraints
16
+ * integer({ type: 'integer', format: 'int64', minimum: 0, maximum: 100 })
17
+ * // → 'z.int64().min(0n).max(100n)'
18
+ *
19
+ * // Exclusive minimum (greater than)
20
+ * integer({ type: 'integer', exclusiveMinimum: 0 })
21
+ * // → 'z.int().positive()'
22
+ * ```
7
23
  */
8
24
  export function integer(schema) {
9
25
  const base = schema.format === 'int32'
@@ -31,12 +47,10 @@ export function integer(schema) {
31
47
  if (value === 0 && schema.exclusiveMinimum === false) {
32
48
  return '.nonnegative()';
33
49
  }
34
- // > value → .gt(...)
35
50
  if ((schema.exclusiveMinimum === true || schema.minimum === undefined) &&
36
51
  typeof value === 'number') {
37
52
  return `.gt(${lit(value)})`;
38
53
  }
39
- // >= value → .min(...)
40
54
  if (typeof schema.minimum === 'number') {
41
55
  return `.min(${lit(schema.minimum)})`;
42
56
  }
@@ -1,9 +1,25 @@
1
1
  import type { Schema } from '../../../openapi/index.js';
2
2
  /**
3
3
  * Generates a Zod schema for number types based on OpenAPI schema.
4
- * Supports float, float32, float64, and number formats.
4
+ *
5
+ * Supports float, float32, float64, and number formats with constraints.
5
6
  *
6
7
  * @param schema - The OpenAPI schema object
7
8
  * @returns The Zod schema string
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Basic number
13
+ * number({ type: 'number' })
14
+ * // → 'z.number()'
15
+ *
16
+ * // Float with constraints
17
+ * number({ type: 'number', format: 'float', minimum: 0, maximum: 1.0 })
18
+ * // → 'z.float32().min(0).max(1)'
19
+ *
20
+ * // Positive number (exclusive minimum = 0)
21
+ * number({ type: 'number', minimum: 0, exclusiveMinimum: true })
22
+ * // → 'z.number().positive()'
23
+ * ```
8
24
  */
9
25
  export declare function number(schema: Schema): string;
@@ -1,9 +1,25 @@
1
1
  /**
2
2
  * Generates a Zod schema for number types based on OpenAPI schema.
3
- * Supports float, float32, float64, and number formats.
3
+ *
4
+ * Supports float, float32, float64, and number formats with constraints.
4
5
  *
5
6
  * @param schema - The OpenAPI schema object
6
7
  * @returns The Zod schema string
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Basic number
12
+ * number({ type: 'number' })
13
+ * // → 'z.number()'
14
+ *
15
+ * // Float with constraints
16
+ * number({ type: 'number', format: 'float', minimum: 0, maximum: 1.0 })
17
+ * // → 'z.float32().min(0).max(1)'
18
+ *
19
+ * // Positive number (exclusive minimum = 0)
20
+ * number({ type: 'number', minimum: 0, exclusiveMinimum: true })
21
+ * // → 'z.number().positive()'
22
+ * ```
7
23
  */
8
24
  export function number(schema) {
9
25
  const base = schema.format === 'float' || schema.format === 'float32'
@@ -8,7 +8,26 @@ import type { Schema } from '../../../openapi/index.js';
8
8
  * - additionalProperties: false → `z.strictObject({...})`
9
9
  * - additionalProperties: Schema → `z.record(z.string(), ...)`
10
10
  *
11
- * @param schema - Schema definition.
12
- * @returns The Zod object schema string.
11
+ * @param schema - Schema definition
12
+ * @returns The Zod object schema string
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Basic object with properties
17
+ * object({
18
+ * type: 'object',
19
+ * properties: { name: { type: 'string' } },
20
+ * required: ['name']
21
+ * })
22
+ * // → 'z.object({name:z.string()})'
23
+ *
24
+ * // Strict object (no additional properties)
25
+ * object({ type: 'object', additionalProperties: false })
26
+ * // → 'z.strictObject({})'
27
+ *
28
+ * // Record type (dictionary)
29
+ * object({ type: 'object', additionalProperties: { type: 'number' } })
30
+ * // → 'z.record(z.string(),z.number())'
31
+ * ```
13
32
  */
14
33
  export declare function object(schema: Schema): string;
@@ -9,8 +9,27 @@ import { zodToOpenAPI } from '../index.js';
9
9
  * - additionalProperties: false → `z.strictObject({...})`
10
10
  * - additionalProperties: Schema → `z.record(z.string(), ...)`
11
11
  *
12
- * @param schema - Schema definition.
13
- * @returns The Zod object schema string.
12
+ * @param schema - Schema definition
13
+ * @returns The Zod object schema string
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // Basic object with properties
18
+ * object({
19
+ * type: 'object',
20
+ * properties: { name: { type: 'string' } },
21
+ * required: ['name']
22
+ * })
23
+ * // → 'z.object({name:z.string()})'
24
+ *
25
+ * // Strict object (no additional properties)
26
+ * object({ type: 'object', additionalProperties: false })
27
+ * // → 'z.strictObject({})'
28
+ *
29
+ * // Record type (dictionary)
30
+ * object({ type: 'object', additionalProperties: { type: 'number' } })
31
+ * // → 'z.record(z.string(),z.number())'
32
+ * ```
14
33
  */
15
34
  export function object(schema) {
16
35
  // Delegate combinators to zodToOpenAPI
@@ -5,5 +5,5 @@ export { core } from './core.js';
5
5
  export { makeExports } from './exports.js';
6
6
  export { makeCallbacks, makeContent, makeEncoding, makeExamples, makeHeadersAndReferences, makeLinkOrReference, makeMedia, makeOperationCallbacks, makeOperationResponses, makeParameters, makeRef, makeRequest, makeRequestBody, makeRequestParams, makeResponses, } from './openapi.js';
7
7
  export { findSchemaRefs, makeSchemaCode, makeSchemaInfo, makeSchemaInfos, makeSplitSchemaFile, makeTypeDefinition, makeTypeDefinitions, } from './schema.js';
8
- export { makeRecordTypeString, makeTypeString } from './type.js';
8
+ export { makeTypeString } from './type.js';
9
9
  export { wrap } from './wrap.js';
@@ -5,5 +5,5 @@ export { core } from './core.js';
5
5
  export { makeExports } from './exports.js';
6
6
  export { makeCallbacks, makeContent, makeEncoding, makeExamples, makeHeadersAndReferences, makeLinkOrReference, makeMedia, makeOperationCallbacks, makeOperationResponses, makeParameters, makeRef, makeRequest, makeRequestBody, makeRequestParams, makeResponses, } from './openapi.js';
7
7
  export { findSchemaRefs, makeSchemaCode, makeSchemaInfo, makeSchemaInfos, makeSplitSchemaFile, makeTypeDefinition, makeTypeDefinitions, } from './schema.js';
8
- export { makeRecordTypeString, makeTypeString } from './type.js';
8
+ export { makeTypeString } from './type.js';
9
9
  export { wrap } from './wrap.js';
@@ -81,9 +81,22 @@ export declare function makeExamples(examples: {
81
81
  };
82
82
  }): string;
83
83
  /**
84
- * generates a responses code from the given responses object.
85
- * @param responses
86
- * @returns
84
+ * Generates response code for an operation's responses object.
85
+ *
86
+ * Converts OpenAPI operation responses into a TypeScript object literal string
87
+ * with status codes as keys and response definitions as values.
88
+ *
89
+ * @param responses - The responses object from an OpenAPI operation
90
+ * @returns Object literal string with status code keys and response values
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * makeOperationResponses({
95
+ * '200': { description: 'Success', content: {...} },
96
+ * 'default': { description: 'Error' }
97
+ * })
98
+ * // → '{200:{description:"Success",content:{...}},"default":{description:"Error"}}'
99
+ * ```
87
100
  */
88
101
  export declare function makeOperationResponses(responses: Operation['responses']): string;
89
102
  /**
@@ -96,21 +109,64 @@ export declare function makeHeaderResponses(headers: {
96
109
  readonly [k: string]: Header | Reference;
97
110
  }): string;
98
111
  /**
99
- * generates a response code from the given responses object.
100
- * @param responses
101
- * @returns
112
+ * Generates code for a single response object.
113
+ *
114
+ * Handles both $ref references and inline response definitions,
115
+ * including headers, content, and links.
116
+ *
117
+ * @param responses - OpenAPI response object or reference
118
+ * @returns TypeScript code string for the response
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * // Reference
123
+ * makeResponses({ $ref: '#/components/responses/NotFound' })
124
+ * // → 'NotFoundResponse'
125
+ *
126
+ * // Inline
127
+ * makeResponses({ description: 'Success', content: {...} })
128
+ * // → '{description:"Success",content:{...}}'
129
+ * ```
102
130
  */
103
131
  export declare function makeResponses(responses: Responses): string;
104
132
  /**
105
- * generates a header code from the given headers object.
106
- * @param headers Headers object
107
- * @returns
133
+ * Generates code for a header or header reference.
134
+ *
135
+ * Handles both $ref references and inline header definitions with
136
+ * all OpenAPI header properties (description, required, schema, etc.).
137
+ *
138
+ * @param headers - OpenAPI header object or reference
139
+ * @returns TypeScript code string for the header
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * // Reference
144
+ * makeHeadersAndReferences({ $ref: '#/components/headers/XRequestId' })
145
+ * // → 'XRequestIdHeaderSchema'
146
+ *
147
+ * // Inline
148
+ * makeHeadersAndReferences({ schema: { type: 'string' }, required: true })
149
+ * // → '{required:true,schema:z.string()}'
150
+ * ```
108
151
  */
109
152
  export declare function makeHeadersAndReferences(headers: Header | Reference): string;
110
153
  /**
111
- * generates a link or reference code from the given link or reference object.
112
- * @param linkOrReference
113
- * @returns
154
+ * Generates code for a link or link reference.
155
+ *
156
+ * Handles OpenAPI link objects with operationRef, operationId,
157
+ * parameters, requestBody, and other link properties.
158
+ *
159
+ * @param linkOrReference - OpenAPI link object or reference
160
+ * @returns TypeScript code string for the link
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * makeLinkOrReference({
165
+ * operationId: 'getUser',
166
+ * parameters: { userId: '$response.body#/id' }
167
+ * })
168
+ * // → '{operationId:"getUser",parameters:{"userId":"$response.body#/id"}}'
169
+ * ```
114
170
  */
115
171
  export declare function makeLinkOrReference(linkOrReference: Link | Reference): string;
116
172
  /**
@@ -121,9 +177,25 @@ export declare function makeLinkOrReference(linkOrReference: Link | Reference):
121
177
  */
122
178
  export declare function makeOperationCallbacks(callbacks: Operation['callbacks']): string | undefined;
123
179
  /**
124
- * generates callbacks
125
- * @param callbacks
126
- * @returns
180
+ * Generates code for OpenAPI callbacks object.
181
+ *
182
+ * Converts callbacks with their path items and operations into
183
+ * TypeScript code. Handles $ref references to callback components.
184
+ *
185
+ * @param callbacks - OpenAPI callbacks object with path expressions
186
+ * @returns TypeScript code string for the callbacks
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * makeCallbacks({
191
+ * onPaymentComplete: {
192
+ * '{$request.body#/callbackUrl}': {
193
+ * post: { requestBody: {...}, responses: {...} }
194
+ * }
195
+ * }
196
+ * })
197
+ * // → '"onPaymentComplete":{post:{requestBody:{...},responses:{...}}}'
198
+ * ```
127
199
  */
128
200
  export declare function makeCallbacks(callbacks: Callbacks | {
129
201
  readonly [k: string]: {
@@ -133,29 +205,86 @@ export declare function makeCallbacks(callbacks: Callbacks | {
133
205
  };
134
206
  }): string;
135
207
  /**
136
- * generates content
137
- * @param content
138
- * @returns
208
+ * Generates code for OpenAPI content object.
209
+ *
210
+ * Processes each media type in the content object and generates
211
+ * corresponding TypeScript code. Handles both $ref references
212
+ * and inline media definitions.
213
+ *
214
+ * @param content - OpenAPI content object with media types
215
+ * @returns Array of media type code strings
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * makeContent({
220
+ * 'application/json': { schema: { type: 'object', properties: {...} } }
221
+ * })
222
+ * // → ["'application/json':{schema:z.object({...})}"]
223
+ * ```
139
224
  */
140
225
  export declare function makeContent(content: Content | {
141
226
  readonly [k: string]: Media | Reference;
142
227
  }): string[];
143
228
  /**
144
- * generates a request body code from the given request body object.
145
- * @param body RequestBody object
146
- * @returns
229
+ * Generates code for an OpenAPI request body.
230
+ *
231
+ * Handles both $ref references and inline request body definitions
232
+ * with description, content, and required properties.
233
+ *
234
+ * @param body - OpenAPI request body object or reference
235
+ * @returns TypeScript code string for the request body
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * // Reference
240
+ * makeRequestBody({ $ref: '#/components/requestBodies/CreateUser' })
241
+ * // → 'CreateUserRequestBody'
242
+ *
243
+ * // Inline
244
+ * makeRequestBody({
245
+ * content: { 'application/json': { schema: {...} } },
246
+ * required: true
247
+ * })
248
+ * // → '{content:{"application/json":{schema:...}},required:true}'
249
+ * ```
147
250
  */
148
251
  export declare function makeRequestBody(body: RequestBody | Reference): string;
149
252
  /**
150
- * generates a media code from the given media object.
151
- * @param media Media object
152
- * @returns
253
+ * Generates code for an OpenAPI media object.
254
+ *
255
+ * Converts media type definitions including schema, examples,
256
+ * and encoding into TypeScript code.
257
+ *
258
+ * @param media - OpenAPI media object
259
+ * @returns TypeScript code string for the media
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * makeMedia({
264
+ * schema: { type: 'object', properties: { name: { type: 'string' } } },
265
+ * example: { name: 'John' }
266
+ * })
267
+ * // → '{schema:z.object({name:z.string()}),example:{"name":"John"}}'
268
+ * ```
153
269
  */
154
270
  export declare function makeMedia(media: Media): string;
155
271
  /**
156
- * generates an encoding code from the given encoding object.
157
- * @param encoding
158
- * @returns
272
+ * Generates code for an OpenAPI encoding object.
273
+ *
274
+ * Handles encoding properties for multipart request bodies including
275
+ * contentType, headers, and nested encoding configurations.
276
+ *
277
+ * @param encoding - OpenAPI encoding object
278
+ * @returns TypeScript code string for the encoding
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * makeEncoding({
283
+ * contentType: 'image/png',
284
+ * headers: { 'X-Custom': { schema: { type: 'string' } } }
285
+ * })
286
+ * // → 'contentType:"image/png",headers:{"X-Custom":{schema:z.string()}}'
287
+ * ```
159
288
  */
160
289
  export declare function makeEncoding(encoding: Encoding): string;
161
290
  /**
@@ -174,13 +174,26 @@ export function makeExamples(examples) {
174
174
  return `{${result}}`;
175
175
  }
176
176
  /**
177
- * generates a responses code from the given responses object.
178
- * @param responses
179
- * @returns
177
+ * Generates response code for an operation's responses object.
178
+ *
179
+ * Converts OpenAPI operation responses into a TypeScript object literal string
180
+ * with status codes as keys and response definitions as values.
181
+ *
182
+ * @param responses - The responses object from an OpenAPI operation
183
+ * @returns Object literal string with status code keys and response values
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * makeOperationResponses({
188
+ * '200': { description: 'Success', content: {...} },
189
+ * 'default': { description: 'Error' }
190
+ * })
191
+ * // → '{200:{description:"Success",content:{...}},"default":{description:"Error"}}'
192
+ * ```
180
193
  */
181
194
  export function makeOperationResponses(responses) {
182
195
  const result = Object.entries(responses)
183
- .map(([StatusCode, res]) => `${/^\d+$/.test(StatusCode) ? StatusCode : `'${StatusCode}'`}:${makeResponses(res)}`)
196
+ .map(([statusCode, res]) => `${/^\d+$/.test(statusCode) ? statusCode : `'${statusCode}'`}:${makeResponses(res)}`)
184
197
  // .map(([statusCode, res]) => `${JSON.stringify(statusCode)}:${makeResponses(res)}`)
185
198
  .join(',');
186
199
  return `{${result}}`;
@@ -198,9 +211,24 @@ export function makeHeaderResponses(headers) {
198
211
  return `z.object({${result}})`;
199
212
  }
200
213
  /**
201
- * generates a response code from the given responses object.
202
- * @param responses
203
- * @returns
214
+ * Generates code for a single response object.
215
+ *
216
+ * Handles both $ref references and inline response definitions,
217
+ * including headers, content, and links.
218
+ *
219
+ * @param responses - OpenAPI response object or reference
220
+ * @returns TypeScript code string for the response
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * // Reference
225
+ * makeResponses({ $ref: '#/components/responses/NotFound' })
226
+ * // → 'NotFoundResponse'
227
+ *
228
+ * // Inline
229
+ * makeResponses({ description: 'Success', content: {...} })
230
+ * // → '{description:"Success",content:{...}}'
231
+ * ```
204
232
  */
205
233
  export function makeResponses(responses) {
206
234
  if (responses.$ref) {
@@ -224,9 +252,24 @@ export function makeResponses(responses) {
224
252
  return `{${result}}`;
225
253
  }
226
254
  /**
227
- * generates a header code from the given headers object.
228
- * @param headers Headers object
229
- * @returns
255
+ * Generates code for a header or header reference.
256
+ *
257
+ * Handles both $ref references and inline header definitions with
258
+ * all OpenAPI header properties (description, required, schema, etc.).
259
+ *
260
+ * @param headers - OpenAPI header object or reference
261
+ * @returns TypeScript code string for the header
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * // Reference
266
+ * makeHeadersAndReferences({ $ref: '#/components/headers/XRequestId' })
267
+ * // → 'XRequestIdHeaderSchema'
268
+ *
269
+ * // Inline
270
+ * makeHeadersAndReferences({ schema: { type: 'string' }, required: true })
271
+ * // → '{required:true,schema:z.string()}'
272
+ * ```
230
273
  */
231
274
  export function makeHeadersAndReferences(headers) {
232
275
  if ('$ref' in headers && headers.$ref) {
@@ -260,9 +303,22 @@ export function makeHeadersAndReferences(headers) {
260
303
  return `{${result}}`;
261
304
  }
262
305
  /**
263
- * generates a link or reference code from the given link or reference object.
264
- * @param linkOrReference
265
- * @returns
306
+ * Generates code for a link or link reference.
307
+ *
308
+ * Handles OpenAPI link objects with operationRef, operationId,
309
+ * parameters, requestBody, and other link properties.
310
+ *
311
+ * @param linkOrReference - OpenAPI link object or reference
312
+ * @returns TypeScript code string for the link
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * makeLinkOrReference({
317
+ * operationId: 'getUser',
318
+ * parameters: { userId: '$response.body#/id' }
319
+ * })
320
+ * // → '{operationId:"getUser",parameters:{"userId":"$response.body#/id"}}'
321
+ * ```
266
322
  */
267
323
  export function makeLinkOrReference(linkOrReference) {
268
324
  const result = [
@@ -321,9 +377,25 @@ export function makeOperationCallbacks(callbacks) {
321
377
  return `{${result}}`;
322
378
  }
323
379
  /**
324
- * generates callbacks
325
- * @param callbacks
326
- * @returns
380
+ * Generates code for OpenAPI callbacks object.
381
+ *
382
+ * Converts callbacks with their path items and operations into
383
+ * TypeScript code. Handles $ref references to callback components.
384
+ *
385
+ * @param callbacks - OpenAPI callbacks object with path expressions
386
+ * @returns TypeScript code string for the callbacks
387
+ *
388
+ * @example
389
+ * ```ts
390
+ * makeCallbacks({
391
+ * onPaymentComplete: {
392
+ * '{$request.body#/callbackUrl}': {
393
+ * post: { requestBody: {...}, responses: {...} }
394
+ * }
395
+ * }
396
+ * })
397
+ * // → '"onPaymentComplete":{post:{requestBody:{...},responses:{...}}}'
398
+ * ```
327
399
  */
328
400
  export function makeCallbacks(callbacks) {
329
401
  const isRef = (v) => {
@@ -395,9 +467,22 @@ export function makeCallbacks(callbacks) {
395
467
  .join(',');
396
468
  }
397
469
  /**
398
- * generates content
399
- * @param content
400
- * @returns
470
+ * Generates code for OpenAPI content object.
471
+ *
472
+ * Processes each media type in the content object and generates
473
+ * corresponding TypeScript code. Handles both $ref references
474
+ * and inline media definitions.
475
+ *
476
+ * @param content - OpenAPI content object with media types
477
+ * @returns Array of media type code strings
478
+ *
479
+ * @example
480
+ * ```ts
481
+ * makeContent({
482
+ * 'application/json': { schema: { type: 'object', properties: {...} } }
483
+ * })
484
+ * // → ["'application/json':{schema:z.object({...})}"]
485
+ * ```
401
486
  */
402
487
  export function makeContent(content) {
403
488
  const isMedia = (v) => typeof v === 'object' && v !== null && 'schema' in v;
@@ -417,9 +502,27 @@ export function makeContent(content) {
417
502
  .filter((v) => v !== undefined);
418
503
  }
419
504
  /**
420
- * generates a request body code from the given request body object.
421
- * @param body RequestBody object
422
- * @returns
505
+ * Generates code for an OpenAPI request body.
506
+ *
507
+ * Handles both $ref references and inline request body definitions
508
+ * with description, content, and required properties.
509
+ *
510
+ * @param body - OpenAPI request body object or reference
511
+ * @returns TypeScript code string for the request body
512
+ *
513
+ * @example
514
+ * ```ts
515
+ * // Reference
516
+ * makeRequestBody({ $ref: '#/components/requestBodies/CreateUser' })
517
+ * // → 'CreateUserRequestBody'
518
+ *
519
+ * // Inline
520
+ * makeRequestBody({
521
+ * content: { 'application/json': { schema: {...} } },
522
+ * required: true
523
+ * })
524
+ * // → '{content:{"application/json":{schema:...}},required:true}'
525
+ * ```
423
526
  */
424
527
  export function makeRequestBody(body) {
425
528
  if ('$ref' in body && body.$ref) {
@@ -435,9 +538,22 @@ export function makeRequestBody(body) {
435
538
  return `{${result}}`;
436
539
  }
437
540
  /**
438
- * generates a media code from the given media object.
439
- * @param media Media object
440
- * @returns
541
+ * Generates code for an OpenAPI media object.
542
+ *
543
+ * Converts media type definitions including schema, examples,
544
+ * and encoding into TypeScript code.
545
+ *
546
+ * @param media - OpenAPI media object
547
+ * @returns TypeScript code string for the media
548
+ *
549
+ * @example
550
+ * ```ts
551
+ * makeMedia({
552
+ * schema: { type: 'object', properties: { name: { type: 'string' } } },
553
+ * example: { name: 'John' }
554
+ * })
555
+ * // → '{schema:z.object({name:z.string()}),example:{"name":"John"}}'
556
+ * ```
441
557
  */
442
558
  export function makeMedia(media) {
443
559
  const encodingCode = media.encoding
@@ -459,9 +575,22 @@ export function makeMedia(media) {
459
575
  return `{${result}}`;
460
576
  }
461
577
  /**
462
- * generates an encoding code from the given encoding object.
463
- * @param encoding
464
- * @returns
578
+ * Generates code for an OpenAPI encoding object.
579
+ *
580
+ * Handles encoding properties for multipart request bodies including
581
+ * contentType, headers, and nested encoding configurations.
582
+ *
583
+ * @param encoding - OpenAPI encoding object
584
+ * @returns TypeScript code string for the encoding
585
+ *
586
+ * @example
587
+ * ```ts
588
+ * makeEncoding({
589
+ * contentType: 'image/png',
590
+ * headers: { 'X-Custom': { schema: { type: 'string' } } }
591
+ * })
592
+ * // → 'contentType:"image/png",headers:{"X-Custom":{schema:z.string()}}'
593
+ * ```
465
594
  */
466
595
  export function makeEncoding(encoding) {
467
596
  const nestedEncoding = encoding.encoding
@@ -20,18 +20,3 @@ import type { Schema } from '../openapi/index.js';
20
20
  * ```
21
21
  */
22
22
  export declare function makeTypeString(schema: Schema, selfTypeName: string, cyclicGroup?: ReadonlySet<string>): string;
23
- /**
24
- * Generates a TypeScript record type string from an OpenAPI schema.
25
- *
26
- * @param valueSchema - The OpenAPI schema for the record values.
27
- * @param selfTypeName - The name of the current type (for self-reference detection).
28
- * @param cyclicGroup - Optional set of type names in a cyclic dependency group.
29
- * @returns A TypeScript record type string like `{[key:string]:ValueType}`.
30
- *
31
- * @example
32
- * ```ts
33
- * makeRecordTypeString({ type: 'string' }, 'Config')
34
- * // → '{[key:string]:string}'
35
- * ```
36
- */
37
- export declare function makeRecordTypeString(valueSchema: Schema, selfTypeName: string, cyclicGroup?: ReadonlySet<string>): string;
@@ -161,21 +161,3 @@ function makeObjectTypeString(schema, selfTypeName, cyclicGroup) {
161
161
  });
162
162
  return `{${propertyStrings.join(';')}}`;
163
163
  }
164
- /**
165
- * Generates a TypeScript record type string from an OpenAPI schema.
166
- *
167
- * @param valueSchema - The OpenAPI schema for the record values.
168
- * @param selfTypeName - The name of the current type (for self-reference detection).
169
- * @param cyclicGroup - Optional set of type names in a cyclic dependency group.
170
- * @returns A TypeScript record type string like `{[key:string]:ValueType}`.
171
- *
172
- * @example
173
- * ```ts
174
- * makeRecordTypeString({ type: 'string' }, 'Config')
175
- * // → '{[key:string]:string}'
176
- * ```
177
- */
178
- export function makeRecordTypeString(valueSchema, selfTypeName, cyclicGroup) {
179
- const valueType = makeTypeString(valueSchema, selfTypeName, cyclicGroup);
180
- return `{[key:string]:${valueType}}`;
181
- }
@@ -8,13 +8,6 @@ export declare function normalizeTypes(t?: 'string' | 'number' | 'integer' | 'da
8
8
  'string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null',
9
9
  ...('string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null')[]
10
10
  ]): ("string" | "number" | "boolean" | "object" | "integer" | "date" | "array" | "null")[];
11
- /**
12
- * Generates registration code for OpenAPI `securitySchemes`.
13
- *
14
- * @param securitySchemes - Record of scheme name to scheme properties.
15
- * @returns Multiline string of registration statements.
16
- */
17
- export declare function registerComponent(securitySchemes: Record<string, unknown>): string;
18
11
  /**
19
12
  * Checks if a value is a non-null object (record-like).
20
13
  *
@@ -7,19 +7,6 @@
7
7
  export function normalizeTypes(t) {
8
8
  return t === undefined ? [] : Array.isArray(t) ? t : [t];
9
9
  }
10
- /**
11
- * Generates registration code for OpenAPI `securitySchemes`.
12
- *
13
- * @param securitySchemes - Record of scheme name to scheme properties.
14
- * @returns Multiline string of registration statements.
15
- */
16
- export function registerComponent(securitySchemes) {
17
- return Object.entries(securitySchemes)
18
- .map(([name, scheme]) => {
19
- return `app.openAPIRegistry.registerComponent('securitySchemes','${name}',${JSON.stringify(scheme)})`;
20
- })
21
- .join('\n');
22
- }
23
10
  /**
24
11
  * Checks if a value is a non-null object (record-like).
25
12
  *
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.74",
4
+ "version": "0.9.75",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [