如何使用 DTO 将响应设置为 swagger 响应中的数组

how to set the response to be an array in the swagger response using DTOs

一些-dto.ts

    export class CreateCatDto {
      @ApiProperty()
      name: string;

      @ApiProperty()
      age: number;

      @ApiProperty()
      breed: string;
    }

我不想要这样的回复:

  @ApiOkResponse(
      description: 'Cat object',
      type: CreateCatDto
    )

但我的回应必须是类似 dto 对象的数组。 我想要soo这样的东西

    ApiOkResponse(
          description: 'The record has been successfully removed.',
          schema: {
            type: 'array',
            properties: {
              obj: {
                type: CreateCatDto
              }
            }
          }
        )

你有没有尝试过这样的事情:

@ApiOkResponse(
    description: 'Cat object',
    type: CreateCatDto,
    isArray: true // <= diff is here
)

如果有帮助请告诉我

我找到了另一个解决方案,我们可以像这样包装在数组中

@ApiOkResponse(
  description: 'Cat object',
  type: [CreateCatDto]
)