Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
ethanhinson / amplifyToZod.ts
Created April 22, 2024 02:29
Create Zod schema from Amplify Model
export function createZodSchema(schemaMap: Record<string, ModelField>) {
let schemaObject: { [key: string]: z.ZodTypeAny } = {};
for (const key in schemaMap) {
const field = schemaMap[key];
let baseType: z.ZodTypeAny;
if (typeof field.type === 'string') {
switch (field.type) {
case 'ID':
case 'String':
case 'AWSJSON':