0

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.

enter image description here

How can I show the content field in the correct format here?

Ping Zhao
  • 266
  • 5
  • 19

1 Answers1

1

you should declare that content like this:

  @ApiProperty({ type: [WoopStatementDto] })
  // @ApiProperty({ type: WoopStatementDto, isArray: true }) 
  @ValidateNested({ each: true })
  @Type(() => WoopStatementDto)
  @IsArray()
  content: WoopStatementDto[];
Micael Levi
  • 5,054
  • 2
  • 16
  • 27