简体   繁体   中英

NestJS/swagger: what model is the ApiExtraModel expecting as a parameter?

The @nestjs/swagger doc describes here that defining an extra model should be done this way:

@ApiExtraModels(ExtraModel)
export class CreateCatDto {}

But what is ExtraModel here? The doc is not very clear about this.

Worked for me, when I've set @ApiExtraModels(MyModelClass) on the top of controller.

Thanks for this topic and also to this comment in GitHub issue.

I don't want to list all models in extraModels array in SwaggerModule.createDocument, so this is a great solution for me.

I ran into the same uncertainity. After googling https://github.com/nestjs/swagger/pull/355/files I understood the documentation:

  • first import your model to be referred to by import { ExtraModel } from '<filename>' (<--- so this is lacking in the docs BTW)
  • then provide it as param 'ExtraModel' to the decorator
  • the decorator then decorates the class which refers to the model (so providing the reference)

I guess you had the same mind-twister as me that the ApiExtraModels -decorator acts on the model...

Cheers, Stephan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM