forked from lukeautry/tsoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleController.ts
193 lines (179 loc) · 4.54 KB
/
exampleController.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { Route, Get, Path, Query, Header, Post, Body, BodyProp, Example, Res, TsoaResponse } from '@tsoa/runtime';
import { exampleResponse } from './consts';
/**
* @example {
* "contry": "123",
* "city": "456"
* }
*/
export interface Location {
contry: string;
city: string;
}
@Route('ExampleTest')
export class ExampleTestController {
/**
* @example path "an_example_path"
* @example path "an_example_path2"
*/
@Get('/path/{path}')
public async path(@Path() path: string): Promise<void> {
return;
}
/**
* @example query "an_example_query"
* @example query "an_example_query2"
*/
@Get('/query')
public async query(@Query() query: string): Promise<void> {
return;
}
/**
* @example header "aaaaaaLongCookie"
* @example header "aaaaaaLongCookie2"
*/
@Get('/header')
public async header(@Header() header: string): Promise<void> {
return;
}
/**
* @example location {
* "contry": "1",
* "city": "1"
* }
* @example location {
* "contry": "2",
* "city": "2"
* }
*/
@Post('/post_body')
public async post(@Body() location: Location): Promise<void> {
return;
}
/**
* @example prop1 "prop1_1"
* @example prop1 "prop1_2"
* @example prop1 "prop1_3"
* @example prop2 "prop2_1"
* @example prop2 "prop2_2"
* @example prop2 "prop2_3"
*/
@Post('/post_body_prop')
public async postBodyProp(@BodyProp() prop1: string, @BodyProp() prop2: string): Promise<void> {
return;
}
/**
* @example location {
* "contry": "1",
* "city": "1"
* }
* @example location {
* "contry": "2",
* "city": "2"
* }
* @example s "aa0"
* @example s "aa1"
* @example s "aa2"
*/
@Post('/two_parameter/{s}')
public async twoParameter(@Body() location: Location, @Path() s: string): Promise<void> {
return;
}
/**
*
* @example locations [
* {
* "contry": "1",
* "city": "1"
* },
* {
* "contry": "2",
* "city": "2"
* }
* ]
* @example locations [
* {
* "contry": "22",
* "city": "22"
* },
* {
* "contry": "33",
* "city": "33"
* }
* ]
*/
@Post('/array_with_object')
public async arrayWithObject(@Body() locations: Location[]): Promise<void> {
return;
}
/**
* @param res The alternate response
* @example res 123
* @example res 1
*/
@Example<string>('test 1')
@Example<string>('test 2')
@Get('MultiResponseExamples')
public async responseExamples(@Res() res: TsoaResponse<400, number, { 'custom-header': string }>): Promise<string> {
res?.(400, 123, { 'custom-header': 'hello' });
return 'test 1';
}
/**
* @param res The alternate response
* @example res.NoSuchCountry { "errorMessage":"No such country", "errorCode": 40000 }
* @example res. { "errorMessage":"No custom label", "errorCode": 40000 }
* @example res "Unlabeled 1"
* @example res "Another unlabeled one"
* @example res.NoSuchCity {
* "errorMessage":"No such city",
* "errorCode": 40000
* }
* @example res { "errorMessage":"No custom label", "errorCode": 40000 }
*/
@Get('CustomExampleLabels')
public async customExampleLabels(@Res() res: TsoaResponse<400, number, { 'custom-header': string }>): Promise<string> {
res?.(400, 123, { 'custom-header': 'hello' });
return 'test 1';
}
/**
* @example requestBody.CustomLabel "CustomLabel"
* @example requestBody. "No Custom Label"
* @example requestBody "Unlabeled 1"
* @example requestBody "Another unlabeled one"
* @example requestBody.CustomLabel2 "CustomLabel2"
* @example requestBody "Unlabeled 2"
*/
@Post('CustomBodyExampleLabels')
public async customBodyExampleLabels(@Body() requestBody: string): Promise<string> {
return 'test custom body labels';
}
/**
* @example res 123
* @example res 1
*/
@Example<string>(exampleResponse)
@Get('ResponseExampleWithImportedValue')
public async responseExamplesWithImportedValue(): Promise<string> {
return 'test 1';
}
/**
* @example res 123
* @example res 1
*/
@Example<string>(exampleResponse, 'Custom_label')
@Get('ResponseExampleWithLabel')
public async responseExamplesWithLabel(): Promise<string> {
return 'test 1';
}
/**
* @example res 123
* @example res 1
*/
@Example<string>(exampleResponse, 'OneExample')
@Example<string>('another example', 'AnotherExample')
@Example<string>('no label example')
@Get('ResponseMultiExampleWithLabel')
public async responseMultiExampleWithLabel(): Promise<string> {
return 'test 1';
}
}