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.20.2 to 3.20.3

2

changelog.md

@@ -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. |

4

package.json
{
"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 &&

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