1Package.json
2"tsoa": "^3.5.1",
3"docs": "npx tsoa spec",
41.1 Add /tsoa.json
5
6{
7 "spec": {
8 "outputDirectory": "./docs/swagger-ui",
9 "host": "localhost:3600",
10 "basePath": "/v1",
11 "securityDefinitions": {
12 "token": {
13 "type": "apiKey",
14 "in": "header",
15 "name": "Authorization"
16 }
17 },
18 "yaml": true,
19 "specVersion": 2
20 },
21 "noImplicitAdditionalProperties": "throw-on-extras",
22 "controllerPathGlobs": ["src/routes/v1/documentation/*.controller.ts"],
23 "routes": {
24 "basePath": "",
25 "entryFile": "./src/server.ts",
26 "routesDir": "./src"
27 }
28}
29On the services files
30import { Get, Query, Route, Controller, Tags, Put } from 'tsoa';
31@Tags('user')
32@Route('users')
33class UsersRouteDocs extends Controller {
34 /**
35 * This endpoint returns all users
36 *
37 *
38 */
39 @Get('/')
40 public getUsers(@Query('query') query?: string): ReadUserDto[] {
41 return UsersService.getUsers({ query } as any) as any;
42 }
43
44 /**
45 * This endpoint returns the user session
46 *
47 *
48 */
49 @Get('/active-session')
50 public getActiveSession(): any {
51 return UsersService.getActiveSession({} as any) as any;
52 }
53
54 /**
55 * This endpoint returns the user state
56 *
57 *
58 */
59 @Get('/state')
60 public getUserState(): string[] {
61 return UsersService.getUserState({} as any) as any;
62 }
63
64 /**
65 * This endpoint changes the user state to available
66 *
67 *
68 */
69 @Put('/set-available')
70 public setUserState(): { status: string } {
71 return UsersService.setUserAvailable({
72 user: {
73 __id: '',
74 },
75 } as any) as any;
76 }
77
78 /**
79 * This endpoint returns a users, by id
80 *
81 *
82 */
83 @Get('/:id')
84 public getUserById(@Query(':id') id?: string): ReadUserDto {
85 return UsersService.getUserById(id) as any;
86 }
87Output
88docs/swagger-ui/swagger.yaml
Created on 2/8/2021