@gabrielbryk/json-schema-to-zod 2.8.0 → 2.9.0
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/CHANGELOG.md +13 -0
- package/dist/cjs/core/analyzeSchema.js +62 -0
- package/dist/cjs/core/emitZod.js +141 -0
- package/dist/cjs/generators/generateBundle.js +103 -59
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/jsonSchemaToZod.js +5 -167
- package/dist/cjs/parsers/parseSchema.js +124 -24
- package/dist/cjs/utils/buildRefRegistry.js +56 -0
- package/dist/cjs/utils/resolveUri.js +16 -0
- package/dist/esm/Types.js +1 -2
- package/dist/esm/cli.js +10 -12
- package/dist/esm/core/analyzeSchema.js +58 -0
- package/dist/esm/core/emitZod.js +137 -0
- package/dist/esm/generators/generateBundle.js +104 -64
- package/dist/esm/index.js +34 -46
- package/dist/esm/jsonSchemaToZod.js +5 -171
- package/dist/esm/parsers/parseAllOf.js +5 -8
- package/dist/esm/parsers/parseAnyOf.js +6 -10
- package/dist/esm/parsers/parseArray.js +11 -15
- package/dist/esm/parsers/parseBoolean.js +1 -5
- package/dist/esm/parsers/parseConst.js +1 -5
- package/dist/esm/parsers/parseDefault.js +3 -7
- package/dist/esm/parsers/parseEnum.js +1 -5
- package/dist/esm/parsers/parseIfThenElse.js +5 -9
- package/dist/esm/parsers/parseMultipleType.js +3 -7
- package/dist/esm/parsers/parseNot.js +4 -8
- package/dist/esm/parsers/parseNull.js +1 -5
- package/dist/esm/parsers/parseNullable.js +4 -8
- package/dist/esm/parsers/parseNumber.js +11 -15
- package/dist/esm/parsers/parseObject.js +25 -28
- package/dist/esm/parsers/parseOneOf.js +6 -10
- package/dist/esm/parsers/parseSchema.js +183 -87
- package/dist/esm/parsers/parseSimpleDiscriminatedOneOf.js +6 -10
- package/dist/esm/parsers/parseString.js +11 -15
- package/dist/esm/utils/anyOrUnknown.js +1 -5
- package/dist/esm/utils/buildRefRegistry.js +52 -0
- package/dist/esm/utils/cliTools.js +7 -13
- package/dist/esm/utils/cycles.js +3 -9
- package/dist/esm/utils/half.js +1 -5
- package/dist/esm/utils/jsdocs.js +3 -8
- package/dist/esm/utils/omit.js +1 -5
- package/dist/esm/utils/resolveUri.js +12 -0
- package/dist/esm/utils/withMessage.js +1 -4
- package/dist/esm/zodToJsonSchema.js +1 -4
- package/dist/types/Types.d.ts +28 -0
- package/dist/types/core/analyzeSchema.d.ts +24 -0
- package/dist/types/core/emitZod.d.ts +2 -0
- package/dist/types/generators/generateBundle.d.ts +5 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/jsonSchemaToZod.d.ts +1 -1
- package/dist/types/parsers/parseSchema.d.ts +2 -1
- package/dist/types/utils/buildRefRegistry.d.ts +12 -0
- package/dist/types/utils/resolveUri.d.ts +1 -0
- package/docs/proposals/bundle-refactor.md +43 -0
- package/docs/proposals/ref-anchor-support.md +65 -0
- package/eslint.config.js +26 -0
- package/package.json +10 -4
- /package/{jest.config.js → jest.config.cjs} +0 -0
- /package/{postcjs.js → postcjs.cjs} +0 -0
- /package/{postesm.js → postesm.cjs} +0 -0
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const anyOrUnknown_js_1 = require("../utils/anyOrUnknown.js");
|
|
5
|
-
const parseDefault = (_schema, refs) => {
|
|
6
|
-
return (0, anyOrUnknown_js_1.anyOrUnknown)(refs);
|
|
1
|
+
import { anyOrUnknown } from "../utils/anyOrUnknown.js";
|
|
2
|
+
export const parseDefault = (_schema, refs) => {
|
|
3
|
+
return anyOrUnknown(refs);
|
|
7
4
|
};
|
|
8
|
-
exports.parseDefault = parseDefault;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseEnum = void 0;
|
|
4
|
-
const parseEnum = (schema) => {
|
|
1
|
+
export const parseEnum = (schema) => {
|
|
5
2
|
if (schema.enum.length === 0) {
|
|
6
3
|
return "z.never()";
|
|
7
4
|
}
|
|
@@ -18,4 +15,3 @@ const parseEnum = (schema) => {
|
|
|
18
15
|
.join(", ")}])`;
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
exports.parseEnum = parseEnum;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const parseIfThenElse = (schema, refs) => {
|
|
6
|
-
const $if = (0, parseSchema_js_1.parseSchema)(schema.if, { ...refs, path: [...refs.path, "if"] });
|
|
7
|
-
const $then = (0, parseSchema_js_1.parseSchema)(schema.then, {
|
|
1
|
+
import { parseSchema } from "./parseSchema.js";
|
|
2
|
+
export const parseIfThenElse = (schema, refs) => {
|
|
3
|
+
const $if = parseSchema(schema.if, { ...refs, path: [...refs.path, "if"] });
|
|
4
|
+
const $then = parseSchema(schema.then, {
|
|
8
5
|
...refs,
|
|
9
6
|
path: [...refs.path, "then"],
|
|
10
7
|
});
|
|
11
|
-
const $else =
|
|
8
|
+
const $else = parseSchema(schema.else, {
|
|
12
9
|
...refs,
|
|
13
10
|
path: [...refs.path, "else"],
|
|
14
11
|
});
|
|
@@ -32,4 +29,3 @@ const parseIfThenElse = (schema, refs) => {
|
|
|
32
29
|
}
|
|
33
30
|
return result;
|
|
34
31
|
};
|
|
35
|
-
exports.parseIfThenElse = parseIfThenElse;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseMultipleType = void 0;
|
|
4
|
-
const parseSchema_js_1 = require("./parseSchema.js");
|
|
5
|
-
const parseMultipleType = (schema, refs) => {
|
|
1
|
+
import { parseSchema } from "./parseSchema.js";
|
|
2
|
+
export const parseMultipleType = (schema, refs) => {
|
|
6
3
|
return `z.union([${schema.type
|
|
7
|
-
.map((type) =>
|
|
4
|
+
.map((type) => parseSchema({ ...schema, type }, { ...refs, withoutDefaults: true }))
|
|
8
5
|
.join(", ")}])`;
|
|
9
6
|
};
|
|
10
|
-
exports.parseMultipleType = parseMultipleType;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const anyOrUnknown_js_1 = require("../utils/anyOrUnknown.js");
|
|
6
|
-
const parseNot = (schema, refs) => {
|
|
7
|
-
return `${(0, anyOrUnknown_js_1.anyOrUnknown)(refs)}.refine((value) => !${(0, parseSchema_js_1.parseSchema)(schema.not, {
|
|
1
|
+
import { parseSchema } from "./parseSchema.js";
|
|
2
|
+
import { anyOrUnknown } from "../utils/anyOrUnknown.js";
|
|
3
|
+
export const parseNot = (schema, refs) => {
|
|
4
|
+
return `${anyOrUnknown(refs)}.refine((value) => !${parseSchema(schema.not, {
|
|
8
5
|
...refs,
|
|
9
6
|
path: [...refs.path, "not"],
|
|
10
7
|
})}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
|
|
11
8
|
};
|
|
12
|
-
exports.parseNot = parseNot;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseNullable = void 0;
|
|
4
|
-
const omit_js_1 = require("../utils/omit.js");
|
|
5
|
-
const parseSchema_js_1 = require("./parseSchema.js");
|
|
1
|
+
import { omit } from "../utils/omit.js";
|
|
2
|
+
import { parseSchema } from "./parseSchema.js";
|
|
6
3
|
/**
|
|
7
4
|
* For compatibility with open api 3.0 nullable
|
|
8
5
|
*/
|
|
9
|
-
const parseNullable = (schema, refs) => {
|
|
10
|
-
return `${
|
|
6
|
+
export const parseNullable = (schema, refs) => {
|
|
7
|
+
return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
|
|
11
8
|
};
|
|
12
|
-
exports.parseNullable = parseNullable;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseNumber = void 0;
|
|
4
|
-
const withMessage_js_1 = require("../utils/withMessage.js");
|
|
5
|
-
const parseNumber = (schema) => {
|
|
1
|
+
import { withMessage } from "../utils/withMessage.js";
|
|
2
|
+
export const parseNumber = (schema) => {
|
|
6
3
|
const formatError = schema.errorMessage?.format;
|
|
7
4
|
const numericFormatMap = {
|
|
8
5
|
int32: "z.int32",
|
|
@@ -18,7 +15,7 @@ const parseNumber = (schema) => {
|
|
|
18
15
|
let r = mappedFormat ? `${mappedFormat}(${formatParams})` : "z.number()";
|
|
19
16
|
if (schema.type === "integer") {
|
|
20
17
|
if (!mappedFormat) {
|
|
21
|
-
r +=
|
|
18
|
+
r += withMessage(schema, "type", () => ({
|
|
22
19
|
opener: ".int(",
|
|
23
20
|
closer: ")",
|
|
24
21
|
messagePrefix: "{ error: ",
|
|
@@ -28,7 +25,7 @@ const parseNumber = (schema) => {
|
|
|
28
25
|
}
|
|
29
26
|
else {
|
|
30
27
|
if (!mappedFormat) {
|
|
31
|
-
r +=
|
|
28
|
+
r += withMessage(schema, "format", ({ value }) => {
|
|
32
29
|
if (value === "int64") {
|
|
33
30
|
return {
|
|
34
31
|
opener: ".int(",
|
|
@@ -40,7 +37,7 @@ const parseNumber = (schema) => {
|
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
r +=
|
|
40
|
+
r += withMessage(schema, "multipleOf", ({ value, json }) => {
|
|
44
41
|
if (value === 1) {
|
|
45
42
|
if (r.startsWith("z.number().int(")) {
|
|
46
43
|
return;
|
|
@@ -61,7 +58,7 @@ const parseNumber = (schema) => {
|
|
|
61
58
|
});
|
|
62
59
|
if (typeof schema.minimum === "number") {
|
|
63
60
|
if (schema.exclusiveMinimum === true) {
|
|
64
|
-
r +=
|
|
61
|
+
r += withMessage(schema, "minimum", ({ json }) => ({
|
|
65
62
|
opener: `.gt(${json}`,
|
|
66
63
|
closer: ")",
|
|
67
64
|
messagePrefix: ", { error: ",
|
|
@@ -69,7 +66,7 @@ const parseNumber = (schema) => {
|
|
|
69
66
|
}));
|
|
70
67
|
}
|
|
71
68
|
else {
|
|
72
|
-
r +=
|
|
69
|
+
r += withMessage(schema, "minimum", ({ json }) => ({
|
|
73
70
|
opener: `.gte(${json}`,
|
|
74
71
|
closer: ")",
|
|
75
72
|
messagePrefix: ", { error: ",
|
|
@@ -78,7 +75,7 @@ const parseNumber = (schema) => {
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
else if (typeof schema.exclusiveMinimum === "number") {
|
|
81
|
-
r +=
|
|
78
|
+
r += withMessage(schema, "exclusiveMinimum", ({ json }) => ({
|
|
82
79
|
opener: `.gt(${json}`,
|
|
83
80
|
closer: ")",
|
|
84
81
|
messagePrefix: ", { error: ",
|
|
@@ -87,7 +84,7 @@ const parseNumber = (schema) => {
|
|
|
87
84
|
}
|
|
88
85
|
if (typeof schema.maximum === "number") {
|
|
89
86
|
if (schema.exclusiveMaximum === true) {
|
|
90
|
-
r +=
|
|
87
|
+
r += withMessage(schema, "maximum", ({ json }) => ({
|
|
91
88
|
opener: `.lt(${json}`,
|
|
92
89
|
closer: ")",
|
|
93
90
|
messagePrefix: ", { error: ",
|
|
@@ -95,7 +92,7 @@ const parseNumber = (schema) => {
|
|
|
95
92
|
}));
|
|
96
93
|
}
|
|
97
94
|
else {
|
|
98
|
-
r +=
|
|
95
|
+
r += withMessage(schema, "maximum", ({ json }) => ({
|
|
99
96
|
opener: `.lte(${json}`,
|
|
100
97
|
closer: ")",
|
|
101
98
|
messagePrefix: ", { error: ",
|
|
@@ -104,7 +101,7 @@ const parseNumber = (schema) => {
|
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
else if (typeof schema.exclusiveMaximum === "number") {
|
|
107
|
-
r +=
|
|
104
|
+
r += withMessage(schema, "exclusiveMaximum", ({ json }) => ({
|
|
108
105
|
opener: `.lt(${json}`,
|
|
109
106
|
closer: ")",
|
|
110
107
|
messagePrefix: ", { error: ",
|
|
@@ -113,4 +110,3 @@ const parseNumber = (schema) => {
|
|
|
113
110
|
}
|
|
114
111
|
return r;
|
|
115
112
|
};
|
|
116
|
-
exports.parseNumber = parseNumber;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const jsdocs_js_1 = require("../utils/jsdocs.js");
|
|
10
|
-
const anyOrUnknown_js_1 = require("../utils/anyOrUnknown.js");
|
|
11
|
-
function parseObject(objectSchema, refs) {
|
|
1
|
+
import { parseAnyOf } from "./parseAnyOf.js";
|
|
2
|
+
import { parseOneOf } from "./parseOneOf.js";
|
|
3
|
+
import { its, parseSchema } from "./parseSchema.js";
|
|
4
|
+
import { parseAllOf } from "./parseAllOf.js";
|
|
5
|
+
import { parseIfThenElse } from "./parseIfThenElse.js";
|
|
6
|
+
import { addJsdocs } from "../utils/jsdocs.js";
|
|
7
|
+
import { anyOrUnknown } from "../utils/anyOrUnknown.js";
|
|
8
|
+
export function parseObject(objectSchema, refs) {
|
|
12
9
|
let properties = undefined;
|
|
13
10
|
if (objectSchema.properties) {
|
|
14
11
|
if (!Object.keys(objectSchema.properties).length) {
|
|
@@ -19,7 +16,7 @@ function parseObject(objectSchema, refs) {
|
|
|
19
16
|
properties += Object.keys(objectSchema.properties)
|
|
20
17
|
.map((key) => {
|
|
21
18
|
const propSchema = objectSchema.properties[key];
|
|
22
|
-
const parsedProp =
|
|
19
|
+
const parsedProp = parseSchema(propSchema, {
|
|
23
20
|
...refs,
|
|
24
21
|
path: [...refs.path, "properties", key],
|
|
25
22
|
});
|
|
@@ -35,7 +32,7 @@ function parseObject(objectSchema, refs) {
|
|
|
35
32
|
? `get ${JSON.stringify(key)}(){ return ${valueWithOptional} }`
|
|
36
33
|
: `${JSON.stringify(key)}: ${valueWithOptional}`;
|
|
37
34
|
if (refs.withJsdocs && typeof propSchema === "object") {
|
|
38
|
-
result =
|
|
35
|
+
result = addJsdocs(propSchema, result);
|
|
39
36
|
}
|
|
40
37
|
return result;
|
|
41
38
|
})
|
|
@@ -44,7 +41,7 @@ function parseObject(objectSchema, refs) {
|
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
const additionalProperties = objectSchema.additionalProperties !== undefined
|
|
47
|
-
?
|
|
44
|
+
? parseSchema(objectSchema.additionalProperties, {
|
|
48
45
|
...refs,
|
|
49
46
|
path: [...refs.path, "additionalProperties"],
|
|
50
47
|
})
|
|
@@ -55,7 +52,7 @@ function parseObject(objectSchema, refs) {
|
|
|
55
52
|
const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
|
|
56
53
|
return [
|
|
57
54
|
key,
|
|
58
|
-
|
|
55
|
+
parseSchema(value, {
|
|
59
56
|
...refs,
|
|
60
57
|
path: [...refs.path, "patternProperties", key],
|
|
61
58
|
}),
|
|
@@ -154,7 +151,7 @@ function parseObject(objectSchema, refs) {
|
|
|
154
151
|
// Check if there will be an .and() call that adds properties from oneOf/anyOf/allOf/if-then-else
|
|
155
152
|
// In that case, we should NOT use .strict() because it will reject the additional keys
|
|
156
153
|
// before the union gets a chance to validate them.
|
|
157
|
-
const hasCompositionKeywords =
|
|
154
|
+
const hasCompositionKeywords = its.an.anyOf(objectSchema) || its.a.oneOf(objectSchema) || its.an.allOf(objectSchema) || its.a.conditional(objectSchema);
|
|
158
155
|
let output = properties
|
|
159
156
|
? patternProperties
|
|
160
157
|
? properties + patternProperties
|
|
@@ -170,12 +167,12 @@ function parseObject(objectSchema, refs) {
|
|
|
170
167
|
? patternProperties
|
|
171
168
|
: additionalProperties
|
|
172
169
|
? `z.record(z.string(), ${additionalProperties})`
|
|
173
|
-
: `z.record(z.string(), ${
|
|
170
|
+
: `z.record(z.string(), ${anyOrUnknown(refs)})`;
|
|
174
171
|
if (unevaluated === false && properties && !hasCompositionKeywords) {
|
|
175
172
|
output += ".strict()";
|
|
176
173
|
}
|
|
177
174
|
else if (unevaluated && typeof unevaluated !== 'boolean') {
|
|
178
|
-
const unevaluatedSchema =
|
|
175
|
+
const unevaluatedSchema = parseSchema(unevaluated, {
|
|
179
176
|
...refs,
|
|
180
177
|
path: [...refs.path, "unevaluatedProperties"],
|
|
181
178
|
});
|
|
@@ -196,8 +193,8 @@ function parseObject(objectSchema, refs) {
|
|
|
196
193
|
}
|
|
197
194
|
})`;
|
|
198
195
|
}
|
|
199
|
-
if (
|
|
200
|
-
output += `.and(${
|
|
196
|
+
if (its.an.anyOf(objectSchema)) {
|
|
197
|
+
output += `.and(${parseAnyOf({
|
|
201
198
|
...objectSchema,
|
|
202
199
|
anyOf: objectSchema.anyOf.map((x) => typeof x === "object" &&
|
|
203
200
|
!x.type &&
|
|
@@ -206,8 +203,8 @@ function parseObject(objectSchema, refs) {
|
|
|
206
203
|
: x),
|
|
207
204
|
}, refs)})`;
|
|
208
205
|
}
|
|
209
|
-
if (
|
|
210
|
-
output += `.and(${
|
|
206
|
+
if (its.a.oneOf(objectSchema)) {
|
|
207
|
+
output += `.and(${parseOneOf({
|
|
211
208
|
...objectSchema,
|
|
212
209
|
oneOf: objectSchema.oneOf.map((x) => typeof x === "object" &&
|
|
213
210
|
!x.type &&
|
|
@@ -216,8 +213,8 @@ function parseObject(objectSchema, refs) {
|
|
|
216
213
|
: x),
|
|
217
214
|
}, refs)})`;
|
|
218
215
|
}
|
|
219
|
-
if (
|
|
220
|
-
output += `.and(${
|
|
216
|
+
if (its.an.allOf(objectSchema)) {
|
|
217
|
+
output += `.and(${parseAllOf({
|
|
221
218
|
...objectSchema,
|
|
222
219
|
allOf: objectSchema.allOf.map((x) => typeof x === "object" &&
|
|
223
220
|
!x.type &&
|
|
@@ -227,8 +224,8 @@ function parseObject(objectSchema, refs) {
|
|
|
227
224
|
}, refs)})`;
|
|
228
225
|
}
|
|
229
226
|
// Handle if/then/else conditionals on object schemas
|
|
230
|
-
if (
|
|
231
|
-
output += `.and(${
|
|
227
|
+
if (its.a.conditional(objectSchema)) {
|
|
228
|
+
output += `.and(${parseIfThenElse(objectSchema, refs)})`;
|
|
232
229
|
}
|
|
233
230
|
// propertyNames
|
|
234
231
|
if (objectSchema.propertyNames) {
|
|
@@ -237,7 +234,7 @@ function parseObject(objectSchema, refs) {
|
|
|
237
234
|
objectSchema.propertyNames.pattern
|
|
238
235
|
? { ...objectSchema.propertyNames, type: "string" }
|
|
239
236
|
: objectSchema.propertyNames;
|
|
240
|
-
const propNameSchema =
|
|
237
|
+
const propNameSchema = parseSchema(normalizedPropNames, {
|
|
241
238
|
...refs,
|
|
242
239
|
path: [...refs.path, "propertyNames"],
|
|
243
240
|
});
|
|
@@ -262,7 +259,7 @@ function parseObject(objectSchema, refs) {
|
|
|
262
259
|
output += `.superRefine((obj, ctx) => {
|
|
263
260
|
${entries
|
|
264
261
|
.map(([key, schema], idx) => {
|
|
265
|
-
const parsed =
|
|
262
|
+
const parsed = parseSchema(schema, { ...refs, path: [...refs.path, "dependentSchemas", key] });
|
|
266
263
|
return `if (Object.prototype.hasOwnProperty.call(obj, ${JSON.stringify(key)})) {
|
|
267
264
|
const result = ${parsed}.safeParse(obj);
|
|
268
265
|
if (!result.success) {
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const parseSchema_js_1 = require("./parseSchema.js");
|
|
5
|
-
const anyOrUnknown_js_1 = require("../utils/anyOrUnknown.js");
|
|
6
|
-
const parseOneOf = (schema, refs) => {
|
|
1
|
+
import { parseSchema } from "./parseSchema.js";
|
|
2
|
+
import { anyOrUnknown } from "../utils/anyOrUnknown.js";
|
|
3
|
+
export const parseOneOf = (schema, refs) => {
|
|
7
4
|
if (!schema.oneOf.length) {
|
|
8
|
-
return
|
|
5
|
+
return anyOrUnknown(refs);
|
|
9
6
|
}
|
|
10
7
|
if (schema.oneOf.length === 1) {
|
|
11
|
-
return
|
|
8
|
+
return parseSchema(schema.oneOf[0], {
|
|
12
9
|
...refs,
|
|
13
10
|
path: [...refs.path, "oneOf", 0],
|
|
14
11
|
});
|
|
15
12
|
}
|
|
16
13
|
// Generate parsed schemas for each oneOf option
|
|
17
|
-
const parsedSchemas = schema.oneOf.map((s, i) =>
|
|
14
|
+
const parsedSchemas = schema.oneOf.map((s, i) => parseSchema(s, {
|
|
18
15
|
...refs,
|
|
19
16
|
path: [...refs.path, "oneOf", i],
|
|
20
17
|
}));
|
|
@@ -50,4 +47,3 @@ const parseOneOf = (schema, refs) => {
|
|
|
50
47
|
// Default: use simple z.union() (at least one must match)
|
|
51
48
|
return `z.union([${parsedSchemas.join(", ")}])`;
|
|
52
49
|
};
|
|
53
|
-
exports.parseOneOf = parseOneOf;
|