-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
header.ts
61 lines (59 loc) · 1.44 KB
/
header.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {isString} from "@tsed/core";
import {JsonHeader, JsonHeaders} from "../../interfaces/JsonOpenSpec";
import {Returns} from "./returns";
/**
* Sets the response’s HTTP header field to value. To set multiple fields at once, pass an object as the parameter.
*
* ```typescript
* @Header('Content-Type', 'text/plain');
* private myMethod() {}
*
* @Status(204)
* @Header({
* "Content-Type": "text/plain",
* "Content-Length": 123,
* "ETag": {
* "value": "12345",
* "description": "header description"
* }
* })
* private myMethod() {}
* ```
*
* This example will produce the swagger responses object:
*
* ```json
* {
* "responses": {
* "204": {
* "description": "Description",
* "headers": {
* "Content-Type": {
* "type": "string"
* },
* "Content-Length": {
* "type": "number"
* },
* "ETag": {
* "type": "string",
* "description": "header description"
* }
* }
* }
* }
* }
* ```
*
* @decorator
* @operation
* @response
*/
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): Function {
if (value !== undefined) {
headers = {[headers as string]: value};
}
if (value === undefined && isString(headers)) {
headers = {[headers as string]: {type: "string"}};
}
return Returns().Headers(headers as JsonHeaders);
}