hono-takibi 0.9.75 → 0.9.77

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.
Files changed (75) hide show
  1. package/README.md +5 -1
  2. package/dist/cli/index.js +17 -12
  3. package/dist/config/index.d.ts +3 -0
  4. package/dist/config/index.js +10 -0
  5. package/dist/core/components/callbacks.d.ts +2 -1
  6. package/dist/core/components/callbacks.js +4 -3
  7. package/dist/core/components/examples.d.ts +2 -1
  8. package/dist/core/components/examples.js +5 -3
  9. package/dist/core/components/headers.d.ts +3 -2
  10. package/dist/core/components/headers.js +7 -6
  11. package/dist/core/components/links.d.ts +2 -1
  12. package/dist/core/components/links.js +4 -3
  13. package/dist/core/components/parameters.d.ts +3 -2
  14. package/dist/core/components/parameters.js +7 -6
  15. package/dist/core/components/requestBodies.d.ts +3 -2
  16. package/dist/core/components/requestBodies.js +7 -6
  17. package/dist/core/components/responses.d.ts +3 -2
  18. package/dist/core/components/responses.js +7 -6
  19. package/dist/core/components/schemas.d.ts +7 -3
  20. package/dist/core/components/schemas.js +11 -7
  21. package/dist/core/components/securitySchemes.d.ts +2 -1
  22. package/dist/core/components/securitySchemes.js +4 -3
  23. package/dist/core/route/index.d.ts +2 -1
  24. package/dist/core/route/index.js +5 -4
  25. package/dist/core/rpc/index.d.ts +1 -1
  26. package/dist/core/rpc/index.js +7 -6
  27. package/dist/core/takibi/index.d.ts +1 -0
  28. package/dist/core/type/index.d.ts +6 -1
  29. package/dist/core/type/index.js +14 -9
  30. package/dist/generator/zod-openapi-hono/openapi/components/callbacks.d.ts +5 -1
  31. package/dist/generator/zod-openapi-hono/openapi/components/callbacks.js +7 -2
  32. package/dist/generator/zod-openapi-hono/openapi/components/examples.d.ts +2 -1
  33. package/dist/generator/zod-openapi-hono/openapi/components/examples.js +5 -3
  34. package/dist/generator/zod-openapi-hono/openapi/components/headers.d.ts +2 -1
  35. package/dist/generator/zod-openapi-hono/openapi/components/headers.js +5 -4
  36. package/dist/generator/zod-openapi-hono/openapi/components/index.d.ts +1 -0
  37. package/dist/generator/zod-openapi-hono/openapi/components/index.js +9 -9
  38. package/dist/generator/zod-openapi-hono/openapi/components/links.d.ts +5 -1
  39. package/dist/generator/zod-openapi-hono/openapi/components/links.js +7 -2
  40. package/dist/generator/zod-openapi-hono/openapi/components/parameters.d.ts +4 -3
  41. package/dist/generator/zod-openapi-hono/openapi/components/parameters.js +5 -4
  42. package/dist/generator/zod-openapi-hono/openapi/components/request-bodies.d.ts +5 -1
  43. package/dist/generator/zod-openapi-hono/openapi/components/request-bodies.js +7 -2
  44. package/dist/generator/zod-openapi-hono/openapi/components/responses.d.ts +5 -1
  45. package/dist/generator/zod-openapi-hono/openapi/components/responses.js +7 -2
  46. package/dist/generator/zod-openapi-hono/openapi/components/schemas.d.ts +6 -2
  47. package/dist/generator/zod-openapi-hono/openapi/components/schemas.js +8 -3
  48. package/dist/generator/zod-openapi-hono/openapi/components/securitySchemes.d.ts +5 -1
  49. package/dist/generator/zod-openapi-hono/openapi/components/securitySchemes.js +7 -2
  50. package/dist/generator/zod-openapi-hono/openapi/index.d.ts +1 -0
  51. package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
  52. package/dist/generator/zod-openapi-hono/openapi/routes/create-route.d.ts +11 -1
  53. package/dist/generator/zod-openapi-hono/openapi/routes/create-route.js +13 -2
  54. package/dist/generator/zod-openapi-hono/openapi/routes/index.d.ts +11 -1
  55. package/dist/generator/zod-openapi-hono/openapi/routes/index.js +12 -2
  56. package/dist/generator/zod-to-openapi/type/index.d.ts +19 -1
  57. package/dist/generator/zod-to-openapi/type/index.js +21 -3
  58. package/dist/helper/{barell.d.ts → barrel.d.ts} +4 -4
  59. package/dist/helper/{barell.js → barrel.js} +3 -3
  60. package/dist/helper/code.d.ts +106 -8
  61. package/dist/helper/code.js +145 -46
  62. package/dist/helper/exports.d.ts +2 -1
  63. package/dist/helper/exports.js +4 -2
  64. package/dist/helper/index.d.ts +1 -1
  65. package/dist/helper/index.js +1 -1
  66. package/dist/helper/openapi.js +21 -32
  67. package/dist/helper/schema.d.ts +21 -8
  68. package/dist/helper/schema.js +27 -14
  69. package/dist/helper/type.d.ts +8 -1
  70. package/dist/helper/type.js +60 -35
  71. package/dist/helper/wrap.js +1 -1
  72. package/dist/utils/index.d.ts +25 -36
  73. package/dist/utils/index.js +32 -43
  74. package/dist/vite-plugin/index.js +2 -2
  75. package/package.json +1 -1
