Development: https://test.f.jobelhome.com/apiDocs
Production: https://f.jobelhome.com/apiDocs
Production direct link:
please remove it, if the link above will be redirected to production instead of test environment.
Purpose: Groups endpoints into categories in the Swagger UI for better organization and readability.
Usage: Place it above a controller class to tag all endpoints within that controller.
import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
@ApiTags('cats')
@Controller('cats')
export class CatsController {
@Get()
findAll(): string {
return 'This action returns all cats';
}
}
Purpose: Provides a short description for an endpoint's operation in the documentation.
Usage: Place it above an endpoint handler to describe its purpose.
import { Controller, Get } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
@Controller('cats')
export class CatsController {
@Get()
@ApiOperation({ summary: 'Find all cats' })
findAll(): string {
return 'This action returns all cats';
}
}
Purpose: Documents the possible responses that an endpoint can return.
Usage: Place it above an endpoint handler to describe the response structure and status code.
import { Controller, Get } from '@nestjs/common';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
@ApiTags('cats')
@Controller('cats')
export class CatsController {
@Get()
@ApiResponse({
status: 200,
description: 'The found record',
schema: {
example: { id: 1, name: 'Cat', breed: 'Bengal', age: 5 },
},
})
findAll() {
return [{ id: 1, name: 'Cat', breed: 'Bengal', age: 5 }];
}
}
Purpose: Describes a model's property in the request or response body.
Usage: Place it within a DTO (Data Transfer Object) class to annotate model properties.
import { ApiProperty } from '@nestjs/swagger';
export class CreateCatDto {
@ApiProperty({ example: 'Whiskers', description: 'The name of the cat' })
name: string;
@ApiProperty({ example: 'Tabby', description: 'The breed of the cat' })
breed: string;
@ApiProperty({ example: 3, description: 'The age of the cat' })
age: number;
}
Purpose: Indicates that an endpoint is protected by bearer token authentication.
Usage: Place it above an endpoint or a controller to signify authentication requirements.
import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
@ApiBearerAuth()
@ApiTags('cats')
@Controller('cats')
export class CatsController {
@UseGuards(AuthGuard('jwt'))
@Get()
findAll(): string {
return 'This action returns all cats, but only for authenticated users';
}
}