Skip to content

docs(@nestjs/swagger): document description support in @ApiSchema #3157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion content/openapi/types-and-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pets: Pet[];

Both `Cat` and `Dog` must be defined as extra models using the `@ApiExtraModels()` decorator (at the class-level).

#### Schema name
#### Schema name and description

As you may have noticed, the name of the generated schema is based on the name of the original model class (for example, the `CreateCatDto` model generates a `CreateCatDto` schema). If you'd like to change the schema name, you can use the `@ApiSchema()` decorator.

Expand All @@ -357,3 +357,19 @@ class CreateCatDto {}
```

The model above will be translated into the `CreateCatRequest` schema.

By default, no description is added to the generated schema. You can add one using the `description` attribute:

```typescript
@ApiSchema({ description: 'Description of the CreateCatDto schema' })
class CreateCatDto {}
```

That way, the description will be included in the schema, as follows:

```yaml
schemas:
CreateCatDto:
type: object
description: Description of the CreateCatDto schema
```