-
Notifications
You must be signed in to change notification settings - Fork 504
/
methodController.ts
179 lines (154 loc) · 5.01 KB
/
methodController.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
import { Controller, Extension, Options, Delete, Get, Patch, Post, Put, Response, Route, Security, SuccessResponse, Tags, Example } from '@tsoa/runtime';
import { ModelService } from '../services/modelService';
import { ErrorResponseModel, TestModel, TestModel as RenamedModel } from '../testModel';
const TEST_OBJECT_CONST = {
unAuthCode: '401',
unAuthText: 'Unauthorized',
success: 'Created',
} as const;
enum TEST_ENUM_CODES {
BAD = 400,
NOT_FOUND = '404',
SUCCESS = 201,
}
enum TEST_ENUM {
BAD = 'Bad Request',
NOT_FOUND = 'Not Found',
SECURITY = 'JWT2',
ADMIN = 'permission:admin',
OWNER = 'permission:owner',
TAG = 'EnumTag1',
}
const TEST_SEC = {
firstSec: [],
secondSec: [TEST_ENUM.ADMIN, TEST_ENUM.OWNER],
};
const ATT_KEY9 = 'x-attKey9';
@Route('MethodTest')
@Tags('MethodTest')
export class MethodController extends Controller {
@Options('Options')
public async optionsMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
@Get('Get')
public async getMethod(): Promise<RenamedModel> {
return new ModelService().getModel();
}
@Post('Post')
public async postMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
@Patch('Patch')
public async patchMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
@Put('Put')
public async putMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
@Delete('Delete')
public async deleteMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
/**
* method description
*/
@Get('Description')
public async description(): Promise<TestModel> {
return new ModelService().getModel();
}
@Tags('Tag1', 'Tag2', 'Tag3')
@Get('Tags')
public async tags(): Promise<TestModel> {
return new ModelService().getModel();
}
@Response<ErrorResponseModel>('400', 'Bad Request', { status: 400, message: 'reason 1' })
@Response<ErrorResponseModel>('400', 'Bad Request', { status: 400, message: 'reason 2' })
@Response<ErrorResponseModel>('401', 'Unauthorized')
@Response<ErrorResponseModel>('default', 'Unexpected error', { status: 500, message: 'Something went wrong!' })
@Get('MultiResponse')
public async multiResponse(): Promise<TestModel> {
return new ModelService().getModel();
}
@Tags(TEST_ENUM.TAG)
@Security(TEST_ENUM.SECURITY, [TEST_ENUM.ADMIN, TEST_ENUM.OWNER])
@Security(TEST_SEC)
@Response<ErrorResponseModel>(TEST_OBJECT_CONST.unAuthCode, TEST_OBJECT_CONST.unAuthText)
@Response<ErrorResponseModel>(TEST_ENUM_CODES.BAD, TEST_ENUM.BAD)
@Response<ErrorResponseModel>(TEST_ENUM_CODES.NOT_FOUND, TEST_ENUM.NOT_FOUND)
@SuccessResponse(TEST_ENUM_CODES.SUCCESS, TEST_OBJECT_CONST.success)
@Get('DecoratorVariousValues')
public async decoratorVariousValues(): Promise<TestModel> {
return new ModelService().getModel();
}
@SuccessResponse('201', 'Created')
@Get('SuccessResponse')
public async successResponse(): Promise<void> {
this.setStatus(201);
return Promise.resolve();
}
@Security('api_key')
@Get('ApiSecurity')
public async apiSecurity(): Promise<TestModel> {
return new ModelService().getModel();
}
@Security('tsoa_auth', ['write:pets', 'read:pets'])
@Get('OauthSecurity')
public async oauthSecurity(): Promise<TestModel> {
return new ModelService().getModel();
}
@Security('tsoa_auth', ['write:pets', 'read:pets'])
@Security('api_key')
@Get('OauthOrApiKeySecurity')
public async oauthOrAPIkeySecurity(): Promise<TestModel> {
return new ModelService().getModel();
}
@Security({
api_key: [],
tsoa_auth: ['write:pets', 'read:pets'],
})
@Get('OauthAndApiKeySecurity')
public async oauthAndAPIkeySecurity(): Promise<TestModel> {
return new ModelService().getModel();
}
/**
* @deprecated
*/
@Get('DeprecatedMethod')
public async deprecatedMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
/**
* @summary simple summary
*/
@Get('SummaryMethod')
public async summaryMethod(): Promise<TestModel> {
return new ModelService().getModel();
}
@Get('returnAnyType')
public async returnAnyType(): Promise<any> {
return 'Hello Word';
}
@Example(undefined)
@Get('returnAliasedVoidType')
public async returnAliasedVoidType(): Promise<VoidAlias1> {
return;
}
@Extension('x-attKey', 'attValue')
@Extension('x-attKey1', 123)
@Extension('x-attKey2', true)
@Extension('x-attKey3', null)
@Extension('x-attKey4', { test: 'testVal' })
@Extension('x-attKey5', ['y0', 'y1', 123, true, null])
@Extension('x-attKey6', [{ y0: 'yt0', y1: 'yt1', y2: 123, y3: true, y4: null }, { y2: 'yt2' }])
@Extension('x-attKey7', { test: ['testVal', 123, true, null] })
@Extension('x-attKey8', { test: { testArray: ['testVal1', true, null, ['testVal2', 'testVal3', 123, true, null]] } })
@Extension(ATT_KEY9, 'identifierAttValue')
@Get('Extension')
public async extension(): Promise<TestModel> {
return new ModelService().getModel();
}
}
type VoidAlias1 = VoidAlias2;
type VoidAlias2 = void;