Creating API documentation in NestJS is streamlined through the use of decorators to annotate your routing handlers and data transfer objects (DTOs). Below is a simplified example based on your provided code snippet:
@ApiTags('Booking')
@ApiBearerAuth('JWT')
@Controller('bookings')
export class BookingController {

  @ApiCreatedResponse({ description: 'Resource successfully returned.' })
  @ApiForbiddenResponse({ description: 'Forbidden resource.' })
  @ApiOperation({
    summary: 'Get all bookings for requested user',
  })
  @Get('/me')
  async get(@Req() req: Request) {
    // ... method implementation
  }
}

Explanation:

  • @ApiTags('Booking'): Groups endpoints under the ‘Booking’ tag in the Swagger UI.
  • @ApiBearerAuth('JWT'): Indicates that this route requires JWT bearer authentication.
  • @Controller('bookings'): Defines a controller with a base route of ‘/bookings’.
  • @ApiCreatedResponse, @ApiForbiddenResponse: Describe the possible responses that the endpoint could return. @ApiCreatedResponse is used for successful responses, while @ApiForbiddenResponse is used for forbidden responses.
  • @ApiOperation: Provides additional information about the operation such as a summary.
  • @Get('/me'): Defines a GET route on the path ‘/bookings/me’.
Ensure to define your data transfer objects (DTOs) with appropriate decorators to document the shape of the data. For more comprehensive guidance, refer to the NestJS documentation on OpenAPI (Swagger).