nestjsnestjs-swagger

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


some-dto.ts

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

      @ApiProperty()
      age: number;

      @ApiProperty()
      breed: string;
    }

I don't want response something like this:

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

but my response must be array of like dto objects. I want smth like soo

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

Solution

  • have you tried something like this:

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

    Let me know if it helps