Decorators for Requests and Responses

To document your requests and responses you can use the following decorators:

  • @ApiProperty

  • @ApiPropertyOptional

By using these decorators on each of the class properties, you have to document each of them.

This is an example of what a documented request body looks like:

import { ApiProperty } from '@nestjs/swagger';

export class NotificationCategoryDto {
  @ApiProperty({
    name: 'name',
    type: String,
    required: true,
    example: 'Accounts',
  })
  name: string;
}
Swagger Interface.

If you want to document your API responses, you should also use decorators to make them visible in the Swagger interface.

Example:

Swagger Interface > Response example.

βœ… Correct:

❌ Incorrect:

Last updated

Was this helpful?