I have my Nest.js project and I use Prisma as ORM. Therefore, there is actually no need for me to use entities to communicate with database, but I still want to document those entities using Swagger.
For example file user.entity.ts
:
import { Users } from '@prisma/client';
import { ApiProperty } from '@nestjs/swagger';
export class UserEntity implements Users {
@ApiProperty()
id: string;
@ApiProperty()
firstName: string;
@ApiProperty()
lastName: string;
@ApiProperty()
...
Even though I export this class, I don't use it, because Prisma allows that. And the issue is that while it's not used somewhere (@Body
decorator, for instance), Swagger can't map this entity and therefore I don't see it in my documentation.
Is there a way to fix that?
Ok, here is why it happens. I have found the thread about the same issue.
Generally speaking, without getting into details, if your model/entity is not used somewhere, even though you mapped it with @ApiProperty()
, it won't be shown within documentation.
Therefore, I have used solution using @ApiExtraModels()
decorator and passed all DTOs.
Hope it was hopeful.