hono-takibi 0.4.3 → 0.4.5
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/generators/zod/generate-zod-enum.js +12 -0
- package/dist/generators/zod/generate-zod-gt.d.ts +7 -0
- package/dist/generators/zod/generate-zod-gt.js +12 -0
- package/dist/generators/zod/generate-zod-length.d.ts +11 -0
- package/dist/generators/zod/generate-zod-length.js +16 -0
- package/dist/generators/zod/generate-zod-lt.d.ts +7 -0
- package/dist/generators/zod/generate-zod-lt.js +12 -0
- package/dist/generators/zod/generate-zod-nullable.d.ts +6 -0
- package/dist/generators/zod/generate-zod-nullable.js +11 -0
- package/dist/generators/zod/generate-zod-number.d.ts +23 -0
- package/dist/generators/zod/generate-zod-number.js +75 -0
- package/dist/generators/zod/{generate-zod-string-schema.d.ts → generate-zod-string.d.ts} +12 -11
- package/dist/generators/zod/{generate-zod-string-schema.js → generate-zod-string.js} +28 -17
- package/dist/generators/zod/helper/strip-max-if-lt-exist-helper.d.ts +1 -0
- package/dist/generators/zod/helper/strip-max-if-lt-exist-helper.js +6 -0
- package/dist/generators/zod/helper/strip-min-if-gt-exist-helper.d.ts +1 -0
- package/dist/generators/zod/helper/strip-min-if-gt-exist-helper.js +6 -0
- package/dist/generators/zod/helper/strip-min-max-exist-helper.d.ts +1 -0
- package/dist/generators/zod/helper/strip-min-max-exist-helper.js +6 -0
- package/dist/generators/zod/schema/generate-zod-schema.js +58 -5
- package/dist/types/index.d.ts +4 -0
- package/package.json +3 -1
- package/dist/generators/zod/generate-zod-number-schema.d.ts +0 -21
- package/dist/generators/zod/generate-zod-number-schema.js +0 -41
|
@@ -7,5 +7,17 @@ function generateZodEnum(schema) {
|
|
|
7
7
|
const openapi_example = (0, generate_zod_to_openapi_1.generateZodToOpenAPI)(schema.example);
|
|
8
8
|
return `z.enum(${JSON.stringify(schema.enum)})${openapi_example}`;
|
|
9
9
|
}
|
|
10
|
+
// number
|
|
11
|
+
if (schema.type === 'number' && schema.enum) {
|
|
12
|
+
return `z.literal(${schema.enum})`;
|
|
13
|
+
}
|
|
14
|
+
// bigint
|
|
15
|
+
if (schema.type === 'bigint' && schema.enum) {
|
|
16
|
+
return `z.literal(${schema.enum}n)`;
|
|
17
|
+
}
|
|
18
|
+
// boolean
|
|
19
|
+
if (schema.type === 'boolean' && schema.enum) {
|
|
20
|
+
return `z.literal(${schema.enum})`;
|
|
21
|
+
}
|
|
10
22
|
return `z.enum(${JSON.stringify(schema.enum)})`;
|
|
11
23
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodGt = generateZodGt;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod gt validation
|
|
6
|
+
*
|
|
7
|
+
* @param minimum - Minimum value
|
|
8
|
+
* @returns Zod gt validation string
|
|
9
|
+
*/
|
|
10
|
+
function generateZodGt(minimum) {
|
|
11
|
+
return `.gt(${minimum})`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a Zod length validation string
|
|
3
|
+
*
|
|
4
|
+
* @param length - The length value to validate against
|
|
5
|
+
* @returns The Zod length validation string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const lengthValidation = generateZodLength(10)
|
|
9
|
+
* // Returns: 'length(10)'
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateZodLength(length: number): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodLength = generateZodLength;
|
|
4
|
+
/**
|
|
5
|
+
* Generates a Zod length validation string
|
|
6
|
+
*
|
|
7
|
+
* @param length - The length value to validate against
|
|
8
|
+
* @returns The Zod length validation string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const lengthValidation = generateZodLength(10)
|
|
12
|
+
* // Returns: 'length(10)'
|
|
13
|
+
*/
|
|
14
|
+
function generateZodLength(length) {
|
|
15
|
+
return `.length(${length})`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodLt = generateZodLt;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod lt validation
|
|
6
|
+
*
|
|
7
|
+
* @param maximum - Maximum value
|
|
8
|
+
* @returns Zod lt validation string
|
|
9
|
+
*/
|
|
10
|
+
function generateZodLt(maximum) {
|
|
11
|
+
return `.lt(${maximum})`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodNullable = generateZodNullable;
|
|
4
|
+
/**
|
|
5
|
+
* Generates a zod nullable validation
|
|
6
|
+
*
|
|
7
|
+
* @returns zod nullable
|
|
8
|
+
*/
|
|
9
|
+
function generateZodNullable() {
|
|
10
|
+
return '.nullable()';
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DefaultValue, ExampleValue } from '../../types';
|
|
2
|
+
type GenerateZodNumberParams = {
|
|
3
|
+
pattern?: string;
|
|
4
|
+
minLength?: number;
|
|
5
|
+
maxLength?: number;
|
|
6
|
+
minimum?: number;
|
|
7
|
+
maximum?: number;
|
|
8
|
+
exclusiveMinimum?: boolean;
|
|
9
|
+
exclusiveMaximum?: boolean;
|
|
10
|
+
default?: DefaultValue;
|
|
11
|
+
example?: ExampleValue;
|
|
12
|
+
paramName?: string;
|
|
13
|
+
isPath?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Generates zod number
|
|
17
|
+
*
|
|
18
|
+
* @function generateZodNumber
|
|
19
|
+
* @param args - zod number params
|
|
20
|
+
* @returns zod number
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateZodNumber(args: GenerateZodNumberParams): string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodNumber = generateZodNumber;
|
|
4
|
+
const generate_zod_default_1 = require("./generate-zod-default");
|
|
5
|
+
const generate_zod_gt_1 = require("./generate-zod-gt");
|
|
6
|
+
const generate_zod_lt_1 = require("./generate-zod-lt");
|
|
7
|
+
const generate_zod_max_1 = require("./generate-zod-max");
|
|
8
|
+
const generate_zod_min_1 = require("./generate-zod-min");
|
|
9
|
+
const generate_zod_regex_1 = require("./generate-zod-regex");
|
|
10
|
+
const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
|
|
11
|
+
/**
|
|
12
|
+
* Generates zod number
|
|
13
|
+
*
|
|
14
|
+
* @function generateZodNumber
|
|
15
|
+
* @param args - zod number params
|
|
16
|
+
* @returns zod number
|
|
17
|
+
*/
|
|
18
|
+
function generateZodNumber(args) {
|
|
19
|
+
const validations = ['z.number()'];
|
|
20
|
+
// pattern
|
|
21
|
+
if (args.pattern) {
|
|
22
|
+
validations.push((0, generate_zod_regex_1.generateZodRegex)(args.pattern));
|
|
23
|
+
}
|
|
24
|
+
// minLength
|
|
25
|
+
if (args.minLength) {
|
|
26
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(args.minLength));
|
|
27
|
+
}
|
|
28
|
+
// maxLength
|
|
29
|
+
if (args.maxLength) {
|
|
30
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(args.maxLength));
|
|
31
|
+
}
|
|
32
|
+
// minimum
|
|
33
|
+
if (args.minimum) {
|
|
34
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(args.minimum));
|
|
35
|
+
}
|
|
36
|
+
// maximum
|
|
37
|
+
if (args.maximum) {
|
|
38
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(args.maximum));
|
|
39
|
+
}
|
|
40
|
+
// default
|
|
41
|
+
if (args.default) {
|
|
42
|
+
validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
|
|
43
|
+
}
|
|
44
|
+
// example
|
|
45
|
+
if (args.example) {
|
|
46
|
+
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example, args.paramName, args.isPath));
|
|
47
|
+
}
|
|
48
|
+
// 0 falsy value
|
|
49
|
+
// minimum === 0
|
|
50
|
+
// positive
|
|
51
|
+
if (args.minimum === 0 && args.exclusiveMinimum) {
|
|
52
|
+
validations.push('.positive()');
|
|
53
|
+
}
|
|
54
|
+
// nonpositive
|
|
55
|
+
if (args.minimum === 0 && !args.exclusiveMinimum) {
|
|
56
|
+
validations.push('.nonpositive()');
|
|
57
|
+
}
|
|
58
|
+
// negative
|
|
59
|
+
if (args.maximum === 0 && args.exclusiveMaximum) {
|
|
60
|
+
validations.push('.negative()');
|
|
61
|
+
}
|
|
62
|
+
// gt
|
|
63
|
+
if (args.minimum) {
|
|
64
|
+
if (args.minimum > 0 && args.exclusiveMinimum) {
|
|
65
|
+
validations.push((0, generate_zod_gt_1.generateZodGt)(args.minimum));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// lt
|
|
69
|
+
if (args.maximum) {
|
|
70
|
+
if (args.maximum > 0 && args.exclusiveMaximum) {
|
|
71
|
+
validations.push((0, generate_zod_lt_1.generateZodLt)(args.maximum));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return validations.join('');
|
|
75
|
+
}
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import type { FormatString, ExampleValue, DefaultValue } from '../../types';
|
|
2
|
-
type
|
|
2
|
+
type GenerateZodStringParams = {
|
|
3
3
|
pattern?: string;
|
|
4
4
|
minLength?: number;
|
|
5
5
|
maxLength?: number;
|
|
6
6
|
format?: FormatString;
|
|
7
|
+
nullable?: boolean;
|
|
7
8
|
default?: DefaultValue;
|
|
8
9
|
example?: ExampleValue;
|
|
9
10
|
paramName?: string;
|
|
10
11
|
isPath?: boolean;
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
|
-
* Generates
|
|
14
|
+
* Generates zod string schema
|
|
14
15
|
*
|
|
15
|
-
* @function
|
|
16
|
-
* @param args -
|
|
17
|
-
* @returns
|
|
16
|
+
* @function generateZodString
|
|
17
|
+
* @param args - zod string params
|
|
18
|
+
* @returns zod string
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* // Basic string validation
|
|
21
|
-
*
|
|
22
|
+
* generateZodString({})
|
|
22
23
|
* // Returns: 'z.string()'
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* // With regex pattern
|
|
26
|
-
*
|
|
27
|
+
* generateZodString({ pattern: '^[A-Z]+$' })
|
|
27
28
|
* // Returns: 'z.string().regex(/^[A-Z]+$/)'
|
|
28
29
|
*
|
|
29
30
|
* @example
|
|
30
31
|
* // With length constraints
|
|
31
|
-
*
|
|
32
|
+
* generateZodString({ minLength: 3, maxLength: 10 })
|
|
32
33
|
* // Returns: 'z.string().min(3).max(10)'
|
|
33
34
|
*
|
|
34
35
|
* @example
|
|
35
36
|
* // With format
|
|
36
|
-
*
|
|
37
|
+
* generateZodString({ format: 'email' })
|
|
37
38
|
* // Returns: 'z.string().email()'
|
|
38
39
|
*
|
|
39
40
|
* @example
|
|
40
41
|
* // Combined validations
|
|
41
|
-
*
|
|
42
|
+
* generateZodString({
|
|
42
43
|
* pattern: '^[a-z]+$',
|
|
43
44
|
* minLength: 3,
|
|
44
45
|
* maxLength: 10,
|
|
@@ -46,5 +47,5 @@ type GenerateZodStringSchemaParams = {
|
|
|
46
47
|
* })
|
|
47
48
|
* // Returns: 'z.string().regex(/^[a-z]+$/).min(3).max(10).email()'
|
|
48
49
|
*/
|
|
49
|
-
export declare function
|
|
50
|
+
export declare function generateZodString(args: GenerateZodStringParams): string;
|
|
50
51
|
export {};
|
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateZodString = generateZodString;
|
|
4
4
|
const get_zod_string_format_1 = require("../../core/zod/get-zod-string-format");
|
|
5
5
|
const generate_zod_default_1 = require("./generate-zod-default");
|
|
6
6
|
const generate_zod_max_1 = require("./generate-zod-max");
|
|
7
7
|
const generate_zod_min_1 = require("./generate-zod-min");
|
|
8
|
+
const generate_zod_nullable_1 = require("./generate-zod-nullable");
|
|
8
9
|
const generate_zod_regex_1 = require("./generate-zod-regex");
|
|
9
10
|
const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
|
|
10
11
|
/**
|
|
11
|
-
* Generates
|
|
12
|
+
* Generates zod string schema
|
|
12
13
|
*
|
|
13
|
-
* @function
|
|
14
|
-
* @param args -
|
|
15
|
-
* @returns
|
|
14
|
+
* @function generateZodString
|
|
15
|
+
* @param args - zod string params
|
|
16
|
+
* @returns zod string
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* // Basic string validation
|
|
19
|
-
*
|
|
20
|
+
* generateZodString({})
|
|
20
21
|
* // Returns: 'z.string()'
|
|
21
22
|
*
|
|
22
23
|
* @example
|
|
23
24
|
* // With regex pattern
|
|
24
|
-
*
|
|
25
|
+
* generateZodString({ pattern: '^[A-Z]+$' })
|
|
25
26
|
* // Returns: 'z.string().regex(/^[A-Z]+$/)'
|
|
26
27
|
*
|
|
27
28
|
* @example
|
|
28
29
|
* // With length constraints
|
|
29
|
-
*
|
|
30
|
+
* generateZodString({ minLength: 3, maxLength: 10 })
|
|
30
31
|
* // Returns: 'z.string().min(3).max(10)'
|
|
31
32
|
*
|
|
32
33
|
* @example
|
|
33
34
|
* // With format
|
|
34
|
-
*
|
|
35
|
+
* generateZodString({ format: 'email' })
|
|
35
36
|
* // Returns: 'z.string().email()'
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
38
39
|
* // Combined validations
|
|
39
|
-
*
|
|
40
|
+
* generateZodString({
|
|
40
41
|
* pattern: '^[a-z]+$',
|
|
41
42
|
* minLength: 3,
|
|
42
43
|
* maxLength: 10,
|
|
@@ -44,25 +45,35 @@ const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
|
|
|
44
45
|
* })
|
|
45
46
|
* // Returns: 'z.string().regex(/^[a-z]+$/).min(3).max(10).email()'
|
|
46
47
|
*/
|
|
47
|
-
function
|
|
48
|
+
function generateZodString(args) {
|
|
48
49
|
const validations = ['z.string()'];
|
|
49
50
|
// pattern
|
|
50
|
-
if (args.pattern)
|
|
51
|
+
if (args.pattern) {
|
|
51
52
|
validations.push((0, generate_zod_regex_1.generateZodRegex)(args.pattern));
|
|
53
|
+
}
|
|
52
54
|
// minLength
|
|
53
|
-
if (args.minLength)
|
|
55
|
+
if (args.minLength) {
|
|
54
56
|
validations.push((0, generate_zod_min_1.generateZodMin)(args.minLength));
|
|
57
|
+
}
|
|
55
58
|
// maxLength
|
|
56
|
-
if (args.maxLength)
|
|
59
|
+
if (args.maxLength) {
|
|
57
60
|
validations.push((0, generate_zod_max_1.generateZodMax)(args.maxLength));
|
|
61
|
+
}
|
|
58
62
|
// format
|
|
59
|
-
if (args.format)
|
|
63
|
+
if (args.format) {
|
|
60
64
|
validations.push((0, get_zod_string_format_1.getZodFormatString)(args.format));
|
|
65
|
+
}
|
|
61
66
|
// default
|
|
62
|
-
if (args.default)
|
|
67
|
+
if (args.default) {
|
|
63
68
|
validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
|
|
69
|
+
}
|
|
70
|
+
// nullable
|
|
71
|
+
if (args.nullable) {
|
|
72
|
+
validations.push((0, generate_zod_nullable_1.generateZodNullable)());
|
|
73
|
+
}
|
|
64
74
|
// example
|
|
65
|
-
if (args.example)
|
|
75
|
+
if (args.example) {
|
|
66
76
|
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example, args.paramName, args.isPath));
|
|
77
|
+
}
|
|
67
78
|
return validations.join('');
|
|
68
79
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stripMaxIfLtExistHelper(str: string, maximum: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stripMinIfgTExistHelper(str: string, minimum: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stripMinMaxExistHelper(str: string, min: number, max: number): string;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateZodSchema = generateZodSchema;
|
|
4
4
|
const generate_zod_array_1 = require("../generate-zod-array");
|
|
5
|
-
const
|
|
5
|
+
const generate_zod_string_1 = require("../generate-zod-string");
|
|
6
6
|
const is_format_string_1 = require("../../../core/validator/is-format-string");
|
|
7
|
-
const
|
|
7
|
+
const generate_zod_number_1 = require("../generate-zod-number");
|
|
8
8
|
const generate_zod_integer_schema_1 = require("../generate-zod-integer-schema");
|
|
9
9
|
const generate_allof_code_1 = require("../../zod-openapi-hono/openapi/component/allof/generate-allof-code");
|
|
10
10
|
const generate_anyof_code_1 = require("../../zod-openapi-hono/openapi/component/anyof/generate-anyof-code");
|
|
@@ -12,6 +12,12 @@ const generate_oneof_code_1 = require("../../zod-openapi-hono/openapi/component/
|
|
|
12
12
|
const get_variable_schema_name_helper_1 = require("../../../core/helper/get-variable-schema-name-helper");
|
|
13
13
|
const generate_zod_object_1 = require("../generate-zod-object");
|
|
14
14
|
const generate_zod_enum_1 = require("../generate-zod-enum");
|
|
15
|
+
const generate_zod_max_1 = require("../generate-zod-max");
|
|
16
|
+
const generate_zod_min_1 = require("../generate-zod-min");
|
|
17
|
+
const strip_min_if_gt_exist_helper_1 = require("../helper/strip-min-if-gt-exist-helper");
|
|
18
|
+
const strip_max_if_lt_exist_helper_1 = require("../helper/strip-max-if-lt-exist-helper");
|
|
19
|
+
const generate_zod_length_1 = require("../generate-zod-length");
|
|
20
|
+
const strip_min_max_exist_helper_1 = require("../helper/strip-min-max-exist-helper");
|
|
15
21
|
/**
|
|
16
22
|
* Mapping of OpenAPI/JSON Schema types to Zod schema strings
|
|
17
23
|
*
|
|
@@ -101,20 +107,32 @@ function generateZodSchema(config, schema, paramName, isPath) {
|
|
|
101
107
|
}
|
|
102
108
|
// string
|
|
103
109
|
if (schema.type === 'string') {
|
|
104
|
-
|
|
110
|
+
const res = (0, generate_zod_string_1.generateZodString)({
|
|
105
111
|
pattern: schema.pattern,
|
|
106
112
|
minLength: schema.minLength,
|
|
107
113
|
maxLength: schema.maxLength,
|
|
108
114
|
format: schema.format && (0, is_format_string_1.isFormatString)(schema.format) ? schema.format : undefined,
|
|
115
|
+
nullable: schema.nullable,
|
|
109
116
|
default: schema.default,
|
|
110
117
|
example: schema.example,
|
|
111
118
|
paramName,
|
|
112
119
|
isPath,
|
|
113
120
|
});
|
|
121
|
+
// length
|
|
122
|
+
if (schema.minLength &&
|
|
123
|
+
schema.maxLength &&
|
|
124
|
+
schema.maxLength &&
|
|
125
|
+
schema.minLength === schema.maxLength &&
|
|
126
|
+
res.includes(`min(${schema.minLength})`) &&
|
|
127
|
+
res.includes(`max(${schema.maxLength})`)) {
|
|
128
|
+
const property = (0, strip_min_max_exist_helper_1.stripMinMaxExistHelper)(res, schema.minLength, schema.maxLength);
|
|
129
|
+
return `${property}${(0, generate_zod_length_1.generateZodLength)(schema.minLength)}`;
|
|
130
|
+
}
|
|
131
|
+
return res;
|
|
114
132
|
}
|
|
115
133
|
// number
|
|
116
134
|
if (schema.type === 'number') {
|
|
117
|
-
|
|
135
|
+
const res = (0, generate_zod_number_1.generateZodNumber)({
|
|
118
136
|
pattern: schema.pattern,
|
|
119
137
|
minLength: schema.minLength,
|
|
120
138
|
maxLength: schema.maxLength,
|
|
@@ -124,7 +142,22 @@ function generateZodSchema(config, schema, paramName, isPath) {
|
|
|
124
142
|
example: schema.example,
|
|
125
143
|
paramName,
|
|
126
144
|
isPath,
|
|
145
|
+
exclusiveMinimum: schema.exclusiveMinimum,
|
|
146
|
+
exclusiveMaximum: schema.exclusiveMaximum,
|
|
127
147
|
});
|
|
148
|
+
// gt
|
|
149
|
+
if (res.includes(`min(${schema.minimum})`) &&
|
|
150
|
+
res.includes(`gt(${schema.minimum})`) &&
|
|
151
|
+
schema.minimum) {
|
|
152
|
+
return (0, strip_min_if_gt_exist_helper_1.stripMinIfgTExistHelper)(res, schema.minimum);
|
|
153
|
+
}
|
|
154
|
+
// lt
|
|
155
|
+
if (res.includes(`max(${schema.maximum})`) &&
|
|
156
|
+
res.includes(`lt(${schema.maximum})`) &&
|
|
157
|
+
schema.maximum) {
|
|
158
|
+
return (0, strip_max_if_lt_exist_helper_1.stripMaxIfLtExistHelper)(res, schema.maximum);
|
|
159
|
+
}
|
|
160
|
+
return res;
|
|
128
161
|
}
|
|
129
162
|
// integer
|
|
130
163
|
if (schema.type === 'integer') {
|
|
@@ -140,8 +173,28 @@ function generateZodSchema(config, schema, paramName, isPath) {
|
|
|
140
173
|
});
|
|
141
174
|
}
|
|
142
175
|
// array
|
|
143
|
-
if (schema.type === 'array' && schema.items)
|
|
176
|
+
if (schema.type === 'array' && schema.items) {
|
|
177
|
+
if (schema.minItems && schema.maxItems) {
|
|
178
|
+
const minItemsSchema = (0, generate_zod_min_1.generateZodMin)(schema.minItems);
|
|
179
|
+
const maxItemsSchema = (0, generate_zod_max_1.generateZodMax)(schema.maxItems);
|
|
180
|
+
const zodArray = (0, generate_zod_array_1.generateZodArray)(generateZodSchema(config, schema.items, undefined, undefined));
|
|
181
|
+
const res = `${zodArray}${minItemsSchema}${maxItemsSchema}`;
|
|
182
|
+
return res;
|
|
183
|
+
}
|
|
184
|
+
if (schema.minItems) {
|
|
185
|
+
const minItemsSchema = (0, generate_zod_min_1.generateZodMin)(schema.minItems);
|
|
186
|
+
const zodArray = (0, generate_zod_array_1.generateZodArray)(generateZodSchema(config, schema.items, undefined, undefined));
|
|
187
|
+
const res = `${zodArray}${minItemsSchema}`;
|
|
188
|
+
return res;
|
|
189
|
+
}
|
|
190
|
+
if (schema.maxItems) {
|
|
191
|
+
const maxItemsSchema = (0, generate_zod_max_1.generateZodMax)(schema.maxItems);
|
|
192
|
+
const zodArray = (0, generate_zod_array_1.generateZodArray)(generateZodSchema(config, schema.items, undefined, undefined));
|
|
193
|
+
const res = `${zodArray}${maxItemsSchema}`;
|
|
194
|
+
return res;
|
|
195
|
+
}
|
|
144
196
|
return (0, generate_zod_array_1.generateZodArray)(generateZodSchema(config, schema.items, undefined, undefined));
|
|
197
|
+
}
|
|
145
198
|
if (schema.allOf) {
|
|
146
199
|
return (0, generate_allof_code_1.generateAllOfCode)(schema, config);
|
|
147
200
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -129,6 +129,10 @@ export type Schema = {
|
|
|
129
129
|
maxLength?: number;
|
|
130
130
|
minimum?: number;
|
|
131
131
|
maximum?: number;
|
|
132
|
+
exclusiveMinimum?: boolean;
|
|
133
|
+
exclusiveMaximum?: boolean;
|
|
134
|
+
minItems?: number;
|
|
135
|
+
maxItems?: number;
|
|
132
136
|
default?: DefaultValue;
|
|
133
137
|
example?: ExampleValue;
|
|
134
138
|
properties?: Record<string, Schema>;
|
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.4.
|
|
4
|
+
"version": "0.4.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hono",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
+
"takibis": "pnpm build && tsx index.ts",
|
|
37
38
|
"dev": "vite --host",
|
|
38
39
|
"deps": "rm -rf node_modules && pnpm install",
|
|
39
40
|
"build": "tsc",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@hono/zod-openapi": "^0.18.3",
|
|
51
52
|
"@types/node": "^22.10.2",
|
|
52
53
|
"@vitest/coverage-v8": "^2.1.8",
|
|
54
|
+
"tsx": "^4.7.1",
|
|
53
55
|
"typescript": "^5.7.2",
|
|
54
56
|
"vite": "^6.1.0",
|
|
55
57
|
"vitest": "^2.1.8"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { DefaultValue, ExampleValue } from '../../types';
|
|
2
|
-
type GenerateZodNumberSchemaParams = {
|
|
3
|
-
pattern?: string;
|
|
4
|
-
minLength?: number;
|
|
5
|
-
maxLength?: number;
|
|
6
|
-
minimum?: number;
|
|
7
|
-
maximum?: number;
|
|
8
|
-
default?: DefaultValue;
|
|
9
|
-
example?: ExampleValue;
|
|
10
|
-
paramName?: string;
|
|
11
|
-
isPath?: boolean;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Generates a zod schema for a number.
|
|
15
|
-
*
|
|
16
|
-
* @function generateZodNumberSchema
|
|
17
|
-
* @param args - The parameters to generate the zod schema.
|
|
18
|
-
* @returns A zod schema for a number.
|
|
19
|
-
*/
|
|
20
|
-
export declare function generateZodNumberSchema(args: GenerateZodNumberSchemaParams): string;
|
|
21
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateZodNumberSchema = generateZodNumberSchema;
|
|
4
|
-
const generate_zod_default_1 = require("./generate-zod-default");
|
|
5
|
-
const generate_zod_max_1 = require("./generate-zod-max");
|
|
6
|
-
const generate_zod_min_1 = require("./generate-zod-min");
|
|
7
|
-
const generate_zod_regex_1 = require("./generate-zod-regex");
|
|
8
|
-
const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
|
|
9
|
-
/**
|
|
10
|
-
* Generates a zod schema for a number.
|
|
11
|
-
*
|
|
12
|
-
* @function generateZodNumberSchema
|
|
13
|
-
* @param args - The parameters to generate the zod schema.
|
|
14
|
-
* @returns A zod schema for a number.
|
|
15
|
-
*/
|
|
16
|
-
function generateZodNumberSchema(args) {
|
|
17
|
-
const validations = ['z.number()'];
|
|
18
|
-
// pattern
|
|
19
|
-
if (args.pattern)
|
|
20
|
-
validations.push((0, generate_zod_regex_1.generateZodRegex)(args.pattern));
|
|
21
|
-
// minLength
|
|
22
|
-
if (args.minLength)
|
|
23
|
-
validations.push((0, generate_zod_min_1.generateZodMin)(args.minLength));
|
|
24
|
-
// maxLength
|
|
25
|
-
if (args.maxLength)
|
|
26
|
-
validations.push((0, generate_zod_max_1.generateZodMax)(args.maxLength));
|
|
27
|
-
// 0 falsy value
|
|
28
|
-
// minimum
|
|
29
|
-
if (typeof args.minimum === 'number')
|
|
30
|
-
validations.push((0, generate_zod_min_1.generateZodMin)(args.minimum));
|
|
31
|
-
// maximum
|
|
32
|
-
if (typeof args.maximum === 'number')
|
|
33
|
-
validations.push((0, generate_zod_max_1.generateZodMax)(args.maximum));
|
|
34
|
-
// default
|
|
35
|
-
if (args.default)
|
|
36
|
-
validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
|
|
37
|
-
// example
|
|
38
|
-
if (args.example)
|
|
39
|
-
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example, args.paramName, args.isPath));
|
|
40
|
-
return validations.join('');
|
|
41
|
-
}
|