hono-takibi 0.1.1 → 0.1.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.
- package/dist/generators/request/params/generate-params-object.js +3 -8
- package/dist/generators/zod/generate-zod-coerce.d.ts +1 -5
- package/dist/generators/zod/generate-zod-coerce.js +4 -12
- package/dist/generators/zod/generate-zod-default.d.ts +2 -0
- package/dist/generators/zod/generate-zod-default.js +6 -0
- package/dist/generators/zod/generate-zod-integer-schema.d.ts +3 -1
- package/dist/generators/zod/generate-zod-integer-schema.js +21 -6
- package/dist/generators/zod/generate-zod-max.d.ts +7 -0
- package/dist/generators/zod/generate-zod-max.js +12 -0
- package/dist/generators/zod/generate-zod-min.d.ts +7 -0
- package/dist/generators/zod/generate-zod-min.js +12 -0
- package/dist/generators/zod/generate-zod-number-schema.d.ts +2 -1
- package/dist/generators/zod/generate-zod-number-schema.js +19 -6
- package/dist/generators/zod/generate-zod-openapi-example.d.ts +2 -13
- package/dist/generators/zod/generate-zod-openapi-example.js +1 -17
- package/dist/generators/zod/generate-zod-property-schema.js +2 -8
- package/dist/generators/zod/generate-zod-regex.d.ts +7 -0
- package/dist/generators/zod/generate-zod-regex.js +12 -0
- package/dist/generators/zod/generate-zod-schema.js +9 -2
- package/dist/generators/zod/generate-zod-string-schema.d.ts +2 -1
- package/dist/generators/zod/generate-zod-string-schema.js +17 -5
- package/dist/generators/zod/generate-zod-to-openapi.d.ts +9 -0
- package/dist/generators/zod/generate-zod-to-openapi.js +13 -0
- package/package.json +1 -1
- package/dist/core/text/remove-zod-optional.d.ts +0 -8
- package/dist/core/text/remove-zod-optional.js +0 -13
- package/dist/core/validator/is-optional.d.ts +0 -8
- package/dist/core/validator/is-optional.js +0 -13
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateParamsObject = generateParamsObject;
|
|
4
4
|
const generate_zod_coerce_1 = require("../../zod/generate-zod-coerce");
|
|
5
|
-
const generate_zod_openapi_example_1 = require("../../zod/generate-zod-openapi-example");
|
|
6
5
|
const generate_zod_schema_1 = require("../../zod/generate-zod-schema");
|
|
7
6
|
/**
|
|
8
7
|
* Mapping of parameter locations to their corresponding object keys
|
|
@@ -85,13 +84,9 @@ function generateParamsObject(parameters) {
|
|
|
85
84
|
const optionalSuffix = param.required ? '' : '.optional()';
|
|
86
85
|
const paramLocation = PARAM_LOCATION_TO_KEY[param.in];
|
|
87
86
|
const baseSchema = (0, generate_zod_schema_1.generateZodSchema)(param.schema);
|
|
88
|
-
const isCoerceNeeded =
|
|
89
|
-
param.schema.type === 'integer';
|
|
90
|
-
const zodSchema = isCoerceNeeded
|
|
91
|
-
? (0, generate_zod_coerce_1.generateZodCoerce)('z.string()', baseSchema, param.schema.example)
|
|
92
|
-
: param.schema.example
|
|
93
|
-
? (0, generate_zod_openapi_example_1.generateZodOpenAPIExample)(baseSchema, param.schema.example)
|
|
94
|
-
: baseSchema;
|
|
87
|
+
const isCoerceNeeded = paramLocation === 'query' &&
|
|
88
|
+
(param.schema.type === 'number' || param.schema.type === 'integer');
|
|
89
|
+
const zodSchema = isCoerceNeeded ? (0, generate_zod_coerce_1.generateZodCoerce)('z.string()', baseSchema) : baseSchema;
|
|
95
90
|
acc[paramLocation][param.name] = `${zodSchema}${optionalSuffix}`;
|
|
96
91
|
return acc;
|
|
97
92
|
}, initialParamsObj);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ExampleValue } from '../../types';
|
|
2
1
|
/**
|
|
3
2
|
* @description
|
|
4
3
|
* Generates a zod pipe function to coerce a value to a zod schema.
|
|
@@ -8,7 +7,4 @@ import type { ExampleValue } from '../../types';
|
|
|
8
7
|
* @param zodSchema - The zod schema to coerce.
|
|
9
8
|
* @returns A zod pipe function to coerce a value to a zod schema.
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
* Generates a Zod coercion schema using pipe with example support
|
|
13
|
-
*/
|
|
14
|
-
export declare function generateZodCoerce(inputSchema: string, outputSchema: string, example?: ExampleValue): string;
|
|
10
|
+
export declare function generateZodCoerce(z: string, zodSchema: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateZodCoerce = generateZodCoerce;
|
|
4
|
-
const
|
|
4
|
+
const remove_zod_prefix_1 = require("../../core/text/remove-zod-prefix");
|
|
5
5
|
/**
|
|
6
6
|
* @description
|
|
7
7
|
* Generates a zod pipe function to coerce a value to a zod schema.
|
|
@@ -11,15 +11,7 @@ const generate_zod_openapi_example_1 = require("./generate-zod-openapi-example")
|
|
|
11
11
|
* @param zodSchema - The zod schema to coerce.
|
|
12
12
|
* @returns A zod pipe function to coerce a value to a zod schema.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// }
|
|
18
|
-
/**
|
|
19
|
-
* Generates a Zod coercion schema using pipe with example support
|
|
20
|
-
*/
|
|
21
|
-
function generateZodCoerce(inputSchema, outputSchema, example) {
|
|
22
|
-
const coerceSchema = outputSchema.replace('z.', 'z.coerce.');
|
|
23
|
-
const finalSchema = example ? (0, generate_zod_openapi_example_1.generateZodOpenAPIExample)(coerceSchema, example) : coerceSchema;
|
|
24
|
-
return `${inputSchema}.pipe(${finalSchema})`;
|
|
14
|
+
function generateZodCoerce(z, zodSchema) {
|
|
15
|
+
const zod = (0, remove_zod_prefix_1.removeZodPrefix)(zodSchema);
|
|
16
|
+
return `${z}.pipe(z.coerce.${zod})`;
|
|
25
17
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { DefaultValue } from '../../types';
|
|
1
|
+
import type { DefaultValue, ExampleValue } from '../../types';
|
|
2
2
|
type GenerateZodIntegerSchemaParams = {
|
|
3
|
+
pattern?: string;
|
|
3
4
|
minLength?: number;
|
|
4
5
|
maxLength?: number;
|
|
5
6
|
minimum?: number;
|
|
6
7
|
maximum?: number;
|
|
7
8
|
default?: DefaultValue;
|
|
9
|
+
example?: ExampleValue;
|
|
8
10
|
};
|
|
9
11
|
/**
|
|
10
12
|
* Generates a zod schema for an integer.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateZodIntegerSchema = generateZodIntegerSchema;
|
|
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("./generate-zod-to-openapi");
|
|
4
9
|
/**
|
|
5
10
|
* Generates a zod schema for an integer.
|
|
6
11
|
*
|
|
@@ -10,18 +15,28 @@ exports.generateZodIntegerSchema = generateZodIntegerSchema;
|
|
|
10
15
|
*/
|
|
11
16
|
function generateZodIntegerSchema(args) {
|
|
12
17
|
const validations = ['z.number().int()'];
|
|
13
|
-
const { minLength, maxLength, minimum, maximum } = args;
|
|
18
|
+
const { pattern, minLength, maxLength, minimum, maximum } = args;
|
|
19
|
+
// pattern
|
|
20
|
+
if (pattern)
|
|
21
|
+
validations.push((0, generate_zod_regex_1.generateZodRegex)(pattern));
|
|
22
|
+
// minLength
|
|
14
23
|
if (minLength)
|
|
15
|
-
validations.push(
|
|
24
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(minLength));
|
|
25
|
+
// maxLength
|
|
16
26
|
if (maxLength)
|
|
17
|
-
validations.push(
|
|
27
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(maxLength));
|
|
18
28
|
// 0 falsy value
|
|
29
|
+
// minimum
|
|
19
30
|
if (typeof minimum === 'number')
|
|
20
|
-
validations.push(
|
|
31
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(minimum));
|
|
32
|
+
// maximum
|
|
21
33
|
if (typeof maximum === 'number')
|
|
22
|
-
validations.push(
|
|
34
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(maximum));
|
|
23
35
|
// default
|
|
24
36
|
if (args.default)
|
|
25
|
-
validations.push(
|
|
37
|
+
validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
|
|
38
|
+
// example
|
|
39
|
+
if (args.example)
|
|
40
|
+
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example));
|
|
26
41
|
return validations.join('');
|
|
27
42
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodMax = generateZodMax;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod max validation
|
|
6
|
+
*
|
|
7
|
+
* @param max - Maximum value
|
|
8
|
+
* @returns Zod max validation string
|
|
9
|
+
*/
|
|
10
|
+
function generateZodMax(max) {
|
|
11
|
+
return `.max(${max})`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodMin = generateZodMin;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod min validation
|
|
6
|
+
*
|
|
7
|
+
* @param min - Minimum value
|
|
8
|
+
* @returns Zod min validation string
|
|
9
|
+
*/
|
|
10
|
+
function generateZodMin(min) {
|
|
11
|
+
return `.min(${min})`;
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DefaultValue } from '../../types';
|
|
1
|
+
import type { DefaultValue, ExampleValue } from '../../types';
|
|
2
2
|
type GenerateZodNumberSchemaParams = {
|
|
3
3
|
pattern?: string;
|
|
4
4
|
minLength?: number;
|
|
@@ -6,6 +6,7 @@ type GenerateZodNumberSchemaParams = {
|
|
|
6
6
|
minimum?: number;
|
|
7
7
|
maximum?: number;
|
|
8
8
|
default?: DefaultValue;
|
|
9
|
+
example?: ExampleValue;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Generates a zod schema for a number.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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("./generate-zod-to-openapi");
|
|
4
9
|
/**
|
|
5
10
|
* Generates a zod schema for a number.
|
|
6
11
|
*
|
|
@@ -11,19 +16,27 @@ exports.generateZodNumberSchema = generateZodNumberSchema;
|
|
|
11
16
|
function generateZodNumberSchema(args) {
|
|
12
17
|
const validations = ['z.number()'];
|
|
13
18
|
const { pattern, minLength, maxLength, minimum, maximum } = args;
|
|
19
|
+
// pattern
|
|
14
20
|
if (pattern)
|
|
15
|
-
validations.push(
|
|
21
|
+
validations.push((0, generate_zod_regex_1.generateZodRegex)(pattern));
|
|
22
|
+
// minLength
|
|
16
23
|
if (minLength)
|
|
17
|
-
validations.push(
|
|
24
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(minLength));
|
|
25
|
+
// maxLength
|
|
18
26
|
if (maxLength)
|
|
19
|
-
validations.push(
|
|
27
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(maxLength));
|
|
20
28
|
// 0 falsy value
|
|
29
|
+
// minimum
|
|
21
30
|
if (typeof minimum === 'number')
|
|
22
|
-
validations.push(
|
|
31
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(minimum));
|
|
32
|
+
// maximum
|
|
23
33
|
if (typeof maximum === 'number')
|
|
24
|
-
validations.push(
|
|
34
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(maximum));
|
|
25
35
|
// default
|
|
26
36
|
if (args.default)
|
|
27
|
-
validations.push(
|
|
37
|
+
validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
|
|
38
|
+
// example
|
|
39
|
+
if (args.example)
|
|
40
|
+
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example));
|
|
28
41
|
return validations.join('');
|
|
29
42
|
}
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @function generateZodOpenAPIExample
|
|
5
|
-
* @param schema - Original Zod schema string
|
|
6
|
-
* @param example - Example value to be added
|
|
7
|
-
* @returns Generated Zod schema string with OpenAPI example
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* generateZodOpenAPIExample('z.string().optional()', 'test@example.com')
|
|
11
|
-
* // Returns: 'z.string().optional().openapi({example:"test@example.com"})'
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateZodOpenAPIExample(schema: string, example: unknown): string;
|
|
1
|
+
import type { ExampleValue } from '../../types';
|
|
2
|
+
export declare function generateZodOpenAPIExample(schema: string, example: ExampleValue): string;
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateZodOpenAPIExample = generateZodOpenAPIExample;
|
|
4
|
-
const remove_zod_optional_1 = require("../../core/text/remove-zod-optional");
|
|
5
|
-
const is_optional_1 = require("../../core/validator/is-optional");
|
|
6
|
-
/**
|
|
7
|
-
* Generates a Zod schema string with OpenAPI example while preserving optional status
|
|
8
|
-
*
|
|
9
|
-
* @function generateZodOpenAPIExample
|
|
10
|
-
* @param schema - Original Zod schema string
|
|
11
|
-
* @param example - Example value to be added
|
|
12
|
-
* @returns Generated Zod schema string with OpenAPI example
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* generateZodOpenAPIExample('z.string().optional()', 'test@example.com')
|
|
16
|
-
* // Returns: 'z.string().optional().openapi({example:"test@example.com"})'
|
|
17
|
-
*/
|
|
18
4
|
function generateZodOpenAPIExample(schema, example) {
|
|
19
|
-
|
|
20
|
-
const schemaWithoutOptional = (0, remove_zod_optional_1.removeZodOptional)(schema);
|
|
21
|
-
return `${schemaWithoutOptional}${hasOptional ? '.optional()' : ''}.openapi({example:${JSON.stringify(example)}})`;
|
|
5
|
+
return `${schema}.openapi({example:${JSON.stringify(example)}})`;
|
|
22
6
|
}
|
|
@@ -5,7 +5,7 @@ const get_ref_name_1 = require("../../core/schema/references/get-ref-name");
|
|
|
5
5
|
const generate_zod_array_1 = require("./generate-zod-array");
|
|
6
6
|
const generate_zod_schema_1 = require("./generate-zod-schema");
|
|
7
7
|
const get_camel_case_schema_name_1 = require("../../core/schema/references/get-camel-case-schema-name");
|
|
8
|
-
|
|
8
|
+
// import { generateZodOpenAPIExample } from './generate-zod-openapi-example'
|
|
9
9
|
/**
|
|
10
10
|
* Generates a Zod schema string for a given OpenAPI schema definition
|
|
11
11
|
*
|
|
@@ -44,11 +44,5 @@ function generatePropertySchema(schema) {
|
|
|
44
44
|
return (0, generate_zod_array_1.generateZodArray)(camelCaseRefName);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
const { example } = schema;
|
|
49
|
-
// add example
|
|
50
|
-
if (example) {
|
|
51
|
-
return (0, generate_zod_openapi_example_1.generateZodOpenAPIExample)(zodSchema, example);
|
|
52
|
-
}
|
|
53
|
-
return zodSchema;
|
|
47
|
+
return (0, generate_zod_schema_1.generateZodSchema)(schema);
|
|
54
48
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodRegex = generateZodRegex;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Zod regex validation
|
|
6
|
+
*
|
|
7
|
+
* @param pattern - Regex pattern
|
|
8
|
+
* @returns Zod regex validation string
|
|
9
|
+
*/
|
|
10
|
+
function generateZodRegex(pattern) {
|
|
11
|
+
return `.regex(/${pattern}/)`;
|
|
12
|
+
}
|
|
@@ -88,10 +88,14 @@ const TYPE_TO_ZOD_SCHEMA = {
|
|
|
88
88
|
*/
|
|
89
89
|
function generateZodSchema(schema) {
|
|
90
90
|
const { type, format, pattern, minLength, maxLength, minimum, maximum, default: defaultValue, // reserved word
|
|
91
|
-
properties, required = [], items, enum: enumValues, additionalProperties, } = schema;
|
|
91
|
+
example, properties, required = [], items, enum: enumValues, additionalProperties, } = schema;
|
|
92
92
|
// enum
|
|
93
|
-
if (enumValues)
|
|
93
|
+
if (enumValues) {
|
|
94
|
+
if (example) {
|
|
95
|
+
return `z.enum(${JSON.stringify(enumValues)}).openapi({example:${JSON.stringify(example)}})`;
|
|
96
|
+
}
|
|
94
97
|
return `z.enum(${JSON.stringify(enumValues)})`;
|
|
98
|
+
}
|
|
95
99
|
// object
|
|
96
100
|
if (type === 'object') {
|
|
97
101
|
if (additionalProperties)
|
|
@@ -108,6 +112,7 @@ function generateZodSchema(schema) {
|
|
|
108
112
|
maxLength,
|
|
109
113
|
format: format && (0, is_format_string_1.isFormatString)(format) ? format : undefined,
|
|
110
114
|
default: defaultValue,
|
|
115
|
+
example,
|
|
111
116
|
});
|
|
112
117
|
}
|
|
113
118
|
// number
|
|
@@ -119,6 +124,7 @@ function generateZodSchema(schema) {
|
|
|
119
124
|
minimum,
|
|
120
125
|
maximum,
|
|
121
126
|
default: defaultValue,
|
|
127
|
+
example,
|
|
122
128
|
});
|
|
123
129
|
}
|
|
124
130
|
// integer
|
|
@@ -129,6 +135,7 @@ function generateZodSchema(schema) {
|
|
|
129
135
|
minimum,
|
|
130
136
|
maximum,
|
|
131
137
|
default: defaultValue,
|
|
138
|
+
example,
|
|
132
139
|
});
|
|
133
140
|
}
|
|
134
141
|
// array
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { FormatString, DefaultValue } from '../../types';
|
|
1
|
+
import type { FormatString, ExampleValue, DefaultValue } from '../../types';
|
|
2
2
|
type GenerateZodStringSchemaParams = {
|
|
3
3
|
pattern?: string;
|
|
4
4
|
minLength?: number;
|
|
5
5
|
maxLength?: number;
|
|
6
6
|
format?: FormatString;
|
|
7
7
|
default?: DefaultValue;
|
|
8
|
+
example?: ExampleValue;
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
10
11
|
* Generates a Zod schema string for string validation
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateZodStringSchema = generateZodStringSchema;
|
|
4
4
|
const get_zod_string_format_1 = require("../../core/zod/get-zod-string-format");
|
|
5
|
+
const generate_zod_default_1 = require("./generate-zod-default");
|
|
6
|
+
const generate_zod_max_1 = require("./generate-zod-max");
|
|
7
|
+
const generate_zod_min_1 = require("./generate-zod-min");
|
|
8
|
+
const generate_zod_regex_1 = require("./generate-zod-regex");
|
|
9
|
+
const generate_zod_to_openapi_1 = require("./generate-zod-to-openapi");
|
|
5
10
|
/**
|
|
6
11
|
* Generates a Zod schema string for string validation
|
|
7
12
|
*
|
|
@@ -41,17 +46,24 @@ const get_zod_string_format_1 = require("../../core/zod/get-zod-string-format");
|
|
|
41
46
|
*/
|
|
42
47
|
function generateZodStringSchema(args) {
|
|
43
48
|
const validations = ['z.string()'];
|
|
44
|
-
const { pattern, minLength, maxLength, format, default: defaultValue } = args;
|
|
49
|
+
const { pattern, minLength, maxLength, format, default: defaultValue, example } = args;
|
|
50
|
+
// pattern
|
|
45
51
|
if (pattern)
|
|
46
|
-
validations.push(
|
|
52
|
+
validations.push((0, generate_zod_regex_1.generateZodRegex)(pattern));
|
|
53
|
+
// minLength
|
|
47
54
|
if (minLength)
|
|
48
|
-
validations.push(
|
|
55
|
+
validations.push((0, generate_zod_min_1.generateZodMin)(minLength));
|
|
56
|
+
// maxLength
|
|
49
57
|
if (maxLength)
|
|
50
|
-
validations.push(
|
|
58
|
+
validations.push((0, generate_zod_max_1.generateZodMax)(maxLength));
|
|
59
|
+
// format
|
|
51
60
|
if (format)
|
|
52
61
|
validations.push((0, get_zod_string_format_1.getZodFormatString)(format));
|
|
53
62
|
// default
|
|
54
63
|
if (defaultValue)
|
|
55
|
-
validations.push(
|
|
64
|
+
validations.push((0, generate_zod_default_1.generateZodDefault)(defaultValue));
|
|
65
|
+
// example
|
|
66
|
+
if (example)
|
|
67
|
+
validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(example));
|
|
56
68
|
return validations.join('');
|
|
57
69
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExampleValue } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Generate OpenAPI example value from Zod example value
|
|
4
|
+
*
|
|
5
|
+
* @function generateZodToOpenAPI
|
|
6
|
+
* @param {ExampleValue} example - The example value to generate OpenAPI example value from
|
|
7
|
+
* @returns {string} The OpenAPI example value
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateZodToOpenAPI(example: ExampleValue): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateZodToOpenAPI = generateZodToOpenAPI;
|
|
4
|
+
/**
|
|
5
|
+
* Generate OpenAPI example value from Zod example value
|
|
6
|
+
*
|
|
7
|
+
* @function generateZodToOpenAPI
|
|
8
|
+
* @param {ExampleValue} example - The example value to generate OpenAPI example value from
|
|
9
|
+
* @returns {string} The OpenAPI example value
|
|
10
|
+
*/
|
|
11
|
+
function generateZodToOpenAPI(example) {
|
|
12
|
+
return `.openapi({example:${JSON.stringify(example)}})`;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes the `.optional()` method from a Zod schema string
|
|
3
|
-
*
|
|
4
|
-
* @function removeZodOptional
|
|
5
|
-
* @param zodSchema - The Zod schema string to remove the `.optional()` method from
|
|
6
|
-
* @returns The Zod schema string with the `.optional()` method removed
|
|
7
|
-
*/
|
|
8
|
-
export declare function removeZodOptional(zodSchema: string): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeZodOptional = removeZodOptional;
|
|
4
|
-
/**
|
|
5
|
-
* Removes the `.optional()` method from a Zod schema string
|
|
6
|
-
*
|
|
7
|
-
* @function removeZodOptional
|
|
8
|
-
* @param zodSchema - The Zod schema string to remove the `.optional()` method from
|
|
9
|
-
* @returns The Zod schema string with the `.optional()` method removed
|
|
10
|
-
*/
|
|
11
|
-
function removeZodOptional(zodSchema) {
|
|
12
|
-
return zodSchema.replace('.optional()', '');
|
|
13
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a Zod schema string contains the `.optional()` method.
|
|
3
|
-
*
|
|
4
|
-
* @function isOptional
|
|
5
|
-
* @param zodSchema - The Zod schema string to check.
|
|
6
|
-
* @returns `true` if the `.optional()` method is present, `false` otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isOptional(zodSchema: string): boolean;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOptional = isOptional;
|
|
4
|
-
/**
|
|
5
|
-
* Checks if a Zod schema string contains the `.optional()` method.
|
|
6
|
-
*
|
|
7
|
-
* @function isOptional
|
|
8
|
-
* @param zodSchema - The Zod schema string to check.
|
|
9
|
-
* @returns `true` if the `.optional()` method is present, `false` otherwise.
|
|
10
|
-
*/
|
|
11
|
-
function isOptional(zodSchema) {
|
|
12
|
-
return zodSchema.includes('.optional()');
|
|
13
|
-
}
|