Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zod-to-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-to-json-schema - npm Package Compare versions

Comparing version 3.22.5 to 3.23.0

0

.prettierrc.json
{}

@@ -0,0 +0,0 @@ # Contributing

@@ -0,0 +0,0 @@ import { readdirSync, writeFileSync, statSync } from "fs";

4

dist/cjs/index.js

@@ -17,4 +17,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./Options.js"), exports);
__exportStar(require("./Refs.js"), exports);
__exportStar(require("./errorMessages.js"), exports);
__exportStar(require("./Options.js"), exports);
__exportStar(require("./parseDef.js"), exports);

@@ -51,5 +52,4 @@ __exportStar(require("./parsers/any.js"), exports);

__exportStar(require("./parsers/unknown.js"), exports);
__exportStar(require("./Refs.js"), exports);
__exportStar(require("./zodToJsonSchema.js"), exports);
const zodToJsonSchema_js_1 = require("./zodToJsonSchema.js");
exports.default = zodToJsonSchema_js_1.zodToJsonSchema;

@@ -22,2 +22,3 @@ "use strict";

emailStrategy: "format:email",
base64Strategy: "contentEncoding:base64",
};

@@ -24,0 +25,0 @@ const getDefaultOptions = (options) => (typeof options === "string"

@@ -35,2 +35,4 @@ "use strict";

ipv6: "^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$",
base64: "^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$",
nanoid: "^[a-zA-Z0-9_-]{21}$",
};

@@ -96,2 +98,11 @@ function parseStringDef(def, refs) {

break;
case "date":
addFormat(res, "date", check.message, refs);
break;
case "time":
addFormat(res, "time", check.message, refs);
break;
case "duration":
addFormat(res, "duration", check.message, refs);
break;
case "length":

@@ -125,6 +136,25 @@ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minLength", typeof res.minLength === "number"

}
case "base64": {
switch (refs.base64Strategy) {
case "format:binary": {
addFormat(res, "binary", check.message, refs);
break;
}
case "contentEncoding:base64": {
(0, errorMessages_js_1.setResponseValueAndErrors)(res, "contentEncoding", "base64", check.message, refs);
break;
}
case "pattern:zod": {
addPattern(res, exports.zodPatterns.base64, check.message, refs);
break;
}
}
break;
}
case "nanoid": {
addPattern(res, exports.zodPatterns.nanoid, check.message, refs);
}
case "toLowerCase":
case "toUpperCase":
case "trim":
// I have no idea why these are checks in Zod 🤷
break;

@@ -131,0 +161,0 @@ default:

@@ -0,3 +1,4 @@

export * from "./Options.js";
export * from "./Refs.js";
export * from "./errorMessages.js";
export * from "./Options.js";
export * from "./parseDef.js";

@@ -34,5 +35,4 @@ export * from "./parsers/any.js";

export * from "./parsers/unknown.js";
export * from "./Refs.js";
export * from "./zodToJsonSchema.js";
import { zodToJsonSchema } from "./zodToJsonSchema.js";
export default zodToJsonSchema;

@@ -19,2 +19,3 @@ export const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");

emailStrategy: "format:email",
base64Strategy: "contentEncoding:base64",
};

@@ -21,0 +22,0 @@ export const getDefaultOptions = (options) => (typeof options === "string"

@@ -32,2 +32,4 @@ import { setResponseValueAndErrors } from "../errorMessages.js";

ipv6: "^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$",
base64: "^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$",
nanoid: "^[a-zA-Z0-9_-]{21}$",
};

@@ -93,2 +95,11 @@ export function parseStringDef(def, refs) {

break;
case "date":
addFormat(res, "date", check.message, refs);
break;
case "time":
addFormat(res, "time", check.message, refs);
break;
case "duration":
addFormat(res, "duration", check.message, refs);
break;
case "length":

@@ -122,6 +133,25 @@ setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number"

}
case "base64": {
switch (refs.base64Strategy) {
case "format:binary": {
addFormat(res, "binary", check.message, refs);
break;
}
case "contentEncoding:base64": {
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
break;
}
case "pattern:zod": {
addPattern(res, zodPatterns.base64, check.message, refs);
break;
}
}
break;
}
case "nanoid": {
addPattern(res, zodPatterns.nanoid, check.message, refs);
}
case "toLowerCase":
case "toUpperCase":
case "trim":
// I have no idea why these are checks in Zod 🤷
break;

