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.23.3 to 3.23.4

.github/FUNDING.yml

1

changelog.md

@@ -5,2 +5,3 @@ # Changelog

| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 3.23.4 | Fixes branded regex property names and a weird edgecase in arrays. Thanks to [Isaiah Marc Sanchez](https://github.com/imsanchez) and [Mitchell Merry](https://github.com/mitchell-merry)! |
| 3.23.3 | More tests (Thanks [Brett Zamir!](https://github.com/brettz9)), removed dead code |

@@ -7,0 +8,0 @@ | 3.23.2 | Lazily loads Emoji regex to avoid incompatibility with some environments. Thanks [Jacob Lee](https://github.com/jacoblee93)! |

2

dist/cjs/parsers/array.js

@@ -11,3 +11,3 @@ "use strict";

};
if (def.type?._def?.typeName !== zod_1.ZodFirstPartyTypeKind.ZodAny) {
if (def.type?._def && def.type?._def?.typeName !== zod_1.ZodFirstPartyTypeKind.ZodAny) {
res.items = (0, parseDef_js_1.parseDef)(def.type._def, {

@@ -14,0 +14,0 @@ ...refs,

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

const string_js_1 = require("./string.js");
const branded_1 = require("./branded");
function parseRecordDef(def, refs) {

@@ -36,3 +37,3 @@ if (refs.target === "openApi3" &&

def.keyType._def.checks?.length) {
const keyType = Object.entries((0, string_js_1.parseStringDef)(def.keyType._def, refs)).reduce((acc, [key, value]) => (key === "type" ? acc : { ...acc, [key]: value }), {});
const { type, ...keyType } = (0, string_js_1.parseStringDef)(def.keyType._def, refs);
return {

@@ -51,4 +52,13 @@ ...schema,

}
else if (def.keyType?._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodBranded &&
def.keyType._def.type._def.typeName === zod_1.ZodFirstPartyTypeKind.ZodString &&
def.keyType._def.type._def.checks?.length) {
const { type, ...keyType } = (0, branded_1.parseBrandedDef)(def.keyType._def, refs);
return {
...schema,
propertyNames: keyType,
};
}
return schema;
}
exports.parseRecordDef = parseRecordDef;

@@ -8,3 +8,3 @@ import { ZodFirstPartyTypeKind } from "zod";

};
if (def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
res.items = parseDef(def.type._def, {

@@ -11,0 +11,0 @@ ...refs,

import { ZodFirstPartyTypeKind, } from "zod";
import { parseDef } from "../parseDef.js";
import { parseStringDef } from "./string.js";
import { parseBrandedDef } from "./branded";
export function parseRecordDef(def, refs) {

@@ -32,3 +33,3 @@ if (refs.target === "openApi3" &&

def.keyType._def.checks?.length) {
const keyType = Object.entries(parseStringDef(def.keyType._def, refs)).reduce((acc, [key, value]) => (key === "type" ? acc : { ...acc, [key]: value }), {});
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
return {

@@ -47,3 +48,12 @@ ...schema,

}
else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded &&
def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString &&
def.keyType._def.type._def.checks?.length) {
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
return {
...schema,
propertyNames: keyType,
};
}
return schema;
}
{
"name": "zod-to-json-schema",
"version": "3.23.3",
"version": "3.23.4",
"description": "Converts Zod schemas to Json Schemas",

@@ -63,3 +63,5 @@ "types": "./dist/types/index.d.ts",

"Jacob Lee (https://github.com/jacoblee93)",
"Brett Zamir (https://github.com/brettz9)"
"Brett Zamir (https://github.com/brettz9)",
"Isaiah Marc Sanchez (https://github.com/imsanchez)",
"Mitchell Merry (https://github.com/mitchell-merry)"
],

@@ -66,0 +68,0 @@ "repository": {

@@ -14,6 +14,33 @@ # Zod to Json Schema

- Resolves recursive and recurring schemas with internal `$ref`s.
- Also able to target Open API 3 (Swagger) specification for paths.
- Also able to target legacy Open API 3.0 specification for path schemas (3.1 supports regular Json Schema).
### Usage
## Sponsors
If you enjoy this package, consider dropping a couple of bucks on my [GitHub Sponsors page](https://github.com/sponsors/StefanTerdell) <3
<table align="center" style="justify-content: center;align-items: center;display: flex;">
<tr>
<td align="center">
<p></p>
<p>
<a href="https://retool.com/?utm_source=github&utm_medium=referral&utm_campaign=zod-to-json-schema">
<picture height="45px">
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/colinhacks/zod/assets/3084745/ac65013f-aeb4-48dd-a2ee-41040b69cbe6">
<img alt="stainless" height="45px" src="https://github.com/colinhacks/zod/assets/3084745/5ef4c11b-efeb-4495-90a8-41b83f798600">
</picture>
</a>
<br />
Build AI apps and workflows with <a href="https://retool.com/products/ai?utm_source=github&utm_medium=referral&utm_campaign=zod-to-json-schema">Retool AI</a>
<br/>
<a href="https://retool.com/?utm_source=github&utm_medium=referral&utm_campaign=zod-to-json-schema" style="text-decoration:none;">retool.com</a>
</p>
<p></p>
</td>
</tr>
</table>
## Usage
### Basic example
```typescript

@@ -20,0 +47,0 @@ import { z } from "zod";

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