🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

json-schema-to-zod

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-zod - npm Package Compare versions

Comparing version

to
2.6.1

2

dist/cjs/parsers/parseMultipleType.js

@@ -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 @@