Decorators for Controllers and HTTP Responses

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

  • @ApiTags

  • @ApiResponse

To document your controllers and separate them from others, you can use the @ApiTags property:

Example @ApiTags code

By using @ApiTags on different controllers you can separate all endpoints via the tag you declared.

Example:

Example @ApiTags - Swagger Interface.

By not using the @ApiTags property in your controllers, they will be grouped under the default tag.

Default @ApiTags

@ApiResponse

To document the responses of each of your endpoints, you can use the @ApiResponse decorator. For example, if there is a response that can occur on any endpoint, you can use this decorator at the controller level, so that all endpoints inherit this property:

Response example
Swagger - Response example

@ApiResponse Properties

You can use the following properties for the @ApiResponse decorator:

  • status: HTTP code of the response.

  • type: If you have a class where you have defined the response, here you can place the class name.

Example:

You can see the configuration of the NotificationCategories class here.

@Get('notification-categories')
@ApiResponse({
  status: 200,
  type: NotificationCategories,
  description: 'Successfuly operation.',
})
public getNotificationCategories() {
  return this.communicationService.getNotificationCategories();
}
  • description: you can use this field to give a brief description of the endpoint.

  • schema: if you don't have a class with the response defined or you use dynamic messages, your best bet is to declare the response example in the schema field.

Last updated

Was this helpful?