json-schema-to-zod
Advanced tools
Comparing version
@@ -7,5 +7,5 @@ "use strict"; | ||
return `z.union([${schema.type | ||
.map((type) => (0, parseSchema_js_1.parseSchema)({ ...schema, type }, refs)) | ||
.map((type) => (0, parseSchema_js_1.parseSchema)({ ...schema, type }, { ...refs, withoutDefaults: true })) | ||
.join(", ")}])`; | ||
}; | ||
exports.parseMultipleType = parseMultipleType; |
import { parseSchema } from "./parseSchema.js"; | ||
export const parseMultipleType = (schema, refs) => { | ||
return `z.union([${schema.type | ||
.map((type) => parseSchema({ ...schema, type }, refs)) | ||
.map((type) => parseSchema({ ...schema, type }, { ...refs, withoutDefaults: true })) | ||
.join(", ")}])`; | ||
}; |
{ | ||
"name": "json-schema-to-zod", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "Converts JSON schema objects or files into Zod schemas", | ||
@@ -39,9 +39,3 @@ "types": "./dist/types/index.d.ts", | ||
}, | ||
"keywords": [ | ||
"zod", | ||
"json", | ||
"schema", | ||
"converter", | ||
"cli" | ||
], | ||
"keywords": ["zod", "json", "schema", "converter", "cli"], | ||
"author": "Stefan Terdell", | ||
@@ -61,3 +55,4 @@ "contributors": [ | ||
"vForgeOne (https://github.com/vforgeone)", | ||
"Adrian Ordonez (https://github.com/adrianord)" | ||
"Adrian Ordonez (https://github.com/adrianord)", | ||
"Jonas Reucher (https://github.com/Mantls)" | ||
], | ||
@@ -64,0 +59,0 @@ "license": "ISC", |
@@ -76,3 +76,7 @@ # Json-Schema-to-Zod | ||
// `type` can be either a string or - outside of the CLI - a boolean. If its `true`, the name of the type will be the name of the schema with a capitalized first letter. | ||
const moduleWithType = jsonSchemaToZod(myObject, { name: "mySchema", module: "esm", type: true }); | ||
const moduleWithType = jsonSchemaToZod(myObject, { | ||
name: "mySchema", | ||
module: "esm", | ||
type: true, | ||
}); | ||
@@ -123,3 +127,3 @@ const cjs = jsonSchemaToZod(myObject, { module: "cjs", name: "mySchema" }); | ||
async function example(jsonSchema: Record<string, unknown>): Promise<string>{ | ||
async function example(jsonSchema: Record<string, unknown>): Promise<string> { | ||
const { resolved } = await resolveRefs(jsonSchema); | ||
@@ -137,2 +141,6 @@ const code = jsonSchemaToZod(resolved); | ||
#### Schema factoring | ||
Factored schemas (like object schemas with "oneOf" etc.) is only partially supported. Here be dragons. | ||
#### Use at Runtime | ||
@@ -139,0 +147,0 @@ |
154
5.48%108959
-99.28%89
-27.64%