@composio/json-schema-to-zod 0.1.15 → 0.1.17
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/index.cjs +50 -54
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -32
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -35,10 +35,10 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/parsers/parse-schema.ts
|
|
38
|
-
var z16 = __toESM(require("zod"), 1);
|
|
38
|
+
var z16 = __toESM(require("zod/v3"), 1);
|
|
39
39
|
|
|
40
40
|
// src/parsers/parse-all-of.ts
|
|
41
|
-
var
|
|
41
|
+
var import_v3 = require("zod/v3");
|
|
42
42
|
|
|
43
43
|
// src/utils/half.ts
|
|
44
44
|
var half = (arr) => {
|
|
@@ -63,7 +63,7 @@ var ensureOriginalIndex = (arr) => {
|
|
|
63
63
|
};
|
|
64
64
|
function parseAllOf(jsonSchema, refs) {
|
|
65
65
|
if (jsonSchema.allOf.length === 0) {
|
|
66
|
-
return
|
|
66
|
+
return import_v3.z.never();
|
|
67
67
|
}
|
|
68
68
|
if (jsonSchema.allOf.length === 1) {
|
|
69
69
|
const item = jsonSchema.allOf[0];
|
|
@@ -73,24 +73,24 @@ function parseAllOf(jsonSchema, refs) {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
const [left, right] = half(ensureOriginalIndex(jsonSchema.allOf));
|
|
76
|
-
return
|
|
76
|
+
return import_v3.z.intersection(parseAllOf({ allOf: left }, refs), parseAllOf({ allOf: right }, refs));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// src/parsers/parse-any-of.ts
|
|
80
|
-
var
|
|
80
|
+
var import_v32 = require("zod/v3");
|
|
81
81
|
var parseAnyOf = (jsonSchema, refs) => {
|
|
82
82
|
return jsonSchema.anyOf.length ? jsonSchema.anyOf.length === 1 ? parseSchema(jsonSchema.anyOf[0], {
|
|
83
83
|
...refs,
|
|
84
84
|
path: [...refs.path, "anyOf", 0]
|
|
85
|
-
}) :
|
|
85
|
+
}) : import_v32.z.union(
|
|
86
86
|
jsonSchema.anyOf.map(
|
|
87
87
|
(schema, i) => parseSchema(schema, { ...refs, path: [...refs.path, "anyOf", i] })
|
|
88
88
|
)
|
|
89
|
-
) :
|
|
89
|
+
) : import_v32.z.any();
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
// src/parsers/parse-array.ts
|
|
93
|
-
var
|
|
93
|
+
var import_v33 = require("zod/v3");
|
|
94
94
|
|
|
95
95
|
// src/utils/extend-schema.ts
|
|
96
96
|
function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
|
|
@@ -105,7 +105,7 @@ function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
|
|
|
105
105
|
// src/utils/its.ts
|
|
106
106
|
var its = {
|
|
107
107
|
an: {
|
|
108
|
-
object: (x) => x.type === "object",
|
|
108
|
+
object: (x) => x.type === "object" || !x.type && (x.properties !== void 0 || x.additionalProperties !== void 0 || x.patternProperties !== void 0),
|
|
109
109
|
array: (x) => x.type === "array",
|
|
110
110
|
anyOf: (x) => x.anyOf !== void 0,
|
|
111
111
|
allOf: (x) => x.allOf !== void 0,
|
|
@@ -158,13 +158,13 @@ var parseArray = (jsonSchema, refs) => {
|
|
|
158
158
|
return parseSchema(newSchema, refs);
|
|
159
159
|
}
|
|
160
160
|
if (Array.isArray(jsonSchema.items)) {
|
|
161
|
-
return
|
|
161
|
+
return import_v33.z.tuple(
|
|
162
162
|
jsonSchema.items.map(
|
|
163
163
|
(v, i) => parseSchema(v, { ...refs, path: [...refs.path, "items", i] })
|
|
164
164
|
)
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
|
-
let zodSchema = !jsonSchema.items ?
|
|
167
|
+
let zodSchema = !jsonSchema.items ? import_v33.z.array(import_v33.z.any()) : import_v33.z.array(parseSchema(jsonSchema.items, { ...refs, path: [...refs.path, "items"] }));
|
|
168
168
|
zodSchema = extendSchemaWithMessage(
|
|
169
169
|
zodSchema,
|
|
170
170
|
jsonSchema,
|
|
@@ -197,42 +197,42 @@ var parseArray = (jsonSchema, refs) => {
|
|
|
197
197
|
};
|
|
198
198
|
|
|
199
199
|
// src/parsers/parse-boolean.ts
|
|
200
|
-
var
|
|
200
|
+
var import_v34 = require("zod/v3");
|
|
201
201
|
var parseBoolean = (_jsonSchema) => {
|
|
202
|
-
return
|
|
202
|
+
return import_v34.z.boolean();
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
// src/parsers/parse-const.ts
|
|
206
|
-
var
|
|
206
|
+
var import_v35 = require("zod/v3");
|
|
207
207
|
var parseConst = (jsonSchema) => {
|
|
208
|
-
return
|
|
208
|
+
return import_v35.z.literal(jsonSchema.const);
|
|
209
209
|
};
|
|
210
210
|
|
|
211
211
|
// src/parsers/parse-default.ts
|
|
212
|
-
var
|
|
212
|
+
var import_v36 = require("zod/v3");
|
|
213
213
|
var parseDefault = (_jsonSchema) => {
|
|
214
|
-
return
|
|
214
|
+
return import_v36.z.any();
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
// src/parsers/parse-enum.ts
|
|
218
|
-
var
|
|
218
|
+
var import_v37 = require("zod/v3");
|
|
219
219
|
var parseEnum = (jsonSchema) => {
|
|
220
220
|
if (jsonSchema.enum.length === 0) {
|
|
221
|
-
return
|
|
221
|
+
return import_v37.z.never();
|
|
222
222
|
}
|
|
223
223
|
if (jsonSchema.enum.length === 1) {
|
|
224
|
-
return
|
|
224
|
+
return import_v37.z.literal(jsonSchema.enum[0]);
|
|
225
225
|
}
|
|
226
226
|
if (jsonSchema.enum.every((x) => typeof x === "string")) {
|
|
227
|
-
return
|
|
227
|
+
return import_v37.z.enum(jsonSchema.enum);
|
|
228
228
|
}
|
|
229
|
-
return
|
|
230
|
-
jsonSchema.enum.map((x) =>
|
|
229
|
+
return import_v37.z.union(
|
|
230
|
+
jsonSchema.enum.map((x) => import_v37.z.literal(x))
|
|
231
231
|
);
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
// src/parsers/parse-if-then-else.ts
|
|
235
|
-
var
|
|
235
|
+
var import_v38 = require("zod/v3");
|
|
236
236
|
var parseIfThenElse = (jsonSchema, refs) => {
|
|
237
237
|
const $if = parseSchema(jsonSchema.if, { ...refs, path: [...refs.path, "if"] });
|
|
238
238
|
const $then = parseSchema(jsonSchema.then, {
|
|
@@ -243,7 +243,7 @@ var parseIfThenElse = (jsonSchema, refs) => {
|
|
|
243
243
|
...refs,
|
|
244
244
|
path: [...refs.path, "else"]
|
|
245
245
|
});
|
|
246
|
-
return
|
|
246
|
+
return import_v38.z.union([$then, $else]).superRefine((value, ctx) => {
|
|
247
247
|
const result = $if.safeParse(value).success ? $then.safeParse(value) : $else.safeParse(value);
|
|
248
248
|
if (!result.success) {
|
|
249
249
|
result.error.errors.forEach((error) => ctx.addIssue(error));
|
|
@@ -252,17 +252,17 @@ var parseIfThenElse = (jsonSchema, refs) => {
|
|
|
252
252
|
};
|
|
253
253
|
|
|
254
254
|
// src/parsers/parse-multiple-type.ts
|
|
255
|
-
var
|
|
255
|
+
var import_v39 = require("zod/v3");
|
|
256
256
|
var parseMultipleType = (jsonSchema, refs) => {
|
|
257
|
-
return
|
|
257
|
+
return import_v39.z.union(
|
|
258
258
|
jsonSchema.type.map((type) => parseSchema({ ...jsonSchema, type }, refs))
|
|
259
259
|
);
|
|
260
260
|
};
|
|
261
261
|
|
|
262
262
|
// src/parsers/parse-not.ts
|
|
263
|
-
var
|
|
263
|
+
var import_v310 = require("zod/v3");
|
|
264
264
|
var parseNot = (jsonSchema, refs) => {
|
|
265
|
-
return
|
|
265
|
+
return import_v310.z.any().refine(
|
|
266
266
|
(value) => !parseSchema(jsonSchema.not, {
|
|
267
267
|
...refs,
|
|
268
268
|
path: [...refs.path, "not"]
|
|
@@ -272,9 +272,9 @@ var parseNot = (jsonSchema, refs) => {
|
|
|
272
272
|
};
|
|
273
273
|
|
|
274
274
|
// src/parsers/parse-null.ts
|
|
275
|
-
var
|
|
275
|
+
var import_v311 = require("zod/v3");
|
|
276
276
|
var parseNull = (_jsonSchema) => {
|
|
277
|
-
return
|
|
277
|
+
return import_v311.z.null();
|
|
278
278
|
};
|
|
279
279
|
|
|
280
280
|
// src/utils/omit.ts
|
|
@@ -294,9 +294,9 @@ var parseNullable = (jsonSchema, refs) => {
|
|
|
294
294
|
};
|
|
295
295
|
|
|
296
296
|
// src/parsers/parse-number.ts
|
|
297
|
-
var
|
|
297
|
+
var import_v312 = require("zod/v3");
|
|
298
298
|
var parseNumber = (jsonSchema) => {
|
|
299
|
-
let zodSchema =
|
|
299
|
+
let zodSchema = import_v312.z.number();
|
|
300
300
|
let isInteger = false;
|
|
301
301
|
if (jsonSchema.type === "integer") {
|
|
302
302
|
isInteger = true;
|
|
@@ -395,13 +395,13 @@ var parseNumber = (jsonSchema) => {
|
|
|
395
395
|
};
|
|
396
396
|
|
|
397
397
|
// src/parsers/parse-object.ts
|
|
398
|
-
var z14 = __toESM(require("zod"), 1);
|
|
398
|
+
var z14 = __toESM(require("zod/v3"), 1);
|
|
399
399
|
|
|
400
400
|
// src/parsers/parse-one-of.ts
|
|
401
|
-
var
|
|
401
|
+
var import_v313 = require("zod/v3");
|
|
402
402
|
var parseOneOf = (jsonSchema, refs) => {
|
|
403
403
|
if (!jsonSchema.oneOf.length) {
|
|
404
|
-
return
|
|
404
|
+
return import_v313.z.any();
|
|
405
405
|
}
|
|
406
406
|
if (jsonSchema.oneOf.length === 1) {
|
|
407
407
|
return parseSchema(jsonSchema.oneOf[0], {
|
|
@@ -409,7 +409,7 @@ var parseOneOf = (jsonSchema, refs) => {
|
|
|
409
409
|
path: [...refs.path, "oneOf", 0]
|
|
410
410
|
});
|
|
411
411
|
}
|
|
412
|
-
return
|
|
412
|
+
return import_v313.z.any().superRefine((x, ctx) => {
|
|
413
413
|
const schemas = jsonSchema.oneOf.map(
|
|
414
414
|
(schema, i) => parseSchema(schema, {
|
|
415
415
|
...refs,
|
|
@@ -434,7 +434,7 @@ var parseOneOf = (jsonSchema, refs) => {
|
|
|
434
434
|
// src/parsers/parse-object.ts
|
|
435
435
|
function parseObjectProperties(objectSchema, refs) {
|
|
436
436
|
if (!objectSchema.properties) {
|
|
437
|
-
return
|
|
437
|
+
return z14.object({});
|
|
438
438
|
}
|
|
439
439
|
const propertyKeys = Object.keys(objectSchema.properties);
|
|
440
440
|
if (propertyKeys.length === 0) {
|
|
@@ -473,16 +473,17 @@ function parseObjectProperties(objectSchema, refs) {
|
|
|
473
473
|
}
|
|
474
474
|
function parseObject(objectSchema, refs) {
|
|
475
475
|
const hasPatternProperties = Object.keys(objectSchema.patternProperties ?? {}).length > 0;
|
|
476
|
-
const
|
|
476
|
+
const normalizedSchema = objectSchema.type === "object" ? objectSchema : { ...objectSchema, type: "object" };
|
|
477
|
+
const propertiesSchema = parseObjectProperties(normalizedSchema, refs);
|
|
477
478
|
let zodSchema = propertiesSchema;
|
|
478
|
-
const additionalProperties =
|
|
479
|
+
const additionalProperties = normalizedSchema.additionalProperties !== void 0 ? parseSchema(normalizedSchema.additionalProperties, {
|
|
479
480
|
...refs,
|
|
480
481
|
path: [...refs.path, "additionalProperties"]
|
|
481
482
|
}) : void 0;
|
|
482
|
-
const isAdditionalPropertiesTrue =
|
|
483
|
-
if (
|
|
483
|
+
const isAdditionalPropertiesTrue = normalizedSchema.additionalProperties === true;
|
|
484
|
+
if (normalizedSchema.patternProperties) {
|
|
484
485
|
const parsedPatternProperties = Object.fromEntries(
|
|
485
|
-
Object.entries(
|
|
486
|
+
Object.entries(normalizedSchema.patternProperties).map(([key, value]) => {
|
|
486
487
|
return [
|
|
487
488
|
key,
|
|
488
489
|
parseSchema(value, {
|
|
@@ -516,11 +517,11 @@ function parseObject(objectSchema, refs) {
|
|
|
516
517
|
zodSchema = z14.record(patternPropertyValues[0]);
|
|
517
518
|
}
|
|
518
519
|
}
|
|
519
|
-
const objectPropertyKeys = new Set(Object.keys(
|
|
520
|
+
const objectPropertyKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));
|
|
520
521
|
zodSchema = zodSchema.superRefine((value, ctx) => {
|
|
521
522
|
for (const key in value) {
|
|
522
523
|
let wasMatched = objectPropertyKeys.has(key);
|
|
523
|
-
for (const patternPropertyKey in
|
|
524
|
+
for (const patternPropertyKey in normalizedSchema.patternProperties) {
|
|
524
525
|
const regex = new RegExp(patternPropertyKey);
|
|
525
526
|
if (key.match(regex)) {
|
|
526
527
|
wasMatched = true;
|
|
@@ -563,15 +564,10 @@ function parseObject(objectSchema, refs) {
|
|
|
563
564
|
} else if (isAdditionalPropertiesTrue) {
|
|
564
565
|
output = propertiesSchema.passthrough();
|
|
565
566
|
} else {
|
|
566
|
-
|
|
567
|
-
if (isEmptyObject) {
|
|
568
|
-
output = propertiesSchema.passthrough();
|
|
569
|
-
} else {
|
|
570
|
-
output = propertiesSchema.catchall(additionalProperties);
|
|
571
|
-
}
|
|
567
|
+
output = propertiesSchema.catchall(additionalProperties);
|
|
572
568
|
}
|
|
573
569
|
} else {
|
|
574
|
-
output = propertiesSchema.
|
|
570
|
+
output = propertiesSchema.strict();
|
|
575
571
|
}
|
|
576
572
|
} else {
|
|
577
573
|
if (hasPatternProperties) {
|
|
@@ -631,9 +627,9 @@ function parseObject(objectSchema, refs) {
|
|
|
631
627
|
}
|
|
632
628
|
|
|
633
629
|
// src/parsers/parse-string.ts
|
|
634
|
-
var
|
|
630
|
+
var import_v314 = require("zod/v3");
|
|
635
631
|
var parseString = (jsonSchema) => {
|
|
636
|
-
let zodSchema =
|
|
632
|
+
let zodSchema = import_v314.z.string();
|
|
637
633
|
zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, "format", (zs, format, errorMsg) => {
|
|
638
634
|
switch (format) {
|
|
639
635
|
case "email":
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/parsers/parse-schema.ts
|
|
2
|
-
import * as z16 from "zod";
|
|
2
|
+
import * as z16 from "zod/v3";
|
|
3
3
|
|
|
4
4
|
// src/parsers/parse-all-of.ts
|
|
5
|
-
import { z } from "zod";
|
|
5
|
+
import { z } from "zod/v3";
|
|
6
6
|
|
|
7
7
|
// src/utils/half.ts
|
|
8
8
|
var half = (arr) => {
|
|
@@ -41,7 +41,7 @@ function parseAllOf(jsonSchema, refs) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// src/parsers/parse-any-of.ts
|
|
44
|
-
import { z as z2 } from "zod";
|
|
44
|
+
import { z as z2 } from "zod/v3";
|
|
45
45
|
var parseAnyOf = (jsonSchema, refs) => {
|
|
46
46
|
return jsonSchema.anyOf.length ? jsonSchema.anyOf.length === 1 ? parseSchema(jsonSchema.anyOf[0], {
|
|
47
47
|
...refs,
|
|
@@ -54,7 +54,7 @@ var parseAnyOf = (jsonSchema, refs) => {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
// src/parsers/parse-array.ts
|
|
57
|
-
import { z as z3 } from "zod";
|
|
57
|
+
import { z as z3 } from "zod/v3";
|
|
58
58
|
|
|
59
59
|
// src/utils/extend-schema.ts
|
|
60
60
|
function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
|
|
@@ -69,7 +69,7 @@ function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
|
|
|
69
69
|
// src/utils/its.ts
|
|
70
70
|
var its = {
|
|
71
71
|
an: {
|
|
72
|
-
object: (x) => x.type === "object",
|
|
72
|
+
object: (x) => x.type === "object" || !x.type && (x.properties !== void 0 || x.additionalProperties !== void 0 || x.patternProperties !== void 0),
|
|
73
73
|
array: (x) => x.type === "array",
|
|
74
74
|
anyOf: (x) => x.anyOf !== void 0,
|
|
75
75
|
allOf: (x) => x.allOf !== void 0,
|
|
@@ -161,25 +161,25 @@ var parseArray = (jsonSchema, refs) => {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
// src/parsers/parse-boolean.ts
|
|
164
|
-
import { z as z4 } from "zod";
|
|
164
|
+
import { z as z4 } from "zod/v3";
|
|
165
165
|
var parseBoolean = (_jsonSchema) => {
|
|
166
166
|
return z4.boolean();
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
// src/parsers/parse-const.ts
|
|
170
|
-
import { z as z5 } from "zod";
|
|
170
|
+
import { z as z5 } from "zod/v3";
|
|
171
171
|
var parseConst = (jsonSchema) => {
|
|
172
172
|
return z5.literal(jsonSchema.const);
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
// src/parsers/parse-default.ts
|
|
176
|
-
import { z as z6 } from "zod";
|
|
176
|
+
import { z as z6 } from "zod/v3";
|
|
177
177
|
var parseDefault = (_jsonSchema) => {
|
|
178
178
|
return z6.any();
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
// src/parsers/parse-enum.ts
|
|
182
|
-
import { z as z7 } from "zod";
|
|
182
|
+
import { z as z7 } from "zod/v3";
|
|
183
183
|
var parseEnum = (jsonSchema) => {
|
|
184
184
|
if (jsonSchema.enum.length === 0) {
|
|
185
185
|
return z7.never();
|
|
@@ -196,7 +196,7 @@ var parseEnum = (jsonSchema) => {
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
// src/parsers/parse-if-then-else.ts
|
|
199
|
-
import { z as z8 } from "zod";
|
|
199
|
+
import { z as z8 } from "zod/v3";
|
|
200
200
|
var parseIfThenElse = (jsonSchema, refs) => {
|
|
201
201
|
const $if = parseSchema(jsonSchema.if, { ...refs, path: [...refs.path, "if"] });
|
|
202
202
|
const $then = parseSchema(jsonSchema.then, {
|
|
@@ -216,7 +216,7 @@ var parseIfThenElse = (jsonSchema, refs) => {
|
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
// src/parsers/parse-multiple-type.ts
|
|
219
|
-
import { z as z9 } from "zod";
|
|
219
|
+
import { z as z9 } from "zod/v3";
|
|
220
220
|
var parseMultipleType = (jsonSchema, refs) => {
|
|
221
221
|
return z9.union(
|
|
222
222
|
jsonSchema.type.map((type) => parseSchema({ ...jsonSchema, type }, refs))
|
|
@@ -224,7 +224,7 @@ var parseMultipleType = (jsonSchema, refs) => {
|
|
|
224
224
|
};
|
|
225
225
|
|
|
226
226
|
// src/parsers/parse-not.ts
|
|
227
|
-
import { z as z10 } from "zod";
|
|
227
|
+
import { z as z10 } from "zod/v3";
|
|
228
228
|
var parseNot = (jsonSchema, refs) => {
|
|
229
229
|
return z10.any().refine(
|
|
230
230
|
(value) => !parseSchema(jsonSchema.not, {
|
|
@@ -236,7 +236,7 @@ var parseNot = (jsonSchema, refs) => {
|
|
|
236
236
|
};
|
|
237
237
|
|
|
238
238
|
// src/parsers/parse-null.ts
|
|
239
|
-
import { z as z11 } from "zod";
|
|
239
|
+
import { z as z11 } from "zod/v3";
|
|
240
240
|
var parseNull = (_jsonSchema) => {
|
|
241
241
|
return z11.null();
|
|
242
242
|
};
|
|
@@ -258,7 +258,7 @@ var parseNullable = (jsonSchema, refs) => {
|
|
|
258
258
|
};
|
|
259
259
|
|
|
260
260
|
// src/parsers/parse-number.ts
|
|
261
|
-
import { z as z12 } from "zod";
|
|
261
|
+
import { z as z12 } from "zod/v3";
|
|
262
262
|
var parseNumber = (jsonSchema) => {
|
|
263
263
|
let zodSchema = z12.number();
|
|
264
264
|
let isInteger = false;
|
|
@@ -359,10 +359,10 @@ var parseNumber = (jsonSchema) => {
|
|
|
359
359
|
};
|
|
360
360
|
|
|
361
361
|
// src/parsers/parse-object.ts
|
|
362
|
-
import * as z14 from "zod";
|
|
362
|
+
import * as z14 from "zod/v3";
|
|
363
363
|
|
|
364
364
|
// src/parsers/parse-one-of.ts
|
|
365
|
-
import { z as z13 } from "zod";
|
|
365
|
+
import { z as z13 } from "zod/v3";
|
|
366
366
|
var parseOneOf = (jsonSchema, refs) => {
|
|
367
367
|
if (!jsonSchema.oneOf.length) {
|
|
368
368
|
return z13.any();
|
|
@@ -398,7 +398,7 @@ var parseOneOf = (jsonSchema, refs) => {
|
|
|
398
398
|
// src/parsers/parse-object.ts
|
|
399
399
|
function parseObjectProperties(objectSchema, refs) {
|
|
400
400
|
if (!objectSchema.properties) {
|
|
401
|
-
return
|
|
401
|
+
return z14.object({});
|
|
402
402
|
}
|
|
403
403
|
const propertyKeys = Object.keys(objectSchema.properties);
|
|
404
404
|
if (propertyKeys.length === 0) {
|
|
@@ -437,16 +437,17 @@ function parseObjectProperties(objectSchema, refs) {
|
|
|
437
437
|
}
|
|
438
438
|
function parseObject(objectSchema, refs) {
|
|
439
439
|
const hasPatternProperties = Object.keys(objectSchema.patternProperties ?? {}).length > 0;
|
|
440
|
-
const
|
|
440
|
+
const normalizedSchema = objectSchema.type === "object" ? objectSchema : { ...objectSchema, type: "object" };
|
|
441
|
+
const propertiesSchema = parseObjectProperties(normalizedSchema, refs);
|
|
441
442
|
let zodSchema = propertiesSchema;
|
|
442
|
-
const additionalProperties =
|
|
443
|
+
const additionalProperties = normalizedSchema.additionalProperties !== void 0 ? parseSchema(normalizedSchema.additionalProperties, {
|
|
443
444
|
...refs,
|
|
444
445
|
path: [...refs.path, "additionalProperties"]
|
|
445
446
|
}) : void 0;
|
|
446
|
-
const isAdditionalPropertiesTrue =
|
|
447
|
-
if (
|
|
447
|
+
const isAdditionalPropertiesTrue = normalizedSchema.additionalProperties === true;
|
|
448
|
+
if (normalizedSchema.patternProperties) {
|
|
448
449
|
const parsedPatternProperties = Object.fromEntries(
|
|
449
|
-
Object.entries(
|
|
450
|
+
Object.entries(normalizedSchema.patternProperties).map(([key, value]) => {
|
|
450
451
|
return [
|
|
451
452
|
key,
|
|
452
453
|
parseSchema(value, {
|
|
@@ -480,11 +481,11 @@ function parseObject(objectSchema, refs) {
|
|
|
480
481
|
zodSchema = z14.record(patternPropertyValues[0]);
|
|
481
482
|
}
|
|
482
483
|
}
|
|
483
|
-
const objectPropertyKeys = new Set(Object.keys(
|
|
484
|
+
const objectPropertyKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));
|
|
484
485
|
zodSchema = zodSchema.superRefine((value, ctx) => {
|
|
485
486
|
for (const key in value) {
|
|
486
487
|
let wasMatched = objectPropertyKeys.has(key);
|
|
487
|
-
for (const patternPropertyKey in
|
|
488
|
+
for (const patternPropertyKey in normalizedSchema.patternProperties) {
|
|
488
489
|
const regex = new RegExp(patternPropertyKey);
|
|
489
490
|
if (key.match(regex)) {
|
|
490
491
|
wasMatched = true;
|
|
@@ -527,15 +528,10 @@ function parseObject(objectSchema, refs) {
|
|
|
527
528
|
} else if (isAdditionalPropertiesTrue) {
|
|
528
529
|
output = propertiesSchema.passthrough();
|
|
529
530
|
} else {
|
|
530
|
-
|
|
531
|
-
if (isEmptyObject) {
|
|
532
|
-
output = propertiesSchema.passthrough();
|
|
533
|
-
} else {
|
|
534
|
-
output = propertiesSchema.catchall(additionalProperties);
|
|
535
|
-
}
|
|
531
|
+
output = propertiesSchema.catchall(additionalProperties);
|
|
536
532
|
}
|
|
537
533
|
} else {
|
|
538
|
-
output = propertiesSchema.
|
|
534
|
+
output = propertiesSchema.strict();
|
|
539
535
|
}
|
|
540
536
|
} else {
|
|
541
537
|
if (hasPatternProperties) {
|
|
@@ -595,7 +591,7 @@ function parseObject(objectSchema, refs) {
|
|
|
595
591
|
}
|
|
596
592
|
|
|
597
593
|
// src/parsers/parse-string.ts
|
|
598
|
-
import { z as z15 } from "zod";
|
|
594
|
+
import { z as z15 } from "zod/v3";
|
|
599
595
|
var parseString = (jsonSchema) => {
|
|
600
596
|
let zodSchema = z15.string();
|
|
601
597
|
zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, "format", (zs, format, errorMsg) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/json-schema-to-zod",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,15 +22,16 @@
|
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/json-schema": "^7.0.15",
|
|
25
26
|
"@types/node": "^24.0.1",
|
|
26
|
-
"tsup": "^8.
|
|
27
|
-
"typescript": "^5.
|
|
28
|
-
"vitest": "^3.
|
|
29
|
-
"zod-to-json-schema": "^3.24.5"
|
|
27
|
+
"tsup": "^8.5.0",
|
|
28
|
+
"typescript": "^5.9.2",
|
|
29
|
+
"vitest": "^3.2.4",
|
|
30
|
+
"zod-to-json-schema": "^3.24.5",
|
|
31
|
+
"zod": "3.25.76"
|
|
30
32
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"zod": "^3.24.2"
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"zod": ">=3.25.76 <5"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
37
|
"clean": "git clean -xdf node_modules",
|