hono-takibi 0.8.1 → 0.8.2

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 (54) hide show
  1. package/dist/cli/takibi.js +1 -1
  2. package/dist/generator/zod/helper/array-reference-schema.js +2 -2
  3. package/dist/generator/zod/index.js +5 -4
  4. package/dist/generator/zod/z/array.d.ts +1 -1
  5. package/dist/generator/zod/z/array.js +13 -20
  6. package/dist/generator/zod/z/enum.d.ts +1 -1
  7. package/dist/generator/zod/z/index.d.ts +0 -1
  8. package/dist/generator/zod/z/index.js +0 -1
  9. package/dist/generator/zod/z/integer.d.ts +1 -1
  10. package/dist/generator/zod/z/integer.js +72 -38
  11. package/dist/generator/zod/z/number.d.ts +8 -1
  12. package/dist/generator/zod/z/number.js +57 -25
  13. package/dist/generator/zod/z/object.d.ts +1 -1
  14. package/dist/generator/zod/z/object.js +3 -2
  15. package/dist/generator/zod/z/string.d.ts +1 -1
  16. package/dist/generator/zod/z/string.js +13 -15
  17. package/dist/generator/zod-openapi-hono/app/helper/docs.d.ts +1 -1
  18. package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.d.ts +3 -3
  19. package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.js +6 -7
  20. package/dist/generator/zod-openapi-hono/openapi/route/params/request-params-array.js +3 -2
  21. package/dist/generator/zod-openapi-hono/openapi/route/request/body/index.d.ts +2 -2
  22. package/dist/generator/zod-openapi-hono/openapi/route/request/body/index.js +6 -6
  23. package/dist/helper/allof.d.ts +1 -1
  24. package/dist/helper/allof.js +7 -3
  25. package/dist/helper/anyof.d.ts +1 -1
  26. package/dist/helper/anyof.js +2 -3
  27. package/dist/helper/index.d.ts +0 -1
  28. package/dist/helper/index.js +0 -1
  29. package/dist/helper/maybe-apply-nullability.d.ts +1 -1
  30. package/dist/helper/oneof.d.ts +1 -1
  31. package/dist/helper/oneof.js +3 -3
  32. package/dist/helper/pick-types.d.ts +1 -1
  33. package/dist/helper/resolve-schemas-dependencies.d.ts +1 -1
  34. package/dist/openapi/index.d.ts +190 -2
  35. package/dist/openapi/index.js +26 -1
  36. package/dist/typespec/index.d.ts +2 -1
  37. package/dist/typespec/index.js +15 -8
  38. package/dist/utils/index.d.ts +0 -131
  39. package/dist/utils/index.js +0 -162
  40. package/dist/vite-plugin/index.d.ts +1 -1
  41. package/dist/vite-plugin/index.js +36 -5
  42. package/package.json +1 -1
  43. package/dist/generator/zod/z/record.d.ts +0 -8
  44. package/dist/generator/zod/z/record.js +0 -12
  45. package/dist/helper/not.d.ts +0 -13
  46. package/dist/helper/not.js +0 -18
  47. package/dist/openapi/parse-openapi.d.ts +0 -9
  48. package/dist/openapi/parse-openapi.js +0 -23
  49. package/dist/openapi/types.d.ts +0 -181
  50. package/dist/openapi/types.js +0 -1
  51. package/dist/vite-plugin/vite-tsp.d.ts +0 -10
  52. package/dist/vite-plugin/vite-tsp.js +0 -33
  53. package/dist/vite-plugin/vite.d.ts +0 -10
  54. package/dist/vite-plugin/vite.js +0 -31
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { fmt } from '../format/index.js';
3
3
  import { mkdir, writeFile } from '../fsp/index.js';
4
4
  import { zodOpenAPIHono } from '../generator/zod-openapi-hono/openapi/index.js';
5
- import { parseOpenAPI } from '../openapi/parse-openapi.js';
5
+ import { parseOpenAPI } from '../openapi/index.js';
6
6
  import { asyncAndThen, ok } from '../result/index.js';
