Skip to content

Commit 11700ef

Browse files
docs: update swagger docs
1 parent f523bd1 commit 11700ef

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

content/openapi/cli-plugin.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ You must duplicate both description and example values. With `introspectComments
9191
roles: RoleEnum[] = [];
9292
```
9393

94-
There are `dtoKeyOfComment` and `controllerKeyOfComment` plugin options that you can use to customize how the plugin will set the value for `ApiProperty` and `ApiOperation` decorators respectively. Take a look at the following example:
94+
There are `dtoKeyOfComment` and `controllerKeyOfComment` plugin options available for customizing how the plugin assigns values to the `ApiProperty` and `ApiOperation` decorators, respectively. See the example below:
9595

9696
```typescript
9797
export class SomeController {
@@ -103,13 +103,29 @@ export class SomeController {
103103
}
104104
```
105105

106-
By default, these options are set to `"description"`. This means the plugin will assign `"Create some resource"` to `description` key on the `ApiOperation` operator. Like so:
106+
This is equivalent to the following instruction:
107107

108-
```ts
109-
@ApiOperation({ description: "Create some resource" })
108+
```typescript
109+
@ApiOperation({ summary: "Create some resource" })
110110
```
111111

112-
> info **Hint** For models, the same logic applies but to `ApiProperty` decorator instead.
112+
> info **Hint** For models, the same logic applies but is used with the `ApiProperty` decorator instead.
113+
114+
For controllers, you can provide not only a summary but also a description (remarks), tags (such as` @deprecated`), and response examples, like this:
115+
116+
```ts
117+
/**
118+
* Create a new cat
119+
*
120+
* @remarks This operation allows you to create a new cat.
121+
*
122+
* @deprecated
123+
* @throws {500} Something went wrong.
124+
* @throws {400} Bad Request.
125+
*/
126+
@Post()
127+
async create(): Promise<Cat> {}
128+
```
113129

114130
#### Using the CLI plugin
115131

@@ -180,11 +196,11 @@ export interface PluginOptions {
180196
</tr>
181197
<tr>
182198
<td><code>controllerKeyOfComment</code></td>
183-
<td><code>'description'</code></td>
199+
<td><code>'summary'</code></td>
184200
<td>The property key to set the comment text to on <code>ApiOperation</code>.</td>
185201
</tr>
186202
<tr>
187-
<td><code>introspectComments</code></td>
203+
<td><code>introspectComments</code></td>
188204
<td><code>false</code></td>
189205
<td>If set to true, plugin will generate descriptions and example values for properties based on comments</td>
190206
</tr>

content/openapi/introduction.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ export interface SwaggerDocumentOptions {
123123
* @default () => controllerKey_methodKey
124124
*/
125125
operationIdFactory?: (controllerKey: string, methodKey: string) => string;
126+
127+
/*
128+
* Generate tags automatically based on the controller name.
129+
* If `false`, you must use the `@ApiTags()` decorator to define tags.
130+
* Otherwise, the controller name without the suffix `Controller` will be used.
131+
*
132+
* @default true
133+
*/
134+
autoTagControllers?: boolean;
126135
}
127136
```
128137

content/openapi/types-and-parameters.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ breed: string;
230230

231231
#### Raw definitions
232232

233-
In some specific scenarios (e.g., deeply nested arrays, matrices), you may want to describe your type by hand.
233+
In certain cases, such as deeply nested arrays or matrices, you may need to manually define your type:
234234

235235
```typescript
236236
@ApiProperty({
@@ -245,7 +245,27 @@ In some specific scenarios (e.g., deeply nested arrays, matrices), you may want
245245
coords: number[][];
246246
```
247247

248-
Likewise, in order to define your input/output content manually in controller classes, use the `schema` property:
248+
You can also specify raw object schemas, like this:
249+
250+
```typescript
251+
@ApiProperty({
252+
type: 'object',
253+
properties: {
254+
name: {
255+
type: 'string',
256+
example: 'Error'
257+
},
258+
status: {
259+
type: 'number',
260+
example: 400
261+
}
262+
},
263+
required: ['name', 'status']
264+
})
265+
rawDefinition: Record<string, any>;
266+
```
267+
268+
To manually define input/output content in controller classes, use the `schema` property:
249269

250270
```typescript
251271
@ApiBody({

0 commit comments

Comments
 (0)