package/README.md CHANGED
@@ -75,7 +75,9 @@ export const getRoute = createRoute({
75
75
  description: 'OK',
76
76
  content: {
77
77
  'application/json': {
78
- schema: z.object({ message: z.string().openapi({ example: 'Hono Takibi🔥' }) }),
78
+ schema: z
79
+ .object({ message: z.string().openapi({ example: 'Hono Takibi🔥' }) })
80
+ .openapi({ required: ['message'] }),
79
81
  },
80
82
  },
81
83
  },
@@ -105,6 +107,7 @@ Options:
105
107
  --export-examples export examples
106
108
  --export-links export links
107
109
  --export-callbacks export callbacks
110
+ --readonly make schemas immutable (adds .readonly() and 'as const')
108
111
  --template generate app file and handler stubs
109
112
  --test generate empty *.test.ts files
110
113
  --base-path <path> api prefix (default: /)
@@ -133,6 +136,7 @@ export default defineConfig({
133
136
  input: 'openapi.yaml',
134
137
  'zod-openapi': {
135
138
  output: './src/index.ts',
139
+ readonly: true,
136
140
  exportSchemas: true,
137
141
  exportSchemasTypes: true,
138
142
  exportParameters: true,
package/dist/cli/index.js CHANGED
@@ -39,6 +39,7 @@ Options:
39
39
  --export-examples export examples
40
40
  --export-links export links
41
41
  --export-callbacks export callbacks
42
+ --readonly make schemas immutable (adds .readonly() and 'as const')
42
43
  --template generate app file and handler stubs
43
44
  --test generate empty *.test.ts files
44
45
  --base-path <path> api prefix (default: /)
@@ -128,6 +129,7 @@ function parseCli(args) {
128
129
  test: args.includes('--test'),
129
130
  basePath: getFlagValue(args, '--base-path') ?? '/', // default: /
130
131
  componentsOptions: {
132
+ readonly: args.includes('--readonly'),
131
133
  exportSchemas: args.includes('--export-schemas'),
132
134
  exportSchemasTypes: args.includes('--export-schemas-types'),
133
135
  exportParameters: args.includes('--export-parameters'),
@@ -176,6 +178,7 @@ export async function honoTakibi() {
176
178
  const [takibiResult, schemaResult, parameterResult, headersResult, examplesResult, linksResult, callbacksResult, securitySchemesResult, requestBodiesResult, responsesResult, routeResult, typeResult, rpcResult,] = await Promise.all([
177
179
  config['zod-openapi']?.output
178
180
  ? takibi(openAPI, config['zod-openapi'].output, false, false, '/', {
181
+ readonly: config['zod-openapi'].readonly,
179
182
  exportSchemasTypes: config['zod-openapi'].exportSchemasTypes ?? false,
180
183
  exportSchemas: config['zod-openapi'].exportSchemas ?? false,
181
184
  exportParametersTypes: config['zod-openapi'].exportParametersTypes ?? false,
@@ -191,38 +194,40 @@ export async function honoTakibi() {
191
194
  })
192
195
  : Promise.resolve(undefined),
193
196
  config['zod-openapi']?.components?.schemas
194
- ? schemas(openAPI.components?.schemas, config['zod-openapi']?.components?.schemas?.output, config['zod-openapi']?.components?.schemas?.split ?? false, config['zod-openapi']?.components?.schemas?.exportTypes ?? false)
197
+ ? schemas(openAPI.components?.schemas, config['zod-openapi']?.components?.schemas?.output, config['zod-openapi']?.components?.schemas?.split ?? false, config['zod-openapi']?.components?.schemas?.exportTypes ?? false, config['zod-openapi']?.readonly)
195
198
  : Promise.resolve(undefined),
196
199
  config['zod-openapi']?.components?.parameters
197
- ? 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)
200
+ ? 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, config['zod-openapi']?.readonly)
198
201
  : Promise.resolve(undefined),
199
202
  config['zod-openapi']?.components?.headers
200
- ? 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)
203
+ ? 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, config['zod-openapi']?.readonly)
201
204
  : Promise.resolve(undefined),
202
205
  config['zod-openapi']?.components?.examples
203
- ? examples(openAPI.components?.examples, config['zod-openapi']?.components?.examples?.output, config['zod-openapi']?.components?.examples?.split ?? false)
206
+ ? examples(openAPI.components?.examples, config['zod-openapi']?.components?.examples?.output, config['zod-openapi']?.components?.examples?.split ?? false, config['zod-openapi']?.readonly)
204
207
  : Promise.resolve(undefined),
205
208
  config['zod-openapi']?.components?.links
206
- ? links(openAPI.components?.links, config['zod-openapi']?.components?.links?.output, config['zod-openapi']?.components?.links?.split ?? false)
209
+ ? links(openAPI.components?.links, config['zod-openapi']?.components?.links?.output, config['zod-openapi']?.components?.links?.split ?? false, config['zod-openapi']?.readonly)
207
210
  : Promise.resolve(undefined),
208
211
  config['zod-openapi']?.components?.callbacks
209
- ? callbacks(openAPI.components?.callbacks, config['zod-openapi']?.components?.callbacks?.output, config['zod-openapi']?.components?.callbacks?.split ?? false)
212
+ ? callbacks(openAPI.components?.callbacks, config['zod-openapi']?.components?.callbacks?.output, config['zod-openapi']?.components?.callbacks?.split ?? false, config['zod-openapi']?.readonly)
210
213
  : Promise.resolve(undefined),
211
214
  config['zod-openapi']?.components?.securitySchemes
212
- ? securitySchemes(openAPI.components?.securitySchemes, config['zod-openapi']?.components?.securitySchemes?.output, config['zod-openapi']?.components?.securitySchemes?.split ?? false)
215
+ ? securitySchemes(openAPI.components?.securitySchemes, config['zod-openapi']?.components?.securitySchemes?.output, config['zod-openapi']?.components?.securitySchemes?.split ?? false, config['zod-openapi']?.readonly)
213
216
  : Promise.resolve(undefined),
214
217
  config['zod-openapi']?.components?.requestBodies
215
- ? requestBodies(openAPI.components?.requestBodies, config['zod-openapi']?.components?.requestBodies?.output, config['zod-openapi']?.components?.requestBodies?.split ?? false, config['zod-openapi']?.components)
218
+ ? requestBodies(openAPI.components?.requestBodies, config['zod-openapi']?.components?.requestBodies?.output, config['zod-openapi']?.components?.requestBodies?.split ?? false, config['zod-openapi']?.components, config['zod-openapi']?.readonly)
216
219
  : Promise.resolve(undefined),
217
220
  config['zod-openapi']?.components?.responses
218
- ? responses(openAPI.components?.responses, config['zod-openapi']?.components?.responses?.output, config['zod-openapi']?.components?.responses?.split ?? false, config['zod-openapi']?.components)
221
+ ? responses(openAPI.components?.responses, config['zod-openapi']?.components?.responses?.output, config['zod-openapi']?.components?.responses?.split ?? false, config['zod-openapi']?.components, config['zod-openapi']?.readonly)
219
222
  : Promise.resolve(undefined),
220
223
  config['zod-openapi']?.routes
221
- ? route(openAPI, config['zod-openapi'].routes, config['zod-openapi'].components)
224
+ ? route(openAPI, config['zod-openapi'].routes, config['zod-openapi'].components, config['zod-openapi']?.readonly)
225
+ : Promise.resolve(undefined),
226
+ config.type
227
+ ? type(openAPI, config.type.output, config.type.readonly)
222
228
  : Promise.resolve(undefined),
223
- config.type ? type(openAPI, config.type.output) : Promise.resolve(undefined),
224
229
  config.rpc
225
- ? rpc(openAPI, config.rpc.output, config.rpc.import, config.rpc.split ?? false)
230
+ ? rpc(openAPI, config.rpc.output, config.rpc.import, config.rpc.split ?? false, config.rpc.client ?? 'client')
226
231
  : Promise.resolve(undefined),
227
232
  ]);
228
233
  if (takibiResult && !takibiResult.ok)
@@ -2,6 +2,7 @@ type Config = {
2
2
  readonly input: `${string}.yaml` | `${string}.json` | `${string}.tsp`;
3
3
  readonly 'zod-openapi'?: {
4
4
  readonly output?: `${string}.ts`;
5
+ readonly readonly?: boolean;
5
6
  readonly exportSchemas?: boolean;
6
7
  readonly exportSchemasTypes?: boolean;
7
8
  readonly exportParameters?: boolean;
@@ -70,12 +71,14 @@ type Config = {
70
71
  };
71
72
  };
72
73
  readonly type?: {
74
+ readonly readonly?: boolean;
73
75
  readonly output: `${string}.ts`;
74
76
  };
75
77
  readonly rpc?: {
76
78
  readonly output: string | `${string}.ts`;
77
79
  readonly import: string;
78
80
  readonly split?: boolean;
81
+ readonly client?: string;
79
82
  };
80
83
  };
81
84
  /**
@@ -54,6 +54,13 @@ export function parseConfig(config) {
54
54
  }
55
55
  // zod-openapi
56
56
  if (config['zod-openapi'] !== undefined) {
57
+ if (config['zod-openapi'].readonly !== undefined &&
58
+ typeof config['zod-openapi'].readonly !== 'boolean') {
59
+ return {
60
+ ok: false,
61
+ error: `Invalid readonly format for zod-openapi: ${String(config['zod-openapi'].readonly)}`,
62
+ };
63
+ }
57
64
  if (config['zod-openapi'].exportSchemasTypes !== undefined &&
58
65
  typeof config['zod-openapi'].exportSchemasTypes !== 'boolean') {
59
66
  return {
@@ -192,6 +199,9 @@ export function parseConfig(config) {
192
199
  if (config.rpc.split !== undefined && typeof config.rpc.split !== 'boolean') {
193
200
  return { ok: false, error: `Invalid split format for rpc: ${String(config.rpc.split)}` };
194
201
  }
202
+ if (config.rpc.client !== undefined && typeof config.rpc.client !== 'string') {
203
+ return { ok: false, error: `Invalid client format for rpc: ${String(config.rpc.client)}` };
204
+ }
195
205
  // split: true requires directory (no .ts)
196
206
  if (config.rpc.split === true && isTs(config.rpc.output)) {
197
207
  return {
@@ -5,6 +5,7 @@ import type { Components } from '../../openapi/index.js';
5
5
  * @param callbacks - OpenAPI callbacks object
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
+ * @param readonly - Whether to add `as const` assertion to the output.
8
9
  * @returns Promise resolving to success message or error
9
10
  *
10
11
  * @example
@@ -25,7 +26,7 @@ import type { Components } from '../../openapi/index.js';
25
26
  * // Creates: src/callbacks/onPaymentComplete.ts, src/callbacks/onOrderUpdate.ts, src/callbacks/index.ts
26
27
  * ```
27
28
  */
28
- export declare function callbacks(callbacks: Components['callbacks'], output: string, split: boolean): Promise<{
29
+ export declare function callbacks(callbacks: Components['callbacks'], output: string, split: boolean, readonly?: boolean | undefined): Promise<{
29
30
  readonly ok: true;
30
31
  readonly value: string;
31
32
  } | {
@@ -15,6 +15,7 @@ import { core, makeExports } from '../../helper/index.js';
15
15
  * @param callbacks - OpenAPI callbacks object
16
16
  * @param output - Output file path or directory
17
17
  * @param split - Whether to split into multiple files
18
+ * @param readonly - Whether to add `as const` assertion to the output.
18
19
  * @returns Promise resolving to success message or error
19
20
  *
20
21
  * @example
@@ -35,19 +36,19 @@ import { core, makeExports } from '../../helper/index.js';
35
36
  * // Creates: src/callbacks/onPaymentComplete.ts, src/callbacks/onOrderUpdate.ts, src/callbacks/index.ts
36
37
  * ```
37
38
  */
38
- export async function callbacks(callbacks, output, split) {
39
+ export async function callbacks(callbacks, output, split, readonly) {
39
40
  if (!callbacks)
40
41
  return { ok: false, error: 'No callbacks found' };
41
42
  const keys = Object.keys(callbacks);
42
43
  if (keys.length === 0)
43
44
  return { ok: true, value: 'No callbacks found' };
44
45
  if (split) {
45
- const exportsResult = await makeExports(callbacks, 'Callback', output);
46
+ const exportsResult = await makeExports(callbacks, 'Callback', output, readonly);
46
47
  if (!exportsResult.ok)
47
48
  return { ok: false, error: exportsResult.error };
48
49
  return { ok: true, value: exportsResult.value };
49
50
  }
50
- const code = makeExportConst(callbacks, 'Callback');
51
+ const code = makeExportConst(callbacks, 'Callback', readonly);
51
52
  const coreResult = await core(code, path.dirname(output), output);
52
53
  if (!coreResult.ok)
53
54
  return { ok: false, error: coreResult.error };
@@ -5,6 +5,7 @@ import type { Components } from '../../openapi/index.js';
5
5
  * @param examples - OpenAPI examples object
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
+ * @param readonly - Whether to add `as const` assertion to the output.
8
9
  * @returns Promise resolving to success message or error
9
10
  *
10
11
  * @example
@@ -25,7 +26,7 @@ import type { Components } from '../../openapi/index.js';
25
26
  * // Creates: src/examples/userExample.ts, src/examples/postExample.ts, src/examples/index.ts
26
27
  * ```
27
28
  */
28
- export declare function examples(examples: Components['examples'], output: string, split: boolean): Promise<{
29
+ export declare function examples(examples: Components['examples'], output: string, split: boolean, readonly?: boolean | undefined): Promise<{
29
30
  readonly ok: true;
30
31
  readonly value: string;
31
32
  } | {
@@ -23,6 +23,7 @@ const hasRef = (val) => typeof val === 'object' && val !== null && '$ref' in val
23
23
  * @param examples - OpenAPI examples object
24
24
  * @param output - Output file path or directory
25
25
  * @param split - Whether to split into multiple files
26
+ * @param readonly - Whether to add `as const` assertion to the output.
26
27
  * @returns Promise resolving to success message or error
27
28
  *
28
29
  * @example
@@ -43,12 +44,13 @@ const hasRef = (val) => typeof val === 'object' && val !== null && '$ref' in val
43
44
  * // Creates: src/examples/userExample.ts, src/examples/postExample.ts, src/examples/index.ts
44
45
  * ```
45
46
  */
46
- export async function examples(examples, output, split) {
47
+ export async function examples(examples, output, split, readonly) {
47
48
  if (!examples)
48
49
  return { ok: false, error: 'No examples found' };
49
50
  const keys = Object.keys(examples);
50
51
  if (keys.length === 0)
51
52
  return { ok: true, value: 'No examples found' };
53
+ const asConst = readonly ? ' as const' : '';
52
54
  if (split) {
53
55
  const outDir = output.replace(/\.ts$/, '');
54
56
  // Generate index.ts with sorted exports
@@ -70,7 +72,7 @@ export async function examples(examples, output, split) {
70
72
  return core(body, path.dirname(filePath), filePath);
71
73
  }
72
74
  // Inline value: generate JSON export
73
- const body = `export const ${name} = ${JSON.stringify(v)}\n`;
75
+ const body = `export const ${name} = ${JSON.stringify(v)}${asConst}\n`;
74
76
  return core(body, path.dirname(filePath), filePath);
75
77
  }),
76
78
  core(indexCode, path.dirname(path.join(outDir, 'index.ts')), path.join(outDir, 'index.ts')),
@@ -83,7 +85,7 @@ export async function examples(examples, output, split) {
83
85
  value: `Generated Example code written to ${outDir}/*.ts (index.ts included)`,
84
86
  };
85
87
  }
86
- const code = makeExportConst(examples, 'Example');
88
+ const code = makeExportConst(examples, 'Example', readonly);
87
89
  const coreResult = await core(code, path.dirname(output), output);
88
90
  if (!coreResult.ok)
89
91
  return { ok: false, error: coreResult.error };
@@ -6,7 +6,8 @@ import type { Components } from '../../openapi/index.js';
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
8
  * @param exportType - Whether to export TypeScript types
9
- * @param imports - Schema import configuration for references
9
+ * @param components - Schema import configuration for references
10
+ * @param readonly - Whether to add `.readonly()` to Zod schemas
10
11
  * @returns Promise resolving to success message or error
11
12
  *
12
13
  * @example
@@ -35,7 +36,7 @@ export declare function headers(headers: Components['headers'], output: string,
35
36
  readonly split?: boolean;
36
37
  readonly import?: string;
37
38
  };
38
- }): Promise<{
39
+ }, readonly?: boolean | undefined): Promise<{
39
40
  readonly ok: true;
40
41
  readonly value: string;
41
42
  } | {
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import path from 'node:path';
10
10
  import { headersCode } from '../../generator/zod-openapi-hono/openapi/components/headers.js';
11
- import { core, makeBarell, makeImports } from '../../helper/index.js';
11
+ import { core, makeBarrel, makeImports } from '../../helper/index.js';
12
12
  import { lowerFirst, renderNamedImport } from '../../utils/index.js';
13
13
  /**
14
14
  * Generates header component files.
@@ -17,7 +17,8 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
17
17
  * @param output - Output file path or directory
18
18
  * @param split - Whether to split into multiple files
19
19
  * @param exportType - Whether to export TypeScript types
20
- * @param imports - Schema import configuration for references
20
+ * @param components - Schema import configuration for references
21
+ * @param readonly - Whether to add `.readonly()` to Zod schemas
21
22
  * @returns Promise resolving to success message or error
22
23
  *
23
24
  * @example
@@ -40,7 +41,7 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
40
41
  * // Creates: src/headers/xRequestId.ts, src/headers/xCorrelationId.ts, src/headers/index.ts
41
42
  * ```
42
43
  */
43
- export async function headers(headers, output, split, exportType, components) {
44
+ export async function headers(headers, output, split, exportType, components, readonly) {
44
45
  if (!headers)
45
46
  return { ok: false, error: 'No headers found' };
46
47
  const headerNames = Object.keys(headers);
@@ -52,11 +53,11 @@ export async function headers(headers, output, split, exportType, components) {
52
53
  const allResults = await Promise.all([
53
54
  ...headerNames.map((headerName) => {
54
55
  const singleComponent = { headers: { [headerName]: headers[headerName] } };
55
- const code = headersCode(singleComponent, true, exportType);
56
+ const code = headersCode(singleComponent, true, exportType, readonly);
56
57
  const filePath = path.join(outDir, `${lowerFirst(headerName)}.ts`);
57
58
  return core(toFileCode(code, filePath), path.dirname(filePath), filePath);
58
59
  }),
59
- core(makeBarell(headers), outDir, path.join(outDir, 'index.ts')),
60
+ core(makeBarrel(headers), outDir, path.join(outDir, 'index.ts')),
60
61
  ]);
61
62
  const firstError = allResults.find((r) => !r.ok);
62
63
  if (firstError)
@@ -67,7 +68,7 @@ export async function headers(headers, output, split, exportType, components) {
67
68
  };
68
69
  }
69
70
  const importCode = renderNamedImport(['z'], '@hono/zod-openapi');
70
- const headerDefinitions = headersCode({ headers }, true, exportType);
71
+ const headerDefinitions = headersCode({ headers }, true, exportType, readonly);
71
72
  const headerDefinitionsCode = `${importCode}\n\n${headerDefinitions}`;
72
73
  const coreResult = await core(toFileCode(headerDefinitionsCode, output), path.dirname(output), output);
73
74
  if (!coreResult.ok)
@@ -5,6 +5,7 @@ import type { Components } from '../../openapi/index.js';
5
5
  * @param links - OpenAPI links object
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
+ * @param readonly - Whether to add `as const` assertion to the output.
8
9
  * @returns Promise resolving to success message or error
9
10
  *
10
11
  * @example
@@ -25,7 +26,7 @@ import type { Components } from '../../openapi/index.js';
25
26
  * // Creates: src/links/getUserById.ts, src/links/getPostById.ts, src/links/index.ts
26
27
  * ```
27
28
  */
28
- export declare function links(links: Components['links'], output: string, split: boolean): Promise<{
29
+ export declare function links(links: Components['links'], output: string, split: boolean, readonly?: boolean | undefined): Promise<{
29
30
  readonly ok: true;
30
31
  readonly value: string;
31
32
  } | {
@@ -15,6 +15,7 @@ import { core, makeExports } from '../../helper/index.js';
15
15
  * @param links - OpenAPI links object
16
16
  * @param output - Output file path or directory
17
17
  * @param split - Whether to split into multiple files
18
+ * @param readonly - Whether to add `as const` assertion to the output.
18
19
  * @returns Promise resolving to success message or error
19
20
  *
20
21
  * @example
@@ -35,19 +36,19 @@ import { core, makeExports } from '../../helper/index.js';
35
36
  * // Creates: src/links/getUserById.ts, src/links/getPostById.ts, src/links/index.ts
36
37
  * ```
37
38
  */
38
- export async function links(links, output, split) {
39
+ export async function links(links, output, split, readonly) {
39
40
  if (!links)
40
41
  return { ok: false, error: 'No links found' };
41
42
  const keys = Object.keys(links);
42
43
  if (keys.length === 0)
43
44
  return { ok: true, value: 'No links found' };
44
45
  if (split) {
45
- const exportsResult = await makeExports(links, 'Link', output);
46
+ const exportsResult = await makeExports(links, 'Link', output, readonly);
46
47
  if (!exportsResult.ok)
47
48
  return { ok: false, error: exportsResult.error };
48
49
  return { ok: true, value: exportsResult.value };
49
50
  }
50
- const code = makeExportConst(links, 'Link');
51
+ const code = makeExportConst(links, 'Link', readonly);
51
52
  const coreResult = await core(code, path.dirname(output), output);
52
53
  if (!coreResult.ok)
53
54
  return { ok: false, error: coreResult.error };
@@ -6,7 +6,8 @@ import type { Components } from '../../openapi/index.js';
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
8
  * @param exportType - Whether to export TypeScript types
9
- * @param imports - Schema import configuration for references
9
+ * @param components - Schema import configuration for references
10
+ * @param readonly - Whether to add `.readonly()` to Zod schemas
10
11
  * @returns Promise resolving to success message or error
11
12
  *
12
13
  * @example
@@ -35,7 +36,7 @@ export declare function parameters(parameters: Components['parameters'], output:
35
36
  readonly split?: boolean;
36
37
  readonly import?: string;
37
38
  };
38
- }): Promise<{
39
+ }, readonly?: boolean | undefined): Promise<{
39
40
  readonly ok: true;
40
41
  readonly value: string;
41
42
  } | {
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import path from 'node:path';
10
10
  import { parametersCode } from '../../generator/zod-openapi-hono/openapi/components/parameters.js';
11
- import { core, makeBarell, makeImports } from '../../helper/index.js';
11
+ import { core, makeBarrel, makeImports } from '../../helper/index.js';
12
12
  import { lowerFirst, renderNamedImport } from '../../utils/index.js';
13
13
  /**
14
14
  * Generates parameter component files.
@@ -17,7 +17,8 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
17
17
  * @param output - Output file path or directory
18
18
  * @param split - Whether to split into multiple files
19
19
  * @param exportType - Whether to export TypeScript types
20
- * @param imports - Schema import configuration for references
20
+ * @param components - Schema import configuration for references
21
+ * @param readonly - Whether to add `.readonly()` to Zod schemas
21
22
  * @returns Promise resolving to success message or error
22
23
  *
23
24
  * @example
@@ -40,7 +41,7 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
40
41
  * // Creates: src/parameters/userId.ts, src/parameters/page.ts, src/parameters/index.ts
41
42
  * ```
42
43
  */
43
- export async function parameters(parameters, output, split, exportType, components) {
44
+ export async function parameters(parameters, output, split, exportType, components, readonly) {
44
45
  if (!parameters)
45
46
  return { ok: false, error: 'No parameters found' };
46
47
  const parameterNames = Object.keys(parameters);
@@ -52,11 +53,11 @@ export async function parameters(parameters, output, split, exportType, componen
52
53
  const allResults = await Promise.all([
53
54
  ...parameterNames.map((parameterName) => {
54
55
  const singleComponent = { parameters: { [parameterName]: parameters[parameterName] } };
55
- const code = parametersCode(singleComponent, true, exportType);
56
+ const code = parametersCode(singleComponent, true, exportType, readonly);
56
57
  const filePath = path.join(outDir, `${lowerFirst(parameterName)}.ts`);
57
58
  return core(toFileCode(code, filePath), path.dirname(filePath), filePath);
58
59
  }),
59
- core(makeBarell(parameters), outDir, path.join(outDir, 'index.ts')),
60
+ core(makeBarrel(parameters), outDir, path.join(outDir, 'index.ts')),
60
61
  ]);
61
62
  const firstError = allResults.find((r) => !r.ok);
62
63
  if (firstError)
@@ -67,7 +68,7 @@ export async function parameters(parameters, output, split, exportType, componen
67
68
  };
68
69
  }
69
70
  const importCode = renderNamedImport(['z'], '@hono/zod-openapi');
70
- const parameterDefinitions = parametersCode({ parameters }, true, exportType);
71
+ const parameterDefinitions = parametersCode({ parameters }, true, exportType, readonly);
71
72
  const parameterDefinitionsCode = `${importCode}\n\n${parameterDefinitions}`;
72
73
  const coreResult = await core(toFileCode(parameterDefinitionsCode, output), path.dirname(output), output);
73
74
  if (!coreResult.ok)
@@ -5,7 +5,8 @@ import type { Components } from '../../openapi/index.js';
5
5
  * @param requestBodies - OpenAPI requestBodies object
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
- * @param imports - Schema import configuration for references
8
+ * @param components - Schema import configuration for references
9
+ * @param readonly - Whether to add `as const` assertion to the output.
9
10
  * @returns Promise resolving to success message or error
10
11
  *
11
12
  * @example
@@ -32,7 +33,7 @@ export declare function requestBodies(requestBodies: Components['requestBodies']
32
33
  readonly split?: boolean;
33
34
  readonly import?: string;
34
35
  };
35
- }): Promise<{
36
+ }, readonly?: boolean | undefined): Promise<{
36
37
  readonly ok: true;
37
38
  readonly value: string;
38
39
  } | {
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import path from 'node:path';
10
10
  import { requestBodiesCode } from '../../generator/zod-openapi-hono/openapi/components/request-bodies.js';
11
- import { core, makeBarell, makeImports } from '../../helper/index.js';
11
+ import { core, makeBarrel, makeImports } from '../../helper/index.js';
12
12
  import { lowerFirst, renderNamedImport } from '../../utils/index.js';
13
13
  /**
14
14
  * Generates requestBody component files.
@@ -16,7 +16,8 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
16
16
  * @param requestBodies - OpenAPI requestBodies object
17
17
  * @param output - Output file path or directory
18
18
  * @param split - Whether to split into multiple files
19
- * @param imports - Schema import configuration for references
19
+ * @param components - Schema import configuration for references
20
+ * @param readonly - Whether to add `as const` assertion to the output.
20
21
  * @returns Promise resolving to success message or error
21
22
  *
22
23
  * @example
@@ -37,7 +38,7 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
37
38
  * // Creates: src/requestBodies/createUser.ts, src/requestBodies/updateUser.ts, src/requestBodies/index.ts
38
39
  * ```
39
40
  */
40
- export async function requestBodies(requestBodies, output, split, components) {
41
+ export async function requestBodies(requestBodies, output, split, components, readonly) {
41
42
  if (!requestBodies)
42
43
  return { ok: false, error: 'No requestBodies found' };
43
44
  const bodyNames = Object.keys(requestBodies);
@@ -49,11 +50,11 @@ export async function requestBodies(requestBodies, output, split, components) {
49
50
  const allResults = await Promise.all([
50
51
  ...bodyNames.map((bodyName) => {
51
52
  const singleComponent = { requestBodies: { [bodyName]: requestBodies[bodyName] } };
52
- const code = requestBodiesCode(singleComponent, true);
53
+ const code = requestBodiesCode(singleComponent, true, readonly);
53
54
  const filePath = path.join(outDir, `${lowerFirst(bodyName)}.ts`);
54
55
  return core(toFileCode(code, filePath), path.dirname(filePath), filePath);
55
56
  }),
56
- core(makeBarell(requestBodies), outDir, path.join(outDir, 'index.ts')),
57
+ core(makeBarrel(requestBodies), outDir, path.join(outDir, 'index.ts')),
57
58
  ]);
58
59
  const firstError = allResults.find((r) => !r.ok);
59
60
  if (firstError)
@@ -64,7 +65,7 @@ export async function requestBodies(requestBodies, output, split, components) {
64
65
  };
65
66
  }
66
67
  const importCode = renderNamedImport(['z'], '@hono/zod-openapi');
67
- const bodyDefinitions = requestBodiesCode({ requestBodies }, true);
68
+ const bodyDefinitions = requestBodiesCode({ requestBodies }, true, readonly);
68
69
  const bodyDefinitionsCode = `${importCode}\n\n${bodyDefinitions}`;
69
70
  const coreResult = await core(toFileCode(bodyDefinitionsCode, output), path.dirname(output), output);
70
71
  if (!coreResult.ok)
@@ -5,7 +5,8 @@ import type { Components } from '../../openapi/index.js';
5
5
  * @param responses - OpenAPI responses object
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
- * @param imports - Schema import configuration for references
8
+ * @param components - Schema import configuration for references
9
+ * @param readonly - Whether to add `as const` assertion to the output.
9
10
  * @returns Promise resolving to success message or error
10
11
  *
11
12
  * @example
@@ -32,7 +33,7 @@ export declare function responses(responses: Components['responses'], output: st
32
33
  readonly split?: boolean;
33
34
  readonly import?: string;
34
35
  };
35
- }): Promise<{
36
+ }, readonly?: boolean | undefined): Promise<{
36
37
  readonly ok: true;
37
38
  readonly value: string;
38
39
  } | {
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import path from 'node:path';
10
10
  import { responsesCode } from '../../generator/zod-openapi-hono/openapi/components/responses.js';
11
- import { core, makeBarell, makeImports } from '../../helper/index.js';
11
+ import { core, makeBarrel, makeImports } from '../../helper/index.js';
12
12
  import { lowerFirst, renderNamedImport } from '../../utils/index.js';
13
13
  /**
14
14
  * Generates response component files.
@@ -16,7 +16,8 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
16
16
  * @param responses - OpenAPI responses object
17
17
  * @param output - Output file path or directory
18
18
  * @param split - Whether to split into multiple files
19
- * @param imports - Schema import configuration for references
19
+ * @param components - Schema import configuration for references
20
+ * @param readonly - Whether to add `as const` assertion to the output.
20
21
  * @returns Promise resolving to success message or error
21
22
  *
22
23
  * @example
@@ -37,7 +38,7 @@ import { lowerFirst, renderNamedImport } from '../../utils/index.js';
37
38
  * // Creates: src/responses/notFound.ts, src/responses/unauthorized.ts, src/responses/index.ts
38
39
  * ```
39
40
  */
40
- export async function responses(responses, output, split, components) {
41
+ export async function responses(responses, output, split, components, readonly) {
41
42
  if (!responses)
42
43
  return { ok: false, error: 'No responses found' };
43
44
  const responseNames = Object.keys(responses);
@@ -49,11 +50,11 @@ export async function responses(responses, output, split, components) {
49
50
  const allResults = await Promise.all([
50
51
  ...responseNames.map((responseName) => {
51
52
  const singleComponent = { responses: { [responseName]: responses[responseName] } };
52
- const code = responsesCode(singleComponent, true);
53
+ const code = responsesCode(singleComponent, true, readonly);
53
54
  const filePath = path.join(outDir, `${lowerFirst(responseName)}.ts`);
54
55
  return core(toFileCode(code, filePath), path.dirname(filePath), filePath);
55
56
  }),
56
- core(makeBarell(responses), outDir, path.join(outDir, 'index.ts')),
57
+ core(makeBarrel(responses), outDir, path.join(outDir, 'index.ts')),
57
58
  ]);
58
59
  const firstError = allResults.find((r) => !r.ok);
59
60
  if (firstError)
@@ -64,7 +65,7 @@ export async function responses(responses, output, split, components) {
64
65
  };
65
66
  }
66
67
  const importCode = renderNamedImport(['z'], '@hono/zod-openapi');
67
- const responseDefinitions = responsesCode({ responses }, true);
68
+ const responseDefinitions = responsesCode({ responses }, true, readonly);
68
69
  const responseDefinitionsCode = `${importCode}\n\n${responseDefinitions}`;
69
70
  const coreResult = await core(toFileCode(responseDefinitionsCode, output), path.dirname(output), output);
70
71
  if (!coreResult.ok)
@@ -6,6 +6,7 @@ import type { Components } from '../../openapi/index.js';
6
6
  * @param output - Output file path or directory
7
7
  * @param split - Whether to split into multiple files
8
8
  * @param exportType - Whether to export TypeScript types
9
+ * @param readonly - Whether to add `.readonly()` modifier to schemas
9
10
  * @returns Promise resolving to success message or error
10
11
  *
11
12
  * @example
@@ -15,20 +16,23 @@ import type { Components } from '../../openapi/index.js';
15
16
  * { User: { type: 'object', ... } },
16
17
  * 'src/schemas.ts',
17
18
  * false,
18
- * true
19
+ * true,
20
+ * false
19
21
  * )
20
22
  *
21
- * // Generate schemas in split mode
23
+ * // Generate schemas in split mode with readonly
22
24
  * await schemas(
23
25
  * { User: {...}, Post: {...} },
24
26
  * 'src/schemas',
25
27
  * true,
28
+ * true,
26
29
  * true
27
30
  * )
28
31
  * // Creates: src/schemas/user.ts, src/schemas/post.ts, src/schemas/index.ts
32
+ * // Each schema has .readonly() modifier
29
33
  * ```
30
34
  */
31
- export declare function schemas(schemas: Components['schemas'], output: string, split: boolean, exportType: boolean): Promise<{
35
+ export declare function schemas(schemas: Components['schemas'], output: string, split: boolean, exportType: boolean, readonly?: boolean): Promise<{
32
36
  readonly ok: true;
33
37
  readonly value: string;
34
38
  } | {