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

问题描述 投票:0回答:2

some-dto.ts

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

      @ApiProperty()
      age: number;

      @ApiProperty()
      breed: string;
    }

我不想回复这样的内容:

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

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

    ApiOkResponse(
          description: 'The record has been successfully removed.',
          schema: {
            type: 'array',
            properties: {
              obj: {
                type: CreateCatDto
              }
            }
          }
        )
nestjs nestjs-swagger
2个回答
0
投票

您是否尝试过这样的事情:

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

让我知道是否有帮助


0
投票

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

@ApiOkResponse(
  description: 'Cat object',
  type: [CreateCatDto]
)
© www.soinside.com 2019 - 2024. All rights reserved.