# Returns Decorator

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

# Overview

function Returns(statusCode: number, options: ISwaggerResponses): any;
function Returns(options: ISwaggerResponses): any;
function Returns(model: Type<any>): any;
function Returns(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

 @Returns(404, {description: "Not found"})
 @Returns(200, {description: "OK", type: Model})
 async myMethod(): Promise<Model>  {

 }
1
2
3
4
5

This example will produce this documentation in swagger:

{
  "responses": {
    "404": {
      "description": "Description"
    },
    "2OO": {
      "description": "Description",
      "schema": {"schemaOfModel": "..."}
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11

# Without status code

Returns 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).

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

 }
1
2
3
4

This example will produce this documentation in swagger:

{
  "responses": {
    "200": {
      "description": "Description"
    }
  }
}
1
2
3
4
5
6
7

# With type schema

Returns accept another signature with a type.

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

 }
1
2
3
4
5

This example will produce this documentation in swagger:

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