@@ -340,7 +340,7 @@ export class ZodSchemaGenerator {
340340 } ) ;
341341 this . sourceFiles . push ( sf ) ;
342342 sf . replaceWithText ( ( writer ) => {
343- this . addPreludeAndImports ( typeDef , writer , output ) ;
343+ this . addPreludeAndImports ( typeDef , writer ) ;
344344
345345 writer . write ( `const baseSchema = z.object(` ) ;
346346 writer . inlineBlock ( ( ) => {
@@ -383,7 +383,7 @@ export const ${typeDef.name}Schema = ${refineFuncName}(${noRefineSchema});
383383 return schemaName ;
384384 }
385385
386- private addPreludeAndImports ( decl : DataModel | TypeDef , writer : CodeBlockWriter , output : string ) {
386+ private addPreludeAndImports ( decl : DataModel | TypeDef , writer : CodeBlockWriter ) {
387387 writer . writeLine ( `import { z } from 'zod/${ this . zodVersion } ';` ) ;
388388
389389 // import user-defined enums from Prisma as they might be referenced in the expressions
@@ -396,10 +396,6 @@ export const ${typeDef.name}Schema = ${refineFuncName}(${noRefineSchema});
396396 }
397397 }
398398 }
399- if ( importEnums . size > 0 ) {
400- const prismaImport = computePrismaClientImport ( path . join ( output , 'models' ) , this . options ) ;
401- writer . writeLine ( `import { ${ [ ...importEnums ] . join ( ', ' ) } } from '${ prismaImport } ';` ) ;
402- }
403399
404400 // import enum schemas
405401 const importedEnumSchemas = new Set < string > ( ) ;
@@ -448,7 +444,7 @@ export const ${typeDef.name}Schema = ${refineFuncName}(${noRefineSchema});
448444 const relations = model . fields . filter ( ( field ) => isDataModel ( field . type . reference ?. ref ) ) ;
449445 const fkFields = model . fields . filter ( ( field ) => isForeignKeyField ( field ) ) ;
450446
451- this . addPreludeAndImports ( model , writer , output ) ;
447+ this . addPreludeAndImports ( model , writer ) ;
452448
453449 // base schema - including all scalar fields, with optionality following the schema
454450 this . createModelBaseSchema ( 'baseSchema' , writer , scalarFields , true ) ;
@@ -730,9 +726,7 @@ export const ${upperCaseFirst(model.name)}UpdateSchema = ${updateSchema};
730726 /**
731727 * Schema refinement function for applying \`@@validate\` rules.
732728 */
733- export function ${ refineFuncName } <T>(schema: z.ZodType<T>) { return schema${ refinements . join (
734- '\n'
735- ) } ;
729+ export function ${ refineFuncName } <T>(schema: z.ZodType<T>) { return schema${ refinements . join ( '\n' ) } ;
736730 }
737731 `
738732 ) ;
@@ -766,6 +760,7 @@ export const ${upperCaseFirst(model.name)}UpdateSchema = ${updateSchema};
766760 let expr = new TypeScriptExpressionTransformer ( {
767761 context : ExpressionContext . ValidationRule ,
768762 fieldReferenceContext : 'value' ,
763+ useLiteralEnum : true ,
769764 } ) . transform ( valueArg ) ;
770765
771766 if ( isDataModelFieldReference ( valueArg ) ) {
0 commit comments