@@ -8,14 +8,15 @@ title: "Getting started"
8
8
9
9
::: code-group
10
10
11
- ``` ts [users_controller.ts]
11
+ ``` ts [users_controller.ts] twoslash
12
+ // @noErrors
12
13
import { ApiOperation , ApiResponse } from " openapi-metadata/decorators" ;
13
14
import User from " ./user" ;
14
15
15
16
class UsersController {
16
17
@ApiOperation ({
17
- method: " get" ,
18
- pattern : " /users" ,
18
+ methods: [ " get" ] ,
19
+ path : " /users" ,
19
20
summary: " List users"
20
21
})
21
22
@ApiResponse ({ type: [User ] })
@@ -25,7 +26,7 @@ class UsersController {
25
26
}
26
27
```
27
28
28
- ``` ts [user.ts]
29
+ ``` ts [user.ts] twoslash
29
30
import { ApiProperty } from " openapi-metadata/decorators" ;
30
31
31
32
class User {
@@ -40,7 +41,8 @@ class User {
40
41
}
41
42
```
42
43
43
- ``` ts [index.ts]
44
+ ``` ts [index.ts] twoslash
45
+ // @noErrors
44
46
import " reflect-metadata" ;
45
47
import { generateDocument } from " openapi-metadata" ;
46
48
import UsersController from " ./users_controller" ;
@@ -49,7 +51,7 @@ const document = await generateDocument({
49
51
controllers: [UsersController ],
50
52
document: {
51
53
info: {
52
- name : " My Api" ,
54
+ title : " My Api" ,
53
55
version: " 1.0.0" ,
54
56
},
55
57
},
@@ -109,21 +111,21 @@ To get started, you can use the `generateDocument` function to create an (almost
109
111
110
112
::: code-group
111
113
112
- ``` ts [index.ts]
114
+ ``` ts [index.ts] twoslash
113
115
import " reflect-metadata" ;
114
116
import { generateDocument } from " openapi-metadata" ;
115
117
116
- const builder = await generateDocument ({
118
+ const document = await generateDocument ({
117
119
controllers: [],
118
120
document: {
119
121
info: {
120
- name : " My API" ,
122
+ title : " My API" ,
121
123
version: " 1.0.0" ,
122
124
},
123
125
},
124
126
});
125
127
126
- console .log (document . build () ); // <- Your generated OpenAPI specifications
128
+ console .log (document ); // <- Your generated OpenAPI specifications
127
129
```
128
130
129
131
:::
@@ -135,14 +137,15 @@ In the following example we have a `UsersController` which declares an operation
135
137
136
138
::: code-group
137
139
138
- ``` ts [controllers/users_controller.ts]
140
+ ``` ts [controllers/users_controller.ts] twoslash
141
+ // @noErrors
139
142
import { ApiOperation , ApiResponse } from " openapi-metadata/decorators" ;
140
143
import User from " ../schemas/user" ;
141
144
142
145
export default class UsersController {
143
146
@ApiOperation ({
144
- method: " get" ,
145
- pattern : " /users" ,
147
+ methods: [ " get" ] ,
148
+ path : " /users" ,
146
149
summary: " List users" ,
147
150
})
148
151
@ApiResponse ({ type: [User ] })
@@ -164,7 +167,7 @@ By using the `@ApiProperty` decorator on class we can define the properties of o
164
167
165
168
::: code-group
166
169
167
- ``` ts [schemas/user.ts]
170
+ ``` ts [schemas/user.ts] twoslash
168
171
import { ApiProperty } from " openapi-metadata/decorators" ;
169
172
170
173
export default class User {
@@ -184,18 +187,19 @@ export default class User {
184
187
185
188
:::
186
189
187
- ### Add the controller to the generated document
190
+ ### Register your controller
188
191
189
- Now that we have our controller ready, we can use it to generate our document.
192
+ Now that we have our controller ready, we can include it when generating our document.
190
193
191
194
::: code-group
192
195
193
- ``` ts [index.ts]
196
+ ``` ts [index.ts] twoslash
197
+ // @noErrors
194
198
import " reflect-metadata" ;
195
199
import { generateDocument } from " openapi-metadata" ;
196
200
import UsersController from " ./controllers/users_controller.ts" ;
197
201
198
- const builder = await generateDocument ({
202
+ const document = await generateDocument ({
199
203
controllers: [UsersController ],
200
204
document: {
201
205
info: {
@@ -205,9 +209,7 @@ const builder = await generateDocument({
205
209
},
206
210
});
207
211
208
- console .log (document . build () ); // <- Your generated OpenAPI specifications
212
+ console .log (document ); // <- Your generated OpenAPI specifications
209
213
```
210
214
211
215
:::
212
-
213
- ### Going further
0 commit comments