How to automatically generate Joi schemas from your Prisma schema

I’m sure you have built an API before, where you had to manually create a Joi schema for every endpoint. It was repetitive and time-consuming. But not anymore with the help of the Prisma generator I have recently built.

Here’s what you need to do:

1-…


This content originally appeared on DEV Community and was authored by Omar Dulaimi

I'm sure you have built an API before, where you had to manually create a Joi schema for every endpoint. It was repetitive and time-consuming. But not anymore with the help of the Prisma generator I have recently built.

Here's what you need to do:

1- Install the generator

  • Using npm
 npm install prisma-joi-generator
  • Using yarn:
 yarn add prisma-joi-generator

2- Add the generator to your Prisma schema

generator joi {
  provider = "prisma-joi-generator"
}

3- Run npx prisma generate for your schema(or the example below)

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?
}

Now you will have all possible Joi schemas generated for you!

Joi schemas


This content originally appeared on DEV Community and was authored by Omar Dulaimi


Print Share Comment Cite Upload Translate Updates
APA

Omar Dulaimi | Sciencx (2022-04-15T20:43:18+00:00) How to automatically generate Joi schemas from your Prisma schema. Retrieved from https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/

MLA
" » How to automatically generate Joi schemas from your Prisma schema." Omar Dulaimi | Sciencx - Friday April 15, 2022, https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/
HARVARD
Omar Dulaimi | Sciencx Friday April 15, 2022 » How to automatically generate Joi schemas from your Prisma schema., viewed ,<https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/>
VANCOUVER
Omar Dulaimi | Sciencx - » How to automatically generate Joi schemas from your Prisma schema. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/
CHICAGO
" » How to automatically generate Joi schemas from your Prisma schema." Omar Dulaimi | Sciencx - Accessed . https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/
IEEE
" » How to automatically generate Joi schemas from your Prisma schema." Omar Dulaimi | Sciencx [Online]. Available: https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/. [Accessed: ]
rf:citation
» How to automatically generate Joi schemas from your Prisma schema | Omar Dulaimi | Sciencx | https://www.scien.cx/2022/04/15/how-to-automatically-generate-joi-schemas-from-your-prisma-schema/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.