extraModels: [...PrismaModel.extraModels] does not work
moh1434 opened this issue · 1 comments
moh1434 commented
I have:
import { User } from '@prisma/client';
import { User as UserClass } from './_gen/prisma-class/user';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('/users')
async getAll(): Promise<User[]> {
return (await this.appService.getAll()) as User[];
}
@Get('/users2')
async getAll2(): Promise<UserClass[]> {
return await this.appService.getAll();
}
}
And in main.ts:
const options = new DocumentBuilder()
.setTitle('nest example')
.setDescription('My nest API description')
.setVersion('1.0')
.addTag('myTag')
.build();
const document = SwaggerModule.createDocument(app, options, {
extraModels: [...PrismaModel.extraModels],
});
SwaggerModule.setup('api', app, document);
Expected Behavior
I expected swagger will display description response schema for both /users
and /users2
Actual Behavior
swagger works only for the explicitly imported generated class.
Steps to Reproduce the Problem
Clone This Repo and see localhost:300/api.
Specifications
- "prisma-class-generator": "^0.2.6"
- "@nestjs/swagger": "^6.3.0"
- Prisma Version: "prisma": "^4.11.0"
- Platform: mac m1
WilliamBlais commented
@moh1434 You need to decorate your Controller.
For example,
@ApiOkResponse({ type: UserClass, isArray:true })
@Get('/users2')
async getAll2(): Promise<UserClass[]> {
return await this.appService.getAll();
}