# ReturnsArray Decorator swagger operation response

Module
import { ReturnsArray } from "@tsed/common"
Source/packages/common/src/mvc/decorators/method/returnType.ts

# Overview

function ReturnsArray(statusCode: number, options: Partial<IResponseOptions>): any;
export function ReturnsArray(statusCode: number, model: Type<any>): any;
export function ReturnsArray(options: Partial<IResponseOptions>): any;
export function ReturnsArray(model: Type<any>): any;
export function ReturnsArray(model: Type<any>, options: Partial<IResponseOptions>): any;
Param Type Description
statusCode number Code status options

# Description

Add responses documentation for a specific status code.

WARNING

This decorator will be removed in v6 in favor of from @tsed/schema. For v5 user, use decorator from @tsed/common then in v6 switch to @Returns(Array).Of(User) from @tsed/schema.

# Examples

# With status code

 @ReturnsArray(200, {description: "OK", type: Model})
 async myMethod(): Promise<Model>  {

 }
1
2
3
4

This example will produce this documentation in swagger:

{
  "responses": {
    "2OO": {
      "description": "Description",
      "schema": {"type": "array"}
    }
  }
}
1
2
3
4
5
6
7
8

# Without status code

ReturnsArray can be use without status code. In this case, the response will be added to the default status code (200 or the status code seated with @Status).

 @ReturnsArray({description: "Description"})
 async myMethod(): Promise<Model>  {

 }
1
2
3
4

This example will produce this documentation in swagger:

{
  "responses": {
    "200": {
      "description": "Description",
      "schema": {"type": "array"}
    }
  }
}
1
2
3
4
5
6
7
8

# With type schema

ReturnsArray accept another signature with a type.

 @ReturnsArray(Model, {description: "Description"}) //OR
 @ReturnsArray(Model)
 async myMethod(): Promise<Model>  {

 }
1
2
3
4
5

This example will produce this documentation in swagger:

{
  "responses": {
    "200": {
      "description": "Description",
      "schema": {
        "type": "array",
        "items": {
          $ref: "Model"
        }
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13