diff --git a/apps/api/v1/lib/validations/shared/jsonSchema.ts b/apps/api/v1/lib/validations/shared/jsonSchema.ts index bfc7ae1f2b..423b28e955 100644 --- a/apps/api/v1/lib/validations/shared/jsonSchema.ts +++ b/apps/api/v1/lib/validations/shared/jsonSchema.ts @@ -1,9 +1,11 @@ import { z } from "zod"; // Helper schema for JSON fields -type Literal = boolean | number | string; +type Literal = boolean | number | string | null; type Json = Literal | { [key: string]: Json } | Json[]; -const literalSchema = z.union([z.string(), z.number(), z.boolean()]); +const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); +const jsonObjectSchema = z.record(z.lazy(() => jsonSchema)); +const jsonArraySchema = z.array(z.lazy(() => jsonSchema)); export const jsonSchema: z.ZodSchema = z.lazy(() => - z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]) + z.union([literalSchema, jsonObjectSchema, jsonArraySchema]) );