Search code examples
javascriptswaggernestjsopenapi

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.


Solution

  • 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