I am creating api using NestJS and making the api documentation using swagger. Following code snippet is showing my dto definition.
export class CreateWoopDto {
@ApiProperty()
@IsUUID()
user_id: string;
@ApiProperty()
@ValidateNested({ each: true })
@Type(() => WoopStatementDto)
@IsArray()
content: WoopStatementDto[];
}
export class WoopStatementDto {
@ApiProperty()
@IsString()
if: string;
@ApiProperty()
@IsString()
then: string;
}
In my POST/ createWoop
endpoint, I am using this Dto, and in my swagger doc, the request body format for this endpoint is not working as I expected.
How can I show the content field in the correct format here?
you should declare that content
like this:
@ApiProperty({ type: [WoopStatementDto] })
// @ApiProperty({ type: WoopStatementDto, isArray: true })
@ValidateNested({ each: true })
@Type(() => WoopStatementDto)
@IsArray()
content: WoopStatementDto[];