zod-to-json-schema
Advanced tools
Comparing version 3.20.2 to 3.20.3
@@ -5,2 +5,4 @@ # Changelog | ||
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 3.20.3 | Added Cuid2 support introduced in Zod 3.20.3 | | ||
| 3.20.2 | Reintroduced conditional simplified return-type for when target is OpenAPI 3 | | ||
| 3.20.1 | Fixed inconsistent casing in imports | | ||
@@ -7,0 +9,0 @@ | 3.20.0 | Adds support for Zod 3.20 with catch and pipe parser as well as new string validations. Refactored Ref handling; adding definitions no longer considered experimental. Main API function refactored and simplified; output type less defined but a lot easier to maintain. Doubt anyone will miss it. | |
{ | ||
"name": "zod-to-json-schema", | ||
"version": "3.20.2", | ||
"version": "3.20.3", | ||
"description": "Converts Zod schemas to Json Schemas", | ||
@@ -48,5 +48,5 @@ "main": "index.js", | ||
"typescript": "^4.9.4", | ||
"zod": "^3.20.2" | ||
"zod": "^3.20.6" | ||
}, | ||
"types": "index.d.ts" | ||
} |
@@ -123,3 +123,3 @@ # Zod to Json Schema | ||
const jsonSchema = zodToJsonSchema(EmailSchema, {errorMessages: true}) | ||
const jsonSchema = zodToJsonSchema(EmailSchema, { errorMessages: true }); | ||
``` | ||
@@ -137,3 +137,3 @@ | ||
"format": "Invalid email", | ||
"minLength": "Too short", | ||
"minLength": "Too short" | ||
} | ||
@@ -153,3 +153,3 @@ } | ||
- ZodNumber | ||
- min, max, lt, lte, gt, gte, | ||
- min, max, lt, lte, gt, gte, | ||
- int | ||
@@ -156,0 +156,0 @@ - multipleOf |
@@ -7,8 +7,12 @@ "use strict"; | ||
const actualKeys = Object.keys(def.values).filter((key) => { | ||
return typeof object[object[key]] !== 'number'; | ||
return typeof object[object[key]] !== "number"; | ||
}); | ||
const actualValues = actualKeys.map((key) => object[key]); | ||
const parsedTypes = Array.from(new Set(actualValues.map((values) => (typeof values)))); | ||
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values))); | ||
return { | ||
type: parsedTypes.length === 1 ? parsedTypes[0] === 'string' ? "string" : "number" : ["string", "number"], | ||
type: parsedTypes.length === 1 | ||
? parsedTypes[0] === "string" | ||
? "string" | ||
: "number" | ||
: ["string", "number"], | ||
enum: actualValues, | ||
@@ -15,0 +19,0 @@ }; |
@@ -37,2 +37,5 @@ "use strict"; | ||
break; | ||
case "cuid2": | ||
addPattern(res, "^[a-z][a-z0-9]*$", check.message, refs); | ||
break; | ||
case "startsWith": | ||
@@ -39,0 +42,0 @@ addPattern(res, "^" + escapeNonAlphaNumeric(check.value), check.message, refs); |
@@ -11,3 +11,3 @@ import { ZodDiscriminatedUnionDef, ZodUnionDef } from "zod"; | ||
}; | ||
type JsonSchema7Primitive = typeof primitiveMappings[keyof typeof primitiveMappings]; | ||
type JsonSchema7Primitive = (typeof primitiveMappings)[keyof typeof primitiveMappings]; | ||
export type JsonSchema7UnionType = JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType; | ||
@@ -14,0 +14,0 @@ type JsonSchema7PrimitiveUnionType = { |
@@ -73,3 +73,5 @@ "use strict"; | ||
const asAnyOf = (def, refs) => { | ||
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options) | ||
const anyOf = (def.options instanceof Map | ||
? Array.from(def.options.values()) | ||
: def.options) | ||
.map((x, i) => (0, parseDef_1.parseDef)(x._def, Object.assign(Object.assign({}, refs), { currentPath: [...refs.currentPath, "anyOf", `${i}`] }))) | ||
@@ -76,0 +78,0 @@ .filter((x) => !!x && |
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
81418
1186