zod-to-json-schema
Advanced tools
Comparing version 3.18.1 to 3.18.2
@@ -5,2 +5,3 @@ # Changelog | ||
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 3.18.2 | Fixes support for native enums | | ||
| 3.18.1 | Add strictUnions options | | ||
@@ -7,0 +8,0 @@ | 3.18.0 | Added support for branded types | |
{ | ||
"name": "zod-to-json-schema", | ||
"version": "3.18.1", | ||
"version": "3.18.2", | ||
"description": "Converts Zod schemas to Json Schemas", | ||
@@ -9,4 +9,4 @@ "main": "index.js", | ||
"dev": "jest --watch", | ||
"build": "rimraf dist && tsc && node copyPackageFiles.js", | ||
"dryrun": "jest && npm run build && npm pub ./dist/ --dry-run" | ||
"build": "npm i && jest && rimraf dist && tsc && node copyPackageFiles.js", | ||
"dryrun": "npm run build && npm pub ./dist/ --dry-run" | ||
}, | ||
@@ -26,3 +26,4 @@ "keywords": [ | ||
"John Wright (https://github.com/johngeorgewright)", | ||
"Krzysztof Ciombor (https://github.com/krzysztofciombor)" | ||
"Krzysztof Ciombor (https://github.com/krzysztofciombor)", | ||
"Yuta Mombetsu (https://github.com/mokocm)" | ||
], | ||
@@ -29,0 +30,0 @@ "repository": { |
@@ -24,3 +24,3 @@ # Zod to Json Schema | ||
myUnion: z.union([z.number(), z.boolean()]), | ||
}); | ||
}).describe("My neat object schema"); | ||
@@ -38,2 +38,3 @@ const jsonSchema = zodToJsonSchema(mySchema, "mySchema"); | ||
"mySchema": { | ||
"description": "My neat object schema", | ||
"type": "object", | ||
@@ -81,2 +82,3 @@ "properties": { | ||
- Relative JSON pointers, while published alongside [JSON schema draft 2020-12](https://json-schema.org/specification.html), is not technically a part of it. Currently, most resolvers do not handle them at all. | ||
- Since v3, the Object parser uses `.isOptional()` to check if a property should be included in `required` or not. This has the potentially dangerous behavior of calling `.safeParse` with `undefined`. To work around this, make sure your `preprocess` and other effects callbacks are pure and not liable to throw errors. An issue has been logged in the Zod repo and can be [tracked here](https://github.com/colinhacks/zod/issues/1460). | ||
@@ -83,0 +85,0 @@ ## Versioning |
@@ -5,12 +5,10 @@ "use strict"; | ||
function parseNativeEnumDef(def) { | ||
const numberValues = Object.values(def.values) | ||
.filter((value) => typeof value === "number") | ||
.map(toString); | ||
const actualValues = Object.values(def.values).filter((_, i) => i >= numberValues.length); | ||
const object = def.values; | ||
const actualKeys = Object.keys(def.values).filter((key) => { | ||
return typeof object[object[key]] !== 'number'; | ||
}); | ||
const actualValues = actualKeys.map((key) => object[key]); | ||
const parsedTypes = Array.from(new Set(actualValues.map((values) => (typeof values)))); | ||
return { | ||
type: numberValues.length === 0 | ||
? "string" | ||
: numberValues.length === actualValues.length | ||
? "number" | ||
: ["string", "number"], | ||
type: parsedTypes.length === 1 ? parsedTypes[0] === 'string' ? "string" : "number" : ["string", "number"], | ||
enum: actualValues, | ||
@@ -17,0 +15,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
72394
91
66
1127