typescriptswaggernestjsopenapinestjs-swagger

NestJs Swagger: How to define Api Property for dynamic classes


I have below class

export class DocumentsSteps {
    @ApiProperty({type: ???})
    [type: string]: DocumentStep;
}

How should I define ApiProperty type?


Solution

  • As of right now (9/21/2021), this isn't possible with Nest's @nestjs/swagger library, due to the fact that there's no field to reflect metadata on. There may be an opportunity to open a pull request to allow for the use of dictionaries with the library, but right now your best bet would be modifying the swagger document that Nest generates and adding it on your own at the moment