@@ -8,14 +8,15 @@ title: "Getting started"
88
99::: code-group
1010
11- ``` ts [users_controller.ts]
11+ ``` ts [users_controller.ts] twoslash
12+ // @noErrors
1213import { ApiOperation , ApiResponse } from " openapi-metadata/decorators" ;
1314import User from " ./user" ;
1415
1516class UsersController {
1617 @ApiOperation ({
17- method: " get" ,
18- pattern : " /users" ,
18+ methods: [ " get" ] ,
19+ path : " /users" ,
1920 summary: " List users"
2021 })
2122 @ApiResponse ({ type: [User ] })
@@ -25,7 +26,7 @@ class UsersController {
2526}
2627```
2728
28- ``` ts [user.ts]
29+ ``` ts [user.ts] twoslash
2930import { ApiProperty } from " openapi-metadata/decorators" ;
3031
3132class User {
@@ -40,7 +41,8 @@ class User {
4041}
4142```
4243
43- ``` ts [index.ts]
44+ ``` ts [index.ts] twoslash
45+ // @noErrors
4446import " reflect-metadata" ;
4547import { generateDocument } from " openapi-metadata" ;
4648import UsersController from " ./users_controller" ;
@@ -49,7 +51,7 @@ const document = await generateDocument({
4951 controllers: [UsersController ],
5052 document: {
5153 info: {
52- name : " My Api" ,
54+ title : " My Api" ,
5355 version: " 1.0.0" ,
5456 },
5557 },
@@ -109,21 +111,21 @@ To get started, you can use the `generateDocument` function to create an (almost
109111
110112::: code-group
111113
112- ``` ts [index.ts]
114+ ``` ts [index.ts] twoslash
113115import " reflect-metadata" ;
114116import { generateDocument } from " openapi-metadata" ;
115117
116- const builder = await generateDocument ({
118+ const document = await generateDocument ({
117119 controllers: [],
118120 document: {
119121 info: {
120- name : " My API" ,
122+ title : " My API" ,
121123 version: " 1.0.0" ,
122124 },
123125 },
124126});
125127
126- console .log (document . build () ); // <- Your generated OpenAPI specifications
128+ console .log (document ); // <- Your generated OpenAPI specifications
127129```
128130
129131:::
@@ -135,14 +137,15 @@ In the following example we have a `UsersController` which declares an operation
135137
136138::: code-group
137139
138- ``` ts [controllers/users_controller.ts]
140+ ``` ts [controllers/users_controller.ts] twoslash
141+ // @noErrors
139142import { ApiOperation , ApiResponse } from " openapi-metadata/decorators" ;
140143import User from " ../schemas/user" ;
141144
142145export default class UsersController {
143146 @ApiOperation ({
144- method: " get" ,
145- pattern : " /users" ,
147+ methods: [ " get" ] ,
148+ path : " /users" ,
146149 summary: " List users" ,
147150 })
148151 @ApiResponse ({ type: [User ] })
@@ -164,7 +167,7 @@ By using the `@ApiProperty` decorator on class we can define the properties of o
164167
165168::: code-group
166169
167- ``` ts [schemas/user.ts]
170+ ``` ts [schemas/user.ts] twoslash
168171import { ApiProperty } from " openapi-metadata/decorators" ;
169172
170173export default class User {
@@ -184,18 +187,19 @@ export default class User {
184187
185188:::
186189
187- ### Add the controller to the generated document
190+ ### Register your controller
188191
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.
190193
191194::: code-group
192195
193- ``` ts [index.ts]
196+ ``` ts [index.ts] twoslash
197+ // @noErrors
194198import " reflect-metadata" ;
195199import { generateDocument } from " openapi-metadata" ;
196200import UsersController from " ./controllers/users_controller.ts" ;
197201
198- const builder = await generateDocument ({
202+ const document = await generateDocument ({
199203 controllers: [UsersController ],
200204 document: {
201205 info: {
@@ -205,9 +209,7 @@ const builder = await generateDocument({
205209 },
206210});
207211
208- console .log (document . build () ); // <- Your generated OpenAPI specifications
212+ console .log (document ); // <- Your generated OpenAPI specifications
209213```
210214
211215:::
212-
213- ### Going further
0 commit comments