7
7
  import { templateCode } from './template-code.js';
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { array, refName } from '../../../utils/index.js';
1
+ import { refName } from '../../../utils/index.js';
2
2
  /**
3
3
  * Generates a Zod schema string for an array of referenced schemas.
4
4
  *
@@ -36,5 +36,5 @@ export function arrayReferenceSchema(schema) {
36
36
  if (!ref) {
37
37
  return 'z.array(z.any())';
38
38
  }
39
- return array(`${ref}Schema`);
39
+ return `z.array(${ref}Schema)`;
40
40
  }
@@ -1,7 +1,6 @@
1
1
  import { allOf } from '../../helper/allof.js';
2
2
  import { anyOf } from '../../helper/anyof.js';
3
3
  import { maybeApplyNullability, pickTypes } from '../../helper/index.js';
4
- import { not } from '../../helper/not.js';
5
4
  import { oneOf } from '../../helper/oneof.js';
6
5
  import { refName } from '../../utils/index.js';
7
6
  import { _enum, array, integer, number, object, string } from './z/index.js';
@@ -59,8 +58,9 @@ import { _enum, array, integer, number, object, string } from './z/index.js';
59
58
  */
60
59
  export function zod(schema) {
61
60
  /* $ref */
62
- if (schema.$ref)
61
+ if (schema.$ref) {
63
62
  return `${refName(schema.$ref)}Schema`;
63
+ }
64
64
  /* const */
65
65
  if (schema.const !== undefined) {
66
66
  return maybeApplyNullability(`z.literal(${JSON.stringify(schema.const)})`, schema);
@@ -111,11 +111,12 @@ export function zod(schema) {
111
111
  return allOf(schema);
112
112
  }
113
113
  if (schema.not) {
114
- return not(schema);
114
+ return 'z.unknown()';
115
115
  }
116
116
  /* null only */
117
- if (types.length === 1 && types[0] === 'null')
117
+ if (types.length === 1 && types[0] === 'null') {
118
118
  return 'z.null()';
119
+ }
119
120
  console.warn(`Unknown schema: ${JSON.stringify(schema)} - fallback to z.any()`);
120
121
  return 'z.any()';
121
122
  }
@@ -1,2 +1,2 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
2
  export declare function array(schema: Schema): string;
@@ -1,27 +1,20 @@
1
- import { length, max, min } from '../../../utils/index.js';
2
1
  import { zod } from '../index.js';
3
2
  export function array(schema) {
4
- // fall back to any[] if items が無い
5
3
  const z = `z.array(${schema.items ? zod(schema.items) : 'z.any()'})`;
6
- // minItems / maxItems → .min() / .max()
7
- if (schema.minItems !== undefined && schema.maxItems !== undefined) {
8
- return schema.minItems === schema.maxItems
9
- ? `${z}${length(schema.minItems)}`
10
- : `${z}${min(schema.minItems)}${max(schema.maxItems)}`;
4
+ // minItems / maxItems → .length() / .min() / .max()
5
+ if (typeof schema.minItems === 'number' && typeof schema.maxItems === 'number') {
6
+ // minItems === maxItems → .length(n)
7
+ if (schema.minItems === schema.maxItems) {
8
+ return `${z}.length(${schema.minItems})`;
9
+ }
10
+ // minItems ≠ maxItems → .min(n).max(n)
11
+ return `${z}.min(${schema.minItems}).max(${schema.maxItems})`;
11
12
  }
12
- if (schema.minItems !== undefined)
13
- return `${z}${min(schema.minItems)}`;
14
- if (schema.maxItems !== undefined)
15
- return `${z}${max(schema.maxItems)}`;
16
- /* legacy: minLength / maxLength on array */
17
- if (schema.minLength !== undefined && schema.maxLength !== undefined) {
18
- return schema.minLength === schema.maxLength
19
- ? `${z}${length(schema.minLength)}`
20
- : `${z}${min(schema.minLength)}${max(schema.maxLength)}`;
13
+ if (typeof schema.minItems === 'number') {
14
+ return `${z}.min(${schema.minItems})`;
15
+ }
16
+ if (typeof schema.maxItems === 'number') {
17
+ return `${z}.max(${schema.maxItems})`;
21
18
  }
22
- if (schema.minLength !== undefined)
23
- return `${z}${min(schema.minLength)}`;
24
- if (schema.maxLength !== undefined)
25
- return `${z}${max(schema.maxLength)}`;
26
19
  return z;
27
20
  }
@@ -1,4 +1,4 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
2
  /**
3
3
  * Generate a Zod enum schema string from an OpenAPI Schema object.
4
4
  *
@@ -3,5 +3,4 @@ export { _enum } from './enum.js';
3
3
  export { integer } from './integer.js';
4
4
  export { number } from './number.js';
5
5
  export { object } from './object.js';
6
- export { record } from './record.js';
7
6
  export { string } from './string.js';
@@ -3,5 +3,4 @@ export { _enum } from './enum.js';
3
3
  export { integer } from './integer.js';
4
4
  export { number } from './number.js';
5
5
  export { object } from './object.js';
6
- export { record } from './record.js';
7
6
  export { string } from './string.js';
@@ -1,4 +1,4 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
2
  /**
3
3
  * Generates a Zod schema for integer types based on OpenAPI schema.
4
4
  * Supports int32, int64, and bigint formats.
@@ -1,4 +1,3 @@
1
- import { regex } from '../../../utils/index.js';
2
1
  /**
3
2
  * Generates a Zod schema for integer types based on OpenAPI schema.
4
3
  * Supports int32, int64, and bigint formats.
@@ -7,55 +6,90 @@ import { regex } from '../../../utils/index.js';
7
6
  * @returns The Zod schema string
8
7
  */
9
8
  export function integer(schema) {
10
- /* ─────────────── 1. base type ─────────────── */
11
9
  const isInt32 = schema.format === 'int32';
12
10
  const isInt64 = schema.format === 'int64';
13
11
  const isBigInt = schema.format === 'bigint';
14
- const out = [
12
+ const o = [
15
13
  isInt32 ? 'z.int32()' : isInt64 ? 'z.int64()' : isBigInt ? 'z.bigint()' : 'z.int()',
16
14
  ];
17
- /* ─────────────── 2. helpers ─────────────── */
18
- /**
19
- * Converts a numeric literal into the correct representation
20
- * for int64 / bigint boundaries and defaults.
21
- */
22
- const lit = (n, forceCtor = false) => {
23
- if (isBigInt || forceCtor)
15
+ const lit = (n) => {
16
+ if (isBigInt)
24
17
  return `BigInt(${n})`;
25
18
  if (isInt64)
26
19
  return `${n}n`;
27
20
  return `${n}`;
28
21
  };
29
- /* ─────────────── 3. pattern ─────────────── */
30
- if (schema.pattern)
31
- out.push(regex(schema.pattern));
32
- /* ─────────────── 4. lower bound ─────────────── */
33
- if (typeof schema.exclusiveMinimum === 'number') {
34
- out.push(`.gt(${lit(schema.exclusiveMinimum)})`);
22
+ // minimum
23
+ if (schema.minimum !== undefined || schema.exclusiveMinimum !== undefined) {
24
+ // > 0
25
+ // z.int().positive().safeParse(1) // { success: true }
26
+ // z.int().positive().safeParse(0) // { success: false }
27
+ if ((schema.minimum ?? schema.exclusiveMinimum) === 0 && schema.exclusiveMinimum === true) {
28
+ o.push('.positive()');
29
+ }
30
+ // >= 0
31
+ // z.int().nonnegative().safeParse(0) // { success: true }
32
+ // z.int().nonnegative().safeParse(-1) // { success: false }
33
+ else if ((schema.minimum ?? schema.exclusiveMinimum) === 0 &&
34
+ schema.exclusiveMinimum === false) {
35
+ o.push('.nonnegative()');
36
+ }
37
+ // > value
38
+ // z.int().gt(100) // value > 100
39
+ // z.int().gt(100).safeParse(101) // { success: true }
40
+ // z.int().gt(100).safeParse(100) // { success: false }
41
+ else if ((schema.exclusiveMinimum === true || schema.minimum === undefined) &&
42
+ typeof (schema.minimum ?? schema.exclusiveMinimum) === 'number') {
43
+ o.push(`.gt(${lit((schema.minimum ?? schema.exclusiveMinimum))})`);
44
+ }
45
+ // >= value
46
+ // z.int().min(100) // value >= 100
47
+ // z.int().min(100).safeParse(100) // { success: true }
48
+ // z.int().min(100).safeParse(99) // { success: false }
49
+ else if (typeof schema.minimum === 'number') {
50
+ o.push(`.min(${lit(schema.minimum)})`);
51
+ }
35
52
  }
36
- else if (schema.minimum === 0 && schema.exclusiveMinimum === true) {
37
- out.push('.positive()');
53
+ // maximum
54
+ if (schema.maximum !== undefined || schema.exclusiveMaximum !== undefined) {
55
+ // < 0
56
+ // z.int().negative().safeParse(-1) // { success: true }
57
+ // z.int().negative().safeParse(0) // { success: false }
58
+ if ((schema.maximum ?? schema.exclusiveMaximum) === 0 && schema.exclusiveMaximum === true) {
59
+ o.push('.negative()');
60
+ }
61
+ // <= 0
62
+ // z.int().nonpositive().safeParse(0) // { success: true }
63
+ // z.int().nonpositive().safeParse(1) // { success: false }
64
+ else if ((schema.maximum ?? schema.exclusiveMaximum) === 0 &&
65
+ schema.exclusiveMaximum === false) {
66
+ o.push('.nonpositive()');
67
+ }
68
+ // < value
69
+ // z.int().lt(100) // value < 100
70
+ // z.int().lt(100).safeParse(99) -> { success: true }
71
+ // z.int().lt(100).safeParse(100) -> { success: false }
72
+ else if ((schema.exclusiveMaximum === true || schema.maximum === undefined) &&
73
+ typeof (schema.maximum ?? schema.exclusiveMaximum) === 'number') {
74
+ o.push(`.lt(${lit((schema.maximum ?? schema.exclusiveMaximum))})`);
75
+ }
76
+ // <= value
77
+ // z.int().max(100) // value <= 100
78
+ // z.int().max(100).safeParse(100) -> { success: true }
79
+ // z.int().max(100).safeParse(101) -> { success: false }
80
+ else if (typeof schema.maximum === 'number') {
81
+ o.push(`.max(${lit(schema.maximum)})`);
82
+ }
38
83
  }
39
- else if (typeof schema.minimum === 'number') {
40
- out.push(`.min(${lit(schema.minimum)})`);
84
+ // multipleOf
85
+ // z.int().multipleOf(2).safeParse(2) // { success: true }
86
+ // z.int().multipleOf(2).safeParse(1) // { success: false }
87
+ if (schema.multipleOf !== undefined && typeof schema.multipleOf === 'number') {
88
+ o.push(`.multipleOf(${lit(schema.multipleOf)})`);
41
89
  }
42
- /* ─────────────── 5. upper bound ─────────────── */
43
- if (typeof schema.exclusiveMaximum === 'number') {
44
- out.push(`.lt(${lit(schema.exclusiveMaximum)})`);
90
+ // default (always last)
91
+ if (schema.default !== undefined && typeof schema.default === 'number') {
92
+ o.push(`.default(${lit(schema.default)})`);
45
93
  }
46
- else if (schema.maximum === 0 && schema.exclusiveMaximum === true) {
47
- out.push('.negative()');
48
- }
49
- else if (typeof schema.maximum === 'number') {
50
- out.push(`.max(${lit(schema.maximum)})`);
51
- }
52
- /* ─────────────── 6. default (always last) ─────────────── */
53
- if (schema.default !== undefined) {
54
- const def = typeof schema.default === 'number'
55
- ? lit(schema.default, /* forceCtor: BigInt as needed */ true)
56
- : JSON.stringify(schema.default);
57
- out.push(`.default(${def})`);
58
- }
59
- /* ─────────────── 7. finish ─────────────── */
60
- return out.join('');
94
+ return o.join('');
61
95
  }
@@ -1,2 +1,9 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod schema for number types based on OpenAPI schema.
4
+ * Supports float, float32, float64, and number formats.
5
+ *
6
+ * @param schema - The OpenAPI schema object
7
+ * @returns The Zod schema string
8
+ */
2
9
  export declare function number(schema: Schema): string;
@@ -1,53 +1,85 @@
1
- import { _default, gt, lt, max, min, regex } from '../../../utils/index.js';
1
+ /**
2
+ * Generates a Zod schema for number types based on OpenAPI schema.
3
+ * Supports float, float32, float64, and number formats.
4
+ *
5
+ * @param schema - The OpenAPI schema object
6
+ * @returns The Zod schema string
7
+ */
2
8
  export function number(schema) {
3
- const parts = [
9
+ const o = [
4
10
  schema.format === 'float' || schema.format === 'float32'
5
11
  ? 'z.float32()'
6
12
  : schema.format === 'float64'
7
13
  ? 'z.float64()'
8
14
  : 'z.number()',
9
15
  ];
10
- if (schema.pattern)
11
- parts.push(regex(schema.pattern));
12
- if (schema.minLength !== undefined)
13
- parts.push(min(schema.minLength));
14
- if (schema.maxLength !== undefined)
15
- parts.push(max(schema.maxLength));
16
- /* -------- lower bound -------- */
16
+ // minimum
17
17
  if (schema.minimum !== undefined) {
18
- if (schema.minimum === 0) {
19
- parts.push(schema.exclusiveMinimum ? '.positive()' : '.nonpositive()');
18
+ // > 0
19
+ // z.number().positive().safeParse(1) // { success: true }
20
+ // z.number().positive().safeParse(0) // { success: false }
21
+ if (schema.minimum === 0 && schema.exclusiveMinimum === true) {
22
+ o.push('.positive()');
20
23
  }
24
+ // >= 0
25
+ // z.number().nonnegative().safeParse(0) // { success: true }
26
+ // z.number().nonnegative().safeParse(-1) // { success: false }
27
+ else if (schema.minimum === 0 && schema.exclusiveMinimum === false) {
28
+ o.push('.nonnegative()');
29
+ }
30
+ // > value
31
+ // z.number().gt(100) // value > 100
21
32
  else if (schema.exclusiveMinimum === true) {
22
- parts.push(gt(schema.minimum));
33
+ o.push(`.gt(${schema.minimum})`);
23
34
  }
35
+ // >= value
36
+ // z.number().min(100) // value >= 100
24
37
  else {
25
- parts.push(min(schema.minimum));
38
+ o.push(`.min(${schema.minimum})`);
26
39
  }
27
40
  }
28
41
  else if (typeof schema.exclusiveMinimum === 'number') {
29
- // numeric exclusiveMinimum without minimum
30
- parts.push(gt(schema.exclusiveMinimum));
42
+ // > value (no minimum)
43
+ o.push(`.gt(${schema.exclusiveMinimum})`);
31
44
  }
32
- /* -------- upper bound -------- */
45
+ // maximum
33
46
  if (schema.maximum !== undefined) {
34
- if (schema.maximum === 0) {
35
- parts.push(schema.exclusiveMaximum ? '.negative()' : '.nonnegative()');
47
+ // < 0
48
+ // z.number().negative().safeParse(-1) // { success: true }
49
+ // z.number().negative().safeParse(0) // { success: false }
50
+ if (schema.maximum === 0 && schema.exclusiveMaximum === true) {
51
+ o.push('.negative()');
52
+ }
53
+ // <= 0
54
+ // z.number().nonpositive().safeParse(0) // { success: true }
55
+ // z.number().nonpositive().safeParse(1) // { success: false }
56
+ else if (schema.maximum === 0 && schema.exclusiveMaximum === false) {
57
+ o.push('.nonpositive()');
36
58
  }
59
+ // < value
60
+ // z.number().lt(100) // value < 100
37
61
  else if (schema.exclusiveMaximum === true) {
38
- parts.push(lt(schema.maximum));
62
+ o.push(`.lt(${schema.maximum})`);
39
63
  }
64
+ // <= value
65
+ // z.number().max(100) // value <= 100
40
66
  else {
41
- parts.push(max(schema.maximum));
67
+ o.push(`.max(${schema.maximum})`);
42
68
  }
43
69
  }
44
70
  else if (typeof schema.exclusiveMaximum === 'number') {
45
- // numeric exclusiveMaximum without maximum
46
- parts.push(lt(schema.exclusiveMaximum));
71
+ // < value (no maximum)
72
+ o.push(`.lt(${schema.exclusiveMaximum})`);
73
+ }
74
+ // multipleOf
75
+ // z.number().multipleOf(2).safeParse(2) // { success: true }
76
+ // z.number().multipleOf(2).safeParse(1) // { success: false }
77
+ if (schema.multipleOf !== undefined) {
78
+ o.push(`.multipleOf(${schema.multipleOf})`);
47
79
  }
48
- /* -------- default (always last) -------- */
80
+ // default (always last)
49
81
  if (schema.default !== undefined) {
50
- parts.push(_default(schema.default));
82
+ o.push(`.default(${JSON.stringify(schema.default)})`);
51
83
  }
52
- return parts.join('');
84
+ return o.join('');
53
85
  }
@@ -1,4 +1,4 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
2
  /**
3
3
  * Generates a Zod object schema from an OpenAPI schema definition.
4
4
  *
@@ -1,8 +1,9 @@
1
1
  import { allOf } from '../../../helper/allof.js';
2
2
  import { anyOf } from '../../../helper/anyof.js';
3
3
  import { oneOf } from '../../../helper/oneof.js';
4
+ import { zodToOpenAPI } from '../../../helper/zod-to-openapi.js';
4
5
  import { propertiesSchema } from '../helper/properties-schema.js';
5
- import { record } from './record.js';
6
+ import { zod } from '../index.js';
6
7
  /**
7
8
  * Generates a Zod object schema from an OpenAPI schema definition.
8
9
  *
@@ -20,7 +21,7 @@ export function object(schema) {
20
21
  }
21
22
  return 'z.any()';
22
23
  }
23
- return record(schema.additionalProperties);
24
+ return `z.record(z.string(),${zodToOpenAPI(zod(schema.additionalProperties), schema.additionalProperties)})`;
24
25
  }
25
26
  if (schema.properties) {
26
27
  const zodSchema = propertiesSchema(schema.properties, Array.isArray(schema.required) ? schema.required : []);
@@ -1,3 +1,3 @@
1
- import type { Schema } from '../../../openapi/types.js';
1
+ import type { Schema } from '../../../openapi/index.js';
2
2
  /** Build a Zod string schema from an OpenAPI string schema. */
3
3
  export declare function string(schema: Schema): string;
@@ -1,4 +1,4 @@
1
- import { _default, length, max, min, regex } from '../../../utils/index.js';
1
+ import { regex } from '../../../utils/index.js';
2
2
  const FORMAT_STRING = {
3
3
  email: '.email()',
4
4
  uuid: '.uuid()',
@@ -30,26 +30,24 @@ const FORMAT_STRING = {
30
30
  /** Build a Zod string schema from an OpenAPI string schema. */
31
31
  export function string(schema) {
32
32
  const parts = [];
33
- /* ---------- base / format ---------- */
34
- const fmt = schema.format && FORMAT_STRING[schema.format];
35
- parts.push(fmt ? `z${fmt}` : 'z.string()');
36
- /* ---------- pattern ---------- */
33
+ const format = schema.format && FORMAT_STRING[schema.format];
34
+ parts.push(format ? `z${format}` : 'z.string()');
37
35
  if (schema.pattern)
38
36
  parts.push(regex(schema.pattern));
39
- /* ---------- length constraints ---------- */
40
- const { minLength, maxLength } = schema;
41
37
  // special-case: equal min & max → .length()
42
- if (minLength !== undefined && maxLength !== undefined && minLength === maxLength) {
43
- parts.push(length(minLength)); // utils.length() -> '.length(n)'
38
+ if (schema.minLength !== undefined &&
39
+ schema.maxLength !== undefined &&
40
+ schema.minLength === schema.maxLength) {
41
+ parts.push(`.length(${schema.minLength})`);
44
42
  }
45
43
  else {
46
- if (minLength !== undefined)
47
- parts.push(min(minLength));
48
- if (maxLength !== undefined)
49
- parts.push(max(maxLength));
44
+ if (schema.minLength !== undefined)
45
+ parts.push(`.min(${schema.minLength})`);
46
+ if (schema.maxLength !== undefined)
47
+ parts.push(`.max(${schema.maxLength})`);
50
48
  }
51
- /* ---------- default (always last) ---------- */
49
+ /* default (always last)*/
52
50
  if (schema.default !== undefined)
53
- parts.push(_default(schema.default));
51
+ parts.push(`.default(${JSON.stringify(schema.default)})`);
54
52
  return parts.join('');
55
53
  }
@@ -1,4 +1,4 @@
1
- import type { OpenAPI } from '../../../../openapi/types.js';
1
+ import type { OpenAPI } from '../../../../openapi/index.js';
2
2
  /**
3
3
  * Extracts top-level OpenAPI document metadata.
4
4
  *
@@ -1,8 +1,8 @@
1
- import type { Parameters } from '../../../../../openapi/types.js';
1
+ import type { Parameters } from '../../../../../openapi/index.js';
2
2
  /**
3
3
  * Generates a Zod schema string for a query parameter, with coercion applied based on its type.
4
4
  *
5
- * @param baseSchema - The base Zod schema string.
5
+ * @param schema - The base Zod schema string.
6
6
  * @param param - The OpenAPI parameter object.
7
7
  * @returns The transformed Zod schema string.
8
8
  *
@@ -11,4 +11,4 @@ import type { Parameters } from '../../../../../openapi/types.js';
11
11
  * - Applies `stringbool` to booleans to support string-based boolean input.
12
12
  * - Returns the base schema unchanged for other types or locations.
13
13
  */
14
- export declare function queryParameter(baseSchema: string, param: Parameters): string;
14
+ export declare function queryParameter(schema: string, param: Parameters): string;
@@ -1,8 +1,7 @@
1
- import { coerce, stringbool } from '../../../../../utils/index.js';
2
1
  /**
3
2
  * Generates a Zod schema string for a query parameter, with coercion applied based on its type.
4
3
  *
5
- * @param baseSchema - The base Zod schema string.
4
+ * @param schema - The base Zod schema string.
6
5
  * @param param - The OpenAPI parameter object.
7
6
  * @returns The transformed Zod schema string.
8
7
  *
@@ -11,15 +10,15 @@ import { coerce, stringbool } from '../../../../../utils/index.js';
11
10
  * - Applies `stringbool` to booleans to support string-based boolean input.
12
11
  * - Returns the base schema unchanged for other types or locations.
13
12
  */
14
- export function queryParameter(baseSchema, param) {
13
+ export function queryParameter(schema, param) {
15
14
  if (param.in === 'query' && param.schema.type === 'number') {
16
- return coerce(baseSchema);
15
+ return `z.coerce.${schema.replace('z.', '')}`;
17
16
  }
18
17
  if (param.in === 'query' && param.schema.type === 'boolean') {
19
- return stringbool(baseSchema);
18
+ return schema.replace('boolean', 'stringbool');
20
19
  }
21
20
  if (param.in === 'query' && param.schema.type === 'date') {
22
- return coerce(baseSchema);
21
+ return `z.coerce.${schema.replace('z.', '')}`;
23
22
  }
24
- return baseSchema;
23
+ return schema;
25
24
  }
@@ -1,4 +1,3 @@
1
- import { schema } from '../../../../../utils/index.js';
2
1
  /**
3
2
  * Generates an array of Zod validator strings from OpenAPI parameter objects.
4
3
  *
@@ -20,7 +19,9 @@ export function requestParamsArray(paramsObj) {
20
19
  const obj = paramsObj[section];
21
20
  // 2.1 process only if object is not empty
22
21
  if (Object.keys(obj).length) {
23
- const s = schema(obj);
22
+ const s = `z.object({${Object.entries(obj)
23
+ .map(([key, val]) => `${key}:${val}`)
24
+ .join(',')}})`;
24
25
  // path is params convention
25
26
  if (section === 'path') {
26
27
  return `params:${s}`;
@@ -4,7 +4,7 @@ import type { Content } from '../../../../../../openapi/index.js';
4
4
  *
5
5
  * @param required - Indicates if the request body is required.
6
6
  * @param content - OpenAPI content object describing media types and schemas.
7
- * @param zodSchema - Zod schema string used for validation.
7
+ * @param schema - Zod schema string used for validation.
8
8
  * @returns A formatted request body definition string, or an empty string if unsupported.
9
9
  */
10
- export declare function requestBody(required: boolean, content: Content, zodSchema: string): string;
10
+ export declare function requestBody(required: boolean, content: Content, schema: string): string;
@@ -1,13 +1,13 @@
1
- import { coerce, isUniqueContentSchema } from '../../../../../../utils/index.js';
1
+ import { isUniqueContentSchema } from '../../../../../../utils/index.js';
2
2
  /**
3
3
  * Generates a request body configuration string for a route.
4
4
  *
5
5
  * @param required - Indicates if the request body is required.
6
6
  * @param content - OpenAPI content object describing media types and schemas.
7
- * @param zodSchema - Zod schema string used for validation.
7
+ * @param schema - Zod schema string used for validation.
8
8
  * @returns A formatted request body definition string, or an empty string if unsupported.
9
9
  */
10
- export function requestBody(required, content, zodSchema) {
10
+ export function requestBody(required, content, schema) {
11
11
  const contentTypes = Object.keys(content);
12
12
  if (contentTypes.length === 0)
13
13
  return '';
@@ -18,11 +18,11 @@ export function requestBody(required, content, zodSchema) {
18
18
  const contentParts = [];
19
19
  for (const contentType of contentTypes) {
20
20
  // z.date() → z.coerce.date()
21
- if (zodSchema.includes('z.date()')) {
22
- contentParts.push(`'${contentType}':{schema:${coerce(zodSchema)}}`);
21
+ if (schema.includes('z.date()')) {
22
+ contentParts.push(`'${contentType}':{schema:z.coerce.${schema.replace('z.', '')}}`);
23
23
  }
24
24
  else {
25
- contentParts.push(`'${contentType}':{schema:${zodSchema}}`);
25
+ contentParts.push(`'${contentType}':{schema:${schema}}`);
26
26
  }
27
27
  }
28
28
  return `body:{required:${required},content:{${contentParts.join(',')}},},`;
@@ -1,4 +1,4 @@
1
- import type { Schema } from '../openapi/types.js';
1
+ import type { Schema } from '../openapi/index.js';
2
2
  /**
3
3
  * Converts an OpenAPI `allOf` schema into a Zod intersection schema.
4
4
  *
@@ -1,5 +1,4 @@
1
1
  import { zodSchemaFromSubSchema } from '../generator/zod/helper/zod-schema-from-sub-schema.js';
2
- import { intersection, isNullableSchema } from '../utils/index.js';
3
2
  /**
4
3
  * Converts an OpenAPI `allOf` schema into a Zod intersection schema.
5
4
  *
@@ -18,7 +17,12 @@ export function allOf(schema) {
18
17
  return 'z.any()';
19
18
  }
20
19
  const { nullable, schemas } = schema.allOf.reduce((acc, subSchema) => {
21
- if (isNullableSchema(subSchema)) {
20
+ const isNullable = typeof subSchema === 'object' &&
21
+ subSchema !== null &&
22
+ 'nullable' in subSchema &&
23
+ subSchema.nullable === true &&
24
+ Object.keys(subSchema).length === 1;
25
+ if (isNullable) {
22
26
  acc.nullable = true;
23
27
  return acc;
24
28
  }
@@ -32,5 +36,5 @@ export function allOf(schema) {
32
36
  if (schemas.length === 1) {
33
37
  return nullable ? `${schemas[0]}.nullable()` : schemas[0];
34
38
  }
35
- return `${intersection(schemas)}${nullable ? '.nullable()' : ''}`;
39
+ return `z.intersection(${schemas.join(',')})${nullable ? '.nullable()' : ''}`;
36
40
  }
@@ -1,4 +1,4 @@
1
- import type { Schema } from '../openapi/types.js';
1
+ import type { Schema } from '../openapi/index.js';
2
2
  /**
3
3
  * Converts an OpenAPI `anyOf` schema into a Zod union expression.
4
4
  *