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.1.0 to 3.2.0

src/parsers/map.d.ts

2

package.json
{
"name": "zod-to-json-schema",
"version": "3.1.0",
"version": "3.2.0",
"description": "Converts Zod schemas to Json Schemas",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -54,13 +54,14 @@ # Zod to Json Schema

| Version | Change |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 3.1.0 | String patterns finally supported! Fixed bugs include broken external type, unsafe nullable parsing, bad intersection implementation, and missing support for passthrough keys in objects. |
| 3.0.3 | Fixed array deep pathing bug (path contained `array` instead of `items`) |
| 3.0.2 | Fixed broken type usage (NonEmptyArrayDefinition was removed from Zod) |
| 3.0.1 | Fixed a typo in the readme |
| 3.0.0 | Compatible with Zod 3.2.0. Huge props to [Mr Hammad Asif](https://github.com/mrhammadasif) for his work on this. |
| 0.6.2 | Hotfix for undefined object properties. Could crash the parser when using Pick |
| 0.6.1 | Fixed bug in union pathing. `$Ref` was missing `/anyOf` |
| 0.6.0 | Moved `@types/json-schema` and `typescript` to dev dependencies. `@types/json-schema` is now only used for the test suites. Using `strict: true` in ts config. |
| 0.5.1 | First working release with all relevant Zod types present with most validations (except for string patterns due to Zod not exposing the source regexp pattern for those). |
| < 0.5.1 | Deprecated due to broken package structure. Please be patient, I eat crayons. |
| Version | Change |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 3.2.0 | Added support for Map and Set as seen by their most common JSON definitions. Beware no standardized definition seem to exist and JSON.parse doesn't handle either natively. Their implementations here are based on the spread approach. Also further simplified intersection definition to just allOf. |
| 3.1.0 | String patterns finally supported! Fixed bugs include broken external type, unsafe nullable parsing, bad intersection implementation, and missing support for passthrough keys in objects. |
| 3.0.3 | Fixed array deep pathing bug (path contained `array` instead of `items`) |
| 3.0.2 | Fixed broken type usage (NonEmptyArrayDefinition was removed from Zod) |
| 3.0.1 | Fixed a typo in the readme |
| 3.0.0 | Compatible with Zod 3.2.0. Huge props to [Mr Hammad Asif](https://github.com/mrhammadasif) for his work on this. |
| 0.6.2 | Hotfix for undefined object properties. Could crash the parser when using Pick |
| 0.6.1 | Fixed bug in union pathing. `$Ref` was missing `/anyOf` |
| 0.6.0 | Moved `@types/json-schema` and `typescript` to dev dependencies. `@types/json-schema` is now only used for the test suites. Using `strict: true` in ts config. |
| 0.5.1 | First working release with all relevant Zod types present with most validations (except for string patterns due to Zod not exposing the source regexp pattern for those). |
| < 0.5.1 | Deprecated due to broken package structure. Please be patient, I eat crayons. |

@@ -10,5 +10,7 @@ import { ZodSchema } from "zod";

import { JsonSchema7NullType } from "./parsers/null";
import { JsonSchema7NullableType } from "./parsers/nullable";
import { JsonSchema7NumberType } from "./parsers/number";
import { JsonSchema7ObjectType } from "./parsers/object";
import { JsonSchema7RecordType } from "./parsers/record";
import { JsonSchema7MapType } from "./parsers/map";
import { JsonSchema7StringType } from "./parsers/string";

@@ -22,3 +24,3 @@ import { JsonSchema7TupleType } from "./parsers/tuple";

};
export declare type JsonSchema7Type = JsonSchema7StringType | JsonSchema7ArrayType | JsonSchema7NumberType | JsonSchema7BigintType | JsonSchema7BooleanType | JsonSchema7DateType | JsonSchema7EnumType | JsonSchema7LiteralType | JsonSchema7NativeEnumType | JsonSchema7NullType | JsonSchema7NumberType | JsonSchema7ObjectType | JsonSchema7RecordType | JsonSchema7TupleType | JsonSchema7PrimitiveUnionType | JsonSchema7UndefinedType | JsonSchema7AnyOfType | JsonSchema7RefType | JsonSchema7AnyType;
export declare type JsonSchema7Type = JsonSchema7StringType | JsonSchema7ArrayType | JsonSchema7NumberType | JsonSchema7BigintType | JsonSchema7BooleanType | JsonSchema7DateType | JsonSchema7EnumType | JsonSchema7LiteralType | JsonSchema7NativeEnumType | JsonSchema7NullType | JsonSchema7NumberType | JsonSchema7ObjectType | JsonSchema7RecordType | JsonSchema7TupleType | JsonSchema7PrimitiveUnionType | JsonSchema7UndefinedType | JsonSchema7AnyOfType | JsonSchema7RefType | JsonSchema7AnyType | JsonSchema7MapType | JsonSchema7NullableType;
export declare type Visited = {

@@ -25,0 +27,0 @@ schema: ZodSchema<any>;

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

const record_1 = require("./parsers/record");
const set_1 = require("./parsers/set");
const map_1 = require("./parsers/map");
const string_1 = require("./parsers/string");

@@ -70,7 +72,9 @@ const tuple_1 = require("./parsers/tuple");

return parseDef(def.innerType, path, visited);
case zod_1.ZodFirstPartyTypeKind.ZodMap:
return map_1.parseMapDef(def, path, visited);
case zod_1.ZodFirstPartyTypeKind.ZodSet:
return set_1.parseSetDef(def, path, visited);
case zod_1.ZodFirstPartyTypeKind.ZodEffects:
case zod_1.ZodFirstPartyTypeKind.ZodAny:
case zod_1.ZodFirstPartyTypeKind.ZodUnknown:
case zod_1.ZodFirstPartyTypeKind.ZodMap:
case zod_1.ZodFirstPartyTypeKind.ZodSet:
case zod_1.ZodFirstPartyTypeKind.ZodDefault:

@@ -77,0 +81,0 @@ return {};

import { ZodIntersectionDef } from "zod";
import { JsonSchema7Type, Visited } from "../parseDef";
export declare function parseIntersectionDef(def: ZodIntersectionDef, path: string[], visited: Visited): JsonSchema7Type | undefined;
export declare function parseIntersectionDef(def: ZodIntersectionDef, path: string[], visited: Visited): JsonSchema7Type;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseIntersectionDef = void 0;
const zod_1 = require("zod");
const parseDef_1 = require("../parseDef");
const object_1 = require("./object");
function parseIntersectionDef(def, path, visited) {
const rightDef = def.right._def;
const leftDef = def.left._def;
if (rightDef.t === zod_1.ZodParsedType.object &&
leftDef.t === zod_1.ZodParsedType.object) {
const right = object_1.parseObjectDef(rightDef, path, visited);
const left = object_1.parseObjectDef(leftDef, path, visited);
return {
type: "object",
properties: Object.assign(Object.assign({}, left.properties), right.properties),
required: [
...(left.required || []).filter((x) => !Object.keys(right.properties).includes(x)),
...(right.required || []),
],
};
}
return {
allOf: [parseDef_1.parseDef(leftDef, path, visited), parseDef_1.parseDef(rightDef, path, visited)],
};
const allOf = [
parseDef_1.parseDef(def.left._def, path, visited),
parseDef_1.parseDef(def.right._def, path, visited),
].filter(Boolean);
return allOf.length === 2 ? { allOf } : allOf.length === 1 ? allOf[0] : {};
}
exports.parseIntersectionDef = parseIntersectionDef;
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