https://github.com/omar-dulaimi/prisma-joi-generator
Prisma 2+ generator to emit Joi schemas from your Prisma schema
https://github.com/omar-dulaimi/prisma-joi-generator
joi joi-validation prisma prisma-generator
Last synced: 6 months ago
JSON representation
Prisma 2+ generator to emit Joi schemas from your Prisma schema
- Host: GitHub
- URL: https://github.com/omar-dulaimi/prisma-joi-generator
- Owner: omar-dulaimi
- License: mit
- Created: 2022-04-14T15:10:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T17:42:14.000Z (over 1 year ago)
- Last Synced: 2025-04-10T21:11:28.497Z (6 months ago)
- Topics: joi, joi-validation, prisma, prisma-generator
- Language: TypeScript
- Homepage:
- Size: 243 KB
- Stars: 43
- Watchers: 2
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Prisma Joi Generator
[](https://badge.fury.io/js/prisma-joi-generator)
[](https://www.npmjs.com/package/prisma-joi-generator)
[](http://hits.dwyl.com/omar-dulaimi/prisma-joi-generator)
[](LICENSE)Automatically generate [Joi](https://joi.dev/api) schemas from your [Prisma](https://github.com/prisma/prisma) Schema, and use them to validate your API endpoints or any other use you have. Updates every time `npx prisma generate` runs.
## Table of Contents
- [Supported Prisma Versions](#supported-prisma-versions)
- [Installation](#installing)
- [Usage](#usage)
- [Additional Options](#additional-options)# Supported Prisma Versions
### Prisma 4
- 0.2.0 and higher
### Prisma 2/3
- 0.1.1 and lower
## Installation
Using npm:
```bash
npm install prisma-joi-generator
```Using yarn:
```bash
yarn add prisma-joi-generator
```# Usage
1- Star this repo 😉
2- Add the generator to your Prisma schema
```prisma
generator joi {
provider = "prisma-joi-generator"
}
```3- Running `npx prisma generate` for the following schema.prisma
```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?
}
```will generate the following files

4- Use generated schemas somewhere in your API logic, like middleware or decorator
```ts
import { PostCreateSchema } from './prisma/generated/schemas';app.post('/blog', async (req, res, next) => {
const { body } = req;
const result = PostCreateSchema.validate(body);
});
```## Additional Options
| Option | Â Description | Type | Â Default |
| -------- | ---------------------------------------------- | -------- | ------------- |
| `output` | Output directory for the generated joi schemas | `string` | `./generated` |Use additional options in the `schema.prisma`
```prisma
generator joi {
provider = "prisma-joi-generator"
output = "./generated-joi-schemas"
}
```