NestJs Swagger: How to define Api Property for dynamic classes

Issue

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

Answered By – Jay McDoniel

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.