zod-to-json-schema
Advanced tools
Comparing version 3.17.0 to 3.17.1
@@ -5,2 +5,3 @@ # Changelog | ||
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 3.17.1 | Added startsWith and endsWith string checks. Merge multiple pattern checks into allOf array. | ||
| 3.17.0 | Added switch case handler for new trim "check". No changes to functionality. | ||
@@ -7,0 +8,0 @@ | 3.15.x - 3.16.x | Skipped: Did not change the Zod API in any way relevant for this package. | |
import { zodToJsonSchema } from "./src/zodToJsonSchema"; | ||
export default zodToJsonSchema; | ||
export { zodToJsonSchema }; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "zod-to-json-schema", | ||
"version": "3.17.0", | ||
"version": "3.17.1", | ||
"description": "Converts Zod schemas to Json Schemas", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"peerDependencies": { | ||
"zod": "^3.14.4" | ||
"zod": "^3.17.10" | ||
}, | ||
@@ -45,5 +45,5 @@ "devDependencies": { | ||
"typescript": "^4.4.3", | ||
"zod": "^3.17.0" | ||
"zod": "^3.17.10" | ||
}, | ||
"types": "index.d.ts" | ||
} |
@@ -0,0 +0,0 @@ # Zod to Json Schema |
@@ -0,0 +0,0 @@ import { ZodTypeDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare type JsonSchema7AnyType = {}; | ||
export declare function parseAnyDef(): JsonSchema7AnyType; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodArrayDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type JsonSchema7BigintType = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type JsonSchema7BooleanType = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type JsonSchema7DateType = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodDefaultDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodEffectsDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodEnumDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodIntersectionDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodLiteralDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodMapDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodNativeEnumDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type JsonSchema7NeverType = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { References } from "../References"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodNullableDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodNumberDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodObjectDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodOptionalDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodPromiseDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodRecordDef, ZodTypeAny } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodSetDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -8,3 +8,6 @@ import { ZodStringDef } from "zod"; | ||
pattern?: string; | ||
allOf?: { | ||
pattern: string; | ||
}[]; | ||
}; | ||
export declare function parseStringDef(def: ZodStringDef): JsonSchema7StringType; |
@@ -12,6 +12,12 @@ "use strict"; | ||
case "min": | ||
res.minLength = check.value; | ||
res.minLength = | ||
typeof res.minLength === "number" | ||
? Math.max(res.minLength, check.value) | ||
: check.value; | ||
break; | ||
case "max": | ||
res.maxLength = check.value; | ||
res.maxLength = | ||
typeof res.maxLength === "number" | ||
? Math.min(res.maxLength, check.value) | ||
: check.value; | ||
break; | ||
@@ -28,7 +34,13 @@ case "email": | ||
case "regex": | ||
res.pattern = check.regex.source; | ||
addPattern(res, check.regex.source); | ||
break; | ||
case "cuid": | ||
res.pattern = "^c[^\\s-]{8,}$"; | ||
addPattern(res, "^c[^\\s-]{8,}$"); | ||
break; | ||
case "startsWith": | ||
addPattern(res, "^" + escapeNonAlphaNumeric(check.value)); | ||
break; | ||
case "endsWith": | ||
addPattern(res, escapeNonAlphaNumeric(check.value) + "$"); | ||
break; | ||
case "trim": | ||
@@ -45,1 +57,20 @@ // I have no idea why this is a check in Zod. It's a runtime string manipulation method. | ||
exports.parseStringDef = parseStringDef; | ||
const escapeNonAlphaNumeric = (value) => Array.from(value) | ||
.map((c) => (/[a-zA-Z0-9]/.test(c) ? c : `\\${c}`)) | ||
.join(""); | ||
const addPattern = (schema, value) => { | ||
var _a; | ||
if (schema.pattern || ((_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.some((x) => x.pattern))) { | ||
if (!schema.allOf) { | ||
schema.allOf = []; | ||
} | ||
if (schema.pattern) { | ||
schema.allOf.push({ pattern: schema.pattern }); | ||
delete schema.pattern; | ||
} | ||
schema.allOf.push({ pattern: value }); | ||
} | ||
else { | ||
schema.pattern = value; | ||
} | ||
}; |
@@ -0,0 +0,0 @@ import { ZodTupleDef, ZodTupleItems, ZodTypeAny } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type JsonSchema7UndefinedType = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodDiscriminatedUnionDef, ZodUnionDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare type JsonSchema7UnknownType = {}; | ||
export declare function parseUnknownDef(): JsonSchema7UnknownType; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodTypeDef } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ZodSchema } from "zod"; |
@@ -0,0 +0,0 @@ "use strict"; |
Sorry, the diff of this file is not supported yet
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
1108
66951
64