# Returns Decorator operation response
Module | import { Returns } from "@tsed/common" |
---|---|
Source | /packages/common/src/mvc/decorators/method/returnType.ts |
# Overview
function Returns(statusCode: number, options: Partial<IResponseOptions>): any;
export function Returns(statusCode: number, model: Type<any>): any;
export function Returns(options: Partial<IResponseOptions>): any;
export function Returns(model: Type<any>): any;
export function Returns(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 @tsed/schema.
# Examples
# With status code
@Returns(404, {description: "Not found"})
@Returns(200, {description: "OK", type: Model})
async myMethod(): Promise<Model> {
}
1
2
3
4
5
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
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
2
3
4
This example will produce this documentation in swagger:
{
"responses": {
"200": {
"description": "Description"
}
}
}
1
2
3
4
5
6
7
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
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
2
3
4
5
6
7
8
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing