zod-to-json-schema
Advanced tools
Comparing version 3.18.0 to 3.18.1
@@ -5,2 +5,4 @@ # Changelog | ||
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 3.18.1 | Add strictUnions options | | ||
| 3.18.0 | Added support for branded types | | ||
| 3.17.2 | Fix for reference paths when supplying name option string. | | ||
@@ -7,0 +9,0 @@ | 3.17.1 | Added startsWith and endsWith string checks. Merge multiple pattern checks into allOf array. | |
{ | ||
"name": "zod-to-json-schema", | ||
"version": "3.18.0", | ||
"version": "3.18.1", | ||
"description": "Converts Zod schemas to Json Schemas", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,2 +72,3 @@ # Zod to Json Schema | ||
| **target**?: "jsonSchema7" \| "openApi3" | Which spec to target. Defaults to "jsonSchema7" | | ||
| **strictUnions**?: boolean | Scrubs unions of any-like json schemas, like `{}` or `true`. Multiple zod types may result in these out of necessity, such as z.instanceof() | | ||
@@ -74,0 +75,0 @@ ## Known issues |
@@ -75,4 +75,5 @@ "use strict"; | ||
.map((x, i) => (0, parseDef_1.parseDef)(x._def, refs.addToPath("anyOf", i.toString()))) | ||
.filter((x) => !!x); | ||
.filter((x) => !!x && | ||
(!refs.strictUnions || (typeof x === "object" && Object.keys(x).length > 0))); | ||
return anyOf.length ? { anyOf } : undefined; | ||
}; |
@@ -10,3 +10,4 @@ import { ZodTypeDef } from "zod"; | ||
propertyPath: string[]; | ||
constructor(path?: string[], items?: Item[], $refStrategy?: $refStrategy, effectStrategy?: EffectStrategy, target?: Target, propertyPath?: string[]); | ||
strictUnions: boolean; | ||
constructor(path?: string[], items?: Item[], $refStrategy?: $refStrategy, effectStrategy?: EffectStrategy, target?: Target, propertyPath?: string[], strictUnions?: boolean); | ||
addToPath(...path: string[]): References; | ||
@@ -13,0 +14,0 @@ addToPathAsProperty(...path: string[]): References; |
@@ -5,3 +5,3 @@ "use strict"; | ||
class References { | ||
constructor(path = ["#"], items = [], $refStrategy = "root", effectStrategy = "input", target = "jsonSchema7", propertyPath = []) { | ||
constructor(path = ["#"], items = [], $refStrategy = "root", effectStrategy = "input", target = "jsonSchema7", propertyPath = [], strictUnions = false) { | ||
this.currentPath = path; | ||
@@ -13,2 +13,3 @@ this.items = items; | ||
this.propertyPath = propertyPath; | ||
this.strictUnions = strictUnions; | ||
} | ||
@@ -15,0 +16,0 @@ addToPath(...path) { |
@@ -26,2 +26,3 @@ import { ZodSchema } from "zod"; | ||
* @param options.target ("jsonSchema7" | "openApi3") defaults to "jsonSchema7" | ||
* @param options.strictUnions (boolean) defaults to "false". Scrubs unions of any-like json schemas, like `{}` or `true`. Multiple zod types may result in these out of necessity, such as z.instanceof() | ||
* | ||
@@ -36,2 +37,3 @@ */ | ||
target?: Target; | ||
strictUnions?: boolean; | ||
}): Target extends "openApi3" ? Name extends string ? BasePath extends string[] ? { | ||
@@ -38,0 +40,0 @@ $ref: string; |
@@ -12,4 +12,4 @@ "use strict"; | ||
? options.target === "openApi3" | ||
? (0, parseDef_1.parseDef)(schema._def, new References_1.References((_a = options.basePath) !== null && _a !== void 0 ? _a : ["#"], [], (_b = options.$refStrategy) !== null && _b !== void 0 ? _b : "root", options.effectStrategy, options.target)) | ||
: Object.assign({ $schema }, (0, parseDef_1.parseDef)(schema._def, new References_1.References((_c = options.basePath) !== null && _c !== void 0 ? _c : ["#"], [], (_d = options.$refStrategy) !== null && _d !== void 0 ? _d : "root", options.effectStrategy, options.target))) | ||
? (0, parseDef_1.parseDef)(schema._def, new References_1.References((_a = options.basePath) !== null && _a !== void 0 ? _a : ["#"], [], (_b = options.$refStrategy) !== null && _b !== void 0 ? _b : "root", options.effectStrategy, options.target, undefined, options.strictUnions)) | ||
: Object.assign({ $schema }, (0, parseDef_1.parseDef)(schema._def, new References_1.References((_c = options.basePath) !== null && _c !== void 0 ? _c : ["#"], [], (_d = options.$refStrategy) !== null && _d !== void 0 ? _d : "root", options.effectStrategy, options.target, undefined, options.strictUnions))) | ||
: options.target === "openApi3" | ||
@@ -25,3 +25,3 @@ ? { | ||
options.name, | ||
], [], (_k = options.$refStrategy) !== null && _k !== void 0 ? _k : "root", options.effectStrategy, options.target)) || {}, | ||
], [], (_k = options.$refStrategy) !== null && _k !== void 0 ? _k : "root", options.effectStrategy, options.target, undefined, options.strictUnions)) || {}, | ||
}, | ||
@@ -39,3 +39,3 @@ } | ||
options.name, | ||
], [], (_r = options.$refStrategy) !== null && _r !== void 0 ? _r : "root", options.effectStrategy, options.target)) || {}, | ||
], [], (_r = options.$refStrategy) !== null && _r !== void 0 ? _r : "root", options.effectStrategy, options.target, undefined, options.strictUnions)) || {}, | ||
}, | ||
@@ -42,0 +42,0 @@ }; |
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
71831
1139
89