0

NestJS exposes entity/DTO classes decorated with @ApiProperty to Swagger UI schemas. CLI Plugin automates it for all class files by default with suffixes ['.dto.ts', '.entity.ts']. Prisma schema, unfortunately, is not defined in terms of class thus cannot be decorated.

Without violating DRY principle by duplicating Prisma schema in another format, be it class or raw OpenAPI specs, how to expose it to swagger UI?

abbr
  • 5,361
  • 6
  • 30
  • 44

1 Answers1

1

Actually, Lot of people asked Prisma about this, their team is aware of this "problem", but for what I could see they didn't plan to work on it at the moment

Until this feature come out, you will have to use a tool to generate your DTOs directly from your schema : https://github.com/robblovell/prisma-generator-nestjs

Then you can use the integrated swagger cli provided with nestjs : https://docs.nestjs.com/openapi/cli-plugin

It will add the decorator to your DTOs

I think this can be automatised with a script, so you can run it every time you update your prisma schema to sync it with your DTOs

Hope it's help

Valentin
  • 56
  • 5
  • Thanks for suggesting prisma-generator-nestjs. It's certainly not satisfactory but in absent of a better one, I'll accept it as answer for now. – abbr Aug 31 '23 at 16:35