
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
prisma-zod-generator
Advanced tools
Prisma 2+ generator to emit Zod schemas from your Prisma schema
Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have. Updates every time npx prisma generate
runs.
Using npm:
npm install prisma-zod-generator
Using yarn:
yarn add prisma-zod-generator
1- Star this repo 😉
2- Add the generator to your Prisma schema
generator zod {
provider = "prisma-zod-generator"
}
3- Enable strict mode in tsconfig
as it is required by Zod, and considered a Typescript best practice
{
"compilerOptions": {
"strict": true
}
}
4- Running npx prisma generate
for the following schema.prisma
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
published Boolean @default(false)
viewCount Int @default(0)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
likes BigInt
}
will generate the following files
5- Use generated schemas somewhere in your API logic, like middleware or decorator
import { PostCreateOneSchema } from './prisma/generated/schemas/createOnePost.schema';
app.post('/blog', async (req, res, next) => {
const { body } = req;
await PostCreateOneSchema.parse(body);
});
/// @@Gen.model(hide: true)
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Option | Description | Type | Default |
---|---|---|---|
output | Output directory for the generated zod schemas | string | ./generated |
isGenerateSelect | Enables the generation of Select related schemas and the select property | boolean | false |
isGenerateInclude | Enables the generation of Include related schemas and the include property | boolean | false |
Use additional options in the schema.prisma
generator zod {
provider = "prisma-zod-generator"
output = "./generated-zod-schemas"
isGenerateSelect = true
isGenerateInclude = true
}
FAQs
Prisma 2+ generator to emit Zod schemas from your Prisma schema
The npm package prisma-zod-generator receives a total of 3,318 weekly downloads. As such, prisma-zod-generator popularity was classified as popular.
We found that prisma-zod-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.