[Feature Request] Add option for Model Schema only
Opened this issue · 1 comments
I really like this library and we use it in my organisation. However, I think there is a lot of boilerplate types being generated when running npx prisma generate
that we do not use.
Is there a way to skip the generation of InputTypeSchemas
or only generate those needed for my model schemas? I see a lot of enumSchemas generated that is not used anywhere.
Furthermore, is there a way to skip creating types for my model schemas? The reason is that it can create confusion between the types generated by the prisma client.
Thanks!
To answer your first question: Yes, you can disable createInputTypes
and enable only createModelTypes
, but that will still generate the InputTypeSchemas
folder with Enum Schemas/Types... which is pointless, in my view.
It would be great to have this package simply use the enum types exported by Prisma itself!
That way, instead of having this:
./generated/zod/inputTypeSchemas/UserRoleSchema.ts
import { z } from 'zod'
export const UserRoleSchema = z.enum(['USER', 'ADMIN'])
export type UserRoleType = `${z.infer<typeof UserRoleSchema>}` // <== By the way, isn't this a bug? shouldn't it be "export type UserRoleType = z.infer<typeof UserRoleSchema>" ???
export default UserRoleSchema
./generated/zod/modelSchema/UserSchema.ts
import { UserRoleSchema } from '../inputTypeSchemas/UserRoleSchema'
/////////////////////////////////////////
// USER SCHEMA
/////////////////////////////////////////
export const UserSchema = z.object({
role: UserRoleSchema,
name: z.string(),
})
export type User = z.infer<typeof UserSchema>
export default UserSchema
We could just have this:
./generated/zod/modelSchema/UserSchema.ts
import { UserRole } from '@prisma/client'
/////////////////////////////////////////
// USER SCHEMA
/////////////////////////////////////////
export const UserSchema = z.object({
role: z.nativeEnum(UserRole),
name: z.string(),
})
export type User = z.infer<typeof UserSchema>
export default UserSchema
No?
Edit: I know Zod Enums (.enum()
) are the recommended approach to defining and validating enums, but as Zod itself says:
If you need to validate against an enum from a third-party library (or you don't want to rewrite your existing enums) you can use z.nativeEnum().
~~ Documentation Source