json-schema-to-zod
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "json-schema-to-zod", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Converts JSON schema objects or files into Zod schemas", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,5 +11,5 @@ "use strict"; | ||
: `z.array(${(0, parseSchema_1.parseSchema)(schema.items)})`; | ||
if (schema.minItems !== undefined) | ||
if (typeof schema.minItems === "number") | ||
r += `.min(${schema.minItems})`; | ||
if (schema.maxItems !== undefined) | ||
if (typeof schema.maxItems === "number") | ||
r += `.max(${schema.maxItems})`; | ||
@@ -16,0 +16,0 @@ return r; |
@@ -11,6 +11,6 @@ "use strict"; | ||
} | ||
if (schema.multipleOf !== undefined && schema.multipleOf !== 1) { | ||
if (typeof schema.multipleOf === "number" && schema.multipleOf !== 1) { | ||
r += `.multipleOf(${schema.multipleOf})`; | ||
} | ||
if (schema.minimum !== undefined) { | ||
if (typeof schema.minimum === "number") { | ||
if (schema.exclusiveMinimum === true) { | ||
@@ -23,7 +23,6 @@ r += `.gt({${schema.minimum}})`; | ||
} | ||
else if (schema.exclusiveMinimum !== undefined && | ||
schema.exclusiveMinimum !== false) { | ||
else if (typeof schema.exclusiveMinimum === "number") { | ||
r += `.gt(${schema.exclusiveMinimum})`; | ||
} | ||
if (schema.maximum !== undefined) { | ||
if (typeof schema.maximum === "number") { | ||
if (schema.exclusiveMaximum === true) { | ||
@@ -36,4 +35,3 @@ r += `.lt({${schema.maximum}})`; | ||
} | ||
else if (schema.exclusiveMaximum !== undefined && | ||
schema.exclusiveMaximum !== false) { | ||
else if (typeof schema.exclusiveMaximum === "number") { | ||
r += `.lt(${schema.exclusiveMaximum})`; | ||
@@ -40,0 +38,0 @@ } |
@@ -8,2 +8,3 @@ "use strict"; | ||
const parseObject = (schema) => { | ||
var _a; | ||
return !schema.properties | ||
@@ -13,5 +14,5 @@ ? typeof schema.additionalProperties === "object" | ||
: "z.object({}).catchall(z.any())" | ||
: `z.object({${Object.entries(schema === null || schema === void 0 ? void 0 : schema.properties).map(([k, v]) => { | ||
: `z.object({${Object.entries((_a = schema === null || schema === void 0 ? void 0 : schema.properties) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => { | ||
var _a; | ||
return `'${k}':${(0, parseSchema_1.parseSchema)(v)}${((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(k)) ? requiredFlag : ".optional()"}`; | ||
return `${JSON.stringify(k)}:${(0, parseSchema_1.parseSchema)(v)}${((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(k)) ? requiredFlag : ".optional()"}`; | ||
})}})${schema.additionalProperties === true | ||
@@ -18,0 +19,0 @@ ? ".catchall(z.any())" |
@@ -29,3 +29,3 @@ "use strict"; | ||
if (schema.description) | ||
parsed += `.describe("${schema.description}")`; | ||
parsed += `.describe(${JSON.stringify(schema.description)})`; | ||
return parsed; | ||
@@ -32,0 +32,0 @@ }; |
@@ -7,3 +7,3 @@ "use strict"; | ||
if (schema.pattern) | ||
r += `.regex(new RegExp("${schema.pattern}"))`; | ||
r += `.regex(new RegExp(${JSON.stringify(schema.pattern)}))`; | ||
if (schema.format === "email") | ||
@@ -15,5 +15,5 @@ r += ".email()"; | ||
r += ".uuid()"; | ||
if (schema.minLength !== undefined) | ||
if (typeof schema.minLength === "number") | ||
r += `.min(${schema.minLength})`; | ||
if (schema.maxLength !== undefined) | ||
if (typeof schema.maxLength === "number") | ||
r += `.max(${schema.maxLength})`; | ||
@@ -20,0 +20,0 @@ return r; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23432
0
562