You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{jsonSchemaToZod}from"json-schema-to-zod";import{z}from"zod";import{zodToJsonSchema}from"zod-to-json-schema";consttestSchema=z.object({name: z.string(),age: z.number().optional(),});constjsonSchema=zodToJsonSchema(testSchema);constzodSchema=jsonSchemaToZod(jsonSchema);// <-- 1st type error with "jsonSchema"console.log({
jsonSchema,
zodSchema,properties: jsonSchema.properties,// <-- 2nd type error with "properties"});
The result of the console.log is below:
The variable jsonSchema has properties that JsonSchemaObject type expects in json-schema-to-zod.
The text was updated successfully, but these errors were encountered:
The first problem is valid. jsonSchemaToZod should accept the output types of zodToJsonSchema. I will look into this... at some point. ;)
The second problem (the "missing" properties) is not a bug. The output will not have inference, like the Zod schema does (meaning the return type just says that it's a JSON Schema, not what the schema contains). Since not all JSON Schemas have "properties" you have to check for it manually.
First of all, thank you for creating the module!
I started using your
zod-to-json-schema
andjson-schema-to-zod
. While the code looks to be working, my VSCode displays errors.The result of the
console.log
is below:The variable
jsonSchema
has properties thatJsonSchemaObject
type expects injson-schema-to-zod
.The text was updated successfully, but these errors were encountered: