@composio/json-schema-to-zod 0.1.10-next.3 → 0.1.10-next.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/index.cjs +15 -5
- package/dist/index.js +15 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -126,7 +126,7 @@ var its = {
|
|
|
126
126
|
var parseArray = (jsonSchema, refs) => {
|
|
127
127
|
if (its.an.anyOf(jsonSchema)) {
|
|
128
128
|
const types = /* @__PURE__ */ new Set();
|
|
129
|
-
|
|
129
|
+
const itemsSchemas = [];
|
|
130
130
|
jsonSchema.anyOf.forEach((option) => {
|
|
131
131
|
if (typeof option === "object" && option.type) {
|
|
132
132
|
types.add(typeof option.type === "string" ? option.type : option.type[0]);
|
|
@@ -134,13 +134,19 @@ var parseArray = (jsonSchema, refs) => {
|
|
|
134
134
|
if (typeof option === "object" && option.items) {
|
|
135
135
|
const optionItems = option.items;
|
|
136
136
|
if (!Array.isArray(optionItems) && typeof optionItems === "object") {
|
|
137
|
-
|
|
137
|
+
itemsSchemas.push(optionItems);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
|
+
let finalItems;
|
|
142
|
+
if (itemsSchemas.length === 1) {
|
|
143
|
+
finalItems = itemsSchemas[0];
|
|
144
|
+
} else if (itemsSchemas.length > 1) {
|
|
145
|
+
finalItems = { anyOf: itemsSchemas };
|
|
146
|
+
}
|
|
141
147
|
const newSchema = {
|
|
142
|
-
type: Array.from(types),
|
|
143
|
-
...
|
|
148
|
+
...types.size > 0 ? { type: Array.from(types) } : { type: "array" },
|
|
149
|
+
...finalItems && { items: finalItems }
|
|
144
150
|
};
|
|
145
151
|
const metadataFields = ["default", "description", "examples", "title"];
|
|
146
152
|
metadataFields.forEach((field) => {
|
|
@@ -408,7 +414,11 @@ function parseObjectProperties(objectSchema, refs) {
|
|
|
408
414
|
});
|
|
409
415
|
const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : false;
|
|
410
416
|
if (!required && propJsonSchema && typeof propJsonSchema === "object" && "default" in propJsonSchema) {
|
|
411
|
-
|
|
417
|
+
if (propJsonSchema.default === null) {
|
|
418
|
+
properties[key] = propZodSchema.nullable().optional().default(null);
|
|
419
|
+
} else {
|
|
420
|
+
properties[key] = propZodSchema.optional().default(propJsonSchema.default);
|
|
421
|
+
}
|
|
412
422
|
} else {
|
|
413
423
|
properties[key] = required ? propZodSchema : propZodSchema.optional();
|
|
414
424
|
}
|
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ var its = {
|
|
|
90
90
|
var parseArray = (jsonSchema, refs) => {
|
|
91
91
|
if (its.an.anyOf(jsonSchema)) {
|
|
92
92
|
const types = /* @__PURE__ */ new Set();
|
|
93
|
-
|
|
93
|
+
const itemsSchemas = [];
|
|
94
94
|
jsonSchema.anyOf.forEach((option) => {
|
|
95
95
|
if (typeof option === "object" && option.type) {
|
|
96
96
|
types.add(typeof option.type === "string" ? option.type : option.type[0]);
|
|
@@ -98,13 +98,19 @@ var parseArray = (jsonSchema, refs) => {
|
|
|
98
98
|
if (typeof option === "object" && option.items) {
|
|
99
99
|
const optionItems = option.items;
|
|
100
100
|
if (!Array.isArray(optionItems) && typeof optionItems === "object") {
|
|
101
|
-
|
|
101
|
+
itemsSchemas.push(optionItems);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
+
let finalItems;
|
|
106
|
+
if (itemsSchemas.length === 1) {
|
|
107
|
+
finalItems = itemsSchemas[0];
|
|
108
|
+
} else if (itemsSchemas.length > 1) {
|
|
109
|
+
finalItems = { anyOf: itemsSchemas };
|
|
110
|
+
}
|
|
105
111
|
const newSchema = {
|
|
106
|
-
type: Array.from(types),
|
|
107
|
-
...
|
|
112
|
+
...types.size > 0 ? { type: Array.from(types) } : { type: "array" },
|
|
113
|
+
...finalItems && { items: finalItems }
|
|
108
114
|
};
|
|
109
115
|
const metadataFields = ["default", "description", "examples", "title"];
|
|
110
116
|
metadataFields.forEach((field) => {
|
|
@@ -372,7 +378,11 @@ function parseObjectProperties(objectSchema, refs) {
|
|
|
372
378
|
});
|
|
373
379
|
const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : false;
|
|
374
380
|
if (!required && propJsonSchema && typeof propJsonSchema === "object" && "default" in propJsonSchema) {
|
|
375
|
-
|
|
381
|
+
if (propJsonSchema.default === null) {
|
|
382
|
+
properties[key] = propZodSchema.nullable().optional().default(null);
|
|
383
|
+
} else {
|
|
384
|
+
properties[key] = propZodSchema.optional().default(propJsonSchema.default);
|
|
385
|
+
}
|
|
376
386
|
} else {
|
|
377
387
|
properties[key] = required ? propZodSchema : propZodSchema.optional();
|
|
378
388
|
}
|