# ReturnsArray Decorator

Module
import { ReturnsArray } from "@tsed/swagger/src/decorators/returnsArray"
Source/packages/swagger/src/decorators/returnsArray.ts

# Overview

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

# Description

Add responses documentation for a specific status code.

# 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