@@ -128,0 +158,0 @@ default:

@@ -0,3 +1,4 @@

export * from "./Options.js";
export * from "./Refs.js";
export * from "./errorMessages.js";
export * from "./Options.js";
export * from "./parseDef.js";

@@ -34,5 +35,4 @@ export * from "./parsers/any.js";

export * from "./parsers/unknown.js";
export * from "./Refs.js";
export * from "./zodToJsonSchema.js";
import { zodToJsonSchema } from "./zodToJsonSchema.js";
export default zodToJsonSchema;

@@ -24,2 +24,3 @@ import { ZodSchema, ZodTypeDef } from "zod";

emailStrategy: "format:email" | "format:idn-email" | "pattern:zod";
base64Strategy: "format:binary" | "contentEncoding:base64" | "pattern:zod";
override?: (def: ZodTypeDef, refs: Refs, seen: Seen | undefined, forceResolution?: boolean) => JsonSchema7Type | undefined | typeof ignoreOverride;

@@ -26,0 +27,0 @@ };

@@ -34,2 +34,4 @@ import { ZodStringDef } from "zod";

readonly ipv6: "^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$";
readonly base64: "^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$";
readonly nanoid: "^[a-zA-Z0-9_-]{21}$";
};

@@ -40,3 +42,3 @@ export type JsonSchema7StringType = {

maxLength?: number;
format?: "email" | "idn-email" | "uri" | "uuid" | "date-time" | "ipv4" | "ipv6";
format?: "email" | "idn-email" | "uri" | "uuid" | "date-time" | "ipv4" | "ipv6" | "date" | "time" | "duration";
pattern?: string;

@@ -56,3 +58,4 @@ allOf?: {

errorMessage?: ErrorMessages<JsonSchema7StringType>;
contentEncoding?: string;
};
export declare function parseStringDef(def: ZodStringDef, refs: Refs): JsonSchema7StringType;
{
"name": "zod-to-json-schema",
"version": "3.22.5",
"version": "3.23.0",
"description": "Converts Zod schemas to Json Schemas",

@@ -51,3 +51,4 @@ "types": "./dist/types/index.d.ts",

"Bram del Canho (https://github.com/Bram-dc)",
"Gilad Hecht (https://github.com/gthecht)"
"Gilad Hecht (https://github.com/gthecht)",
"Colin McDonnell (https://github.com/colinhacks)"
],

@@ -60,3 +61,3 @@ "repository": {

"peerDependencies": {
"zod": "^3.22.4"
"zod": "^3.23.3"
},

@@ -73,4 +74,4 @@ "devDependencies": {

"typescript": "^5.1.3",
"zod": "^3.22.4"
"zod": "^3.23.3"
}
}

@@ -77,2 +77,3 @@ # Zod to Json Schema

| **emailStrategy**?: "format:email" \| "format:idn-email" \| "pattern:zod" | Choose how to handle the email string check. Defaults to "format:email". |
| **base64Strategy**?: "format:binary" \| "contentEnconding:base64" \| "pattern:zod" | Choose how to handle the base64 string check. Defaults to "contentEncoding:base64" as described [here](https://json-schema.org/understanding-json-schema/reference/non_json_data#contentencoding). Note that "format:binary" is not represented in the output type as it's not part of the JSON Schema spec and only intended to be used when targeting OpenAPI 3.0. Later versions of OpenAPI support contentEncoding. |
| **definitionPath**?: "definitions" \| "$defs" | The name of the definitions property when name is passed. Defaults to "definitions". |

@@ -79,0 +80,0 @@ | **target**?: "jsonSchema7" \| "jsonSchema2019-09" \| "openApi3" | Which spec to target. Defaults to "jsonSchema7" |

@@ -0,0 +0,0 @@ # Security Policy

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc