diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts index 45cd242..08a02d7 100644 --- a/src/core/generateZodSchema.test.ts +++ b/src/core/generateZodSchema.test.ts @@ -68,9 +68,9 @@ describe("generateZodSchema", () => { }); it("should generate a literal schema (number)", () => { - const source = `export type IdentiesCount = 2;`; + const source = `export type IdentitiesCount = 2;`; expect(generate(source)).toMatchInlineSnapshot( - `"export const identiesCountSchema = z.literal(2);"` + `"export const identitiesCountSchema = z.literal(2);"` ); }); @@ -164,9 +164,9 @@ describe("generateZodSchema", () => { }); it("should generate a record schema", () => { - const source = `export type EnnemiesPowers = Record;`; + const source = `export type EnemiesPowers = Record;`; expect(generate(source)).toMatchInlineSnapshot( - `"export const ennemiesPowersSchema = z.record(powerSchema);"` + `"export const enemiesPowersSchema = z.record(powerSchema);"` ); }); @@ -368,6 +368,17 @@ describe("generateZodSchema", () => { `); }); + it("should deal with optional array", () => { + const source = `export interface Collection { + movies?: Array + }`; + expect(generate(source)).toMatchInlineSnapshot(` + "export const collectionSchema = z.object({ + movies: z.array(z.string()).optional() + });" + `); + }); + it("should generate an empty object schema", () => { const source = `export type Empty = {};`; expect(generate(source)).toMatchInlineSnapshot( diff --git a/src/core/generateZodSchema.ts b/src/core/generateZodSchema.ts index ff2139e..bb7dd5c 100644 --- a/src/core/generateZodSchema.ts +++ b/src/core/generateZodSchema.ts @@ -212,7 +212,7 @@ function buildZodPrimitive({ return buildZodPrimitive({ z, typeNode: f.createArrayTypeNode(typeNode.typeArguments[0]), - isOptional: false, + isOptional, jsDocTags: {}, sourceFile, dependencies,