Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import is not a valid validator type #216

Open
laneme opened this issue Nov 28, 2023 · 3 comments
Open

Import is not a valid validator type #216

laneme opened this issue Nov 28, 2023 · 3 comments
Assignees
Labels
bug (unconfirmed) Could be a bug

Comments

@laneme
Copy link

laneme commented Nov 28, 2023

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):

  • zod-prisma-types: 3.1.6 and 2.8.1
  • zod: 3.21.1
  • prisma: 5.3.1
@laneme
Copy link
Author

laneme commented Nov 30, 2023

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

  • zod-prisma-types: 3.1.6
  • prisma: 5.6.0 and 5.5.2

Status: Needs Fix

@timfenton-dermi
Copy link

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
Copy link

grantsiemens commented Jan 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unconfirmed) Could be a bug
Projects
None yet
Development

No branches or pull requests

4 participants