chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
578 stars 43 forks source link

Import is not a valid validator type #216

Open laneme opened 7 months ago

laneme commented 7 months ago

Tried to follow how it is documented exactly and some varations (tested my luck)

model Target {
  id   String @id @default(auto()) @map("_id") @db.ObjectId
  /// @zod.import(["import { zodStringNonempty } from '@libs'"]).custom.use(zodStringNonempty('Name'))
  name String

  /// @zod.import(["import { zodStringNonempty } from '@libs'"]).custom.use(z.string())
  withoutUsingTheImoprtedValue String

  /// @zod.import(["import { zodStringNonempty } from '../libs/refinements'"]).custom.use(z.string())
  withRelativeImport String

  /// @zod.import(['import { zodStringNonempty } from "../libs/refinements"']).custom.use(z.string())
  withSingleQuotes String

  /// @zod.import('import { zodStringNonempty } from "@libs"').custom.use(z.string())
  withoutArray String
}

My config

generator zod {
  provider                         = "zod-prisma-types"
  output                           = "../lib/zod/generated"
  writeBarrelFiles                 = false
  createInputTypes                 = false
  addInputTypeValidation           = false
  addIncludeType                   = false
  addSelectType                    = false
  createOptionalDefaultValuesTypes = true
  createRelationValuesTypes        = true
  coerceDate                       = false
  writeNullishInModelTypes         = true
}

Screenshots image

Package versions (please complete the following information):

laneme commented 7 months ago

Alright so I noticed you use prisma packages above v5.5.0, so I bumpted my prisma to 5.6.0 (current latest) and the validation error supressed.

But, the generated file did Not have the imports written on top of the file.

Tested with

Status: Needs Fix

timfenton-dermi commented 6 months ago

not sure if this is a requirement, but it didnt work for me until i turned useMultipleFiles to true to break the schemas into their own files.

grantsiemens commented 5 months ago

Dealing with the same issue. I did find out import location is based on output location of the generated file, but turning on multiple files is the only thing I can do for the imports to appear. I am running the latest version of everything.