Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • NestJS Documentation21টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • Installation
  • Modules
  • Controllers
  • Providers & DI
  • Pipes
  • Guards
  • Interceptors
  • Exception Handling
  • Middleware
  • Database
  • Authentication
  • Config & Env
  • File Upload
  • WebSockets
  • Microservices
  • Swagger
  • Testing
  • Best Practices
  • Project
  • Interview
  1. Docs
  2. NestJS
  3. NestJS Swagger (OpenAPI)
NestJSIntermediate

NestJS Swagger (OpenAPI)

@nestjs/swagger setup, decorators, DTO binding, production — API documentation বাংলায়।

12টি অংশবাংলা ভাষায়

Swagger/OpenAPI দিয়ে automatic interactive API documentation তৈরি হয় — বড় project-এ 매우 গুরুত্বপূর্ণ।

Setup

npm i @nestjs/swagger
main.tstypescript
typescript
import { NestFactory } from "@nestjs/core";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle("Nest API")
    .setDescription("Tech Tutor API documentation")
    .setVersion("1.0")
    .addBearerAuth() // JWT authorization
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup("api", app, document); // /api-এ docs

  await app.listen(3000);
}
bootstrap();

DTO-তে Swagger Decorator

create-user.dto.tstypescript
typescript
import { ApiProperty } from "@nestjs/swagger";
import { IsEmail, IsString, MinLength } from "class-validator";

export class CreateUserDto {
  @ApiProperty({ example: "রহিম", description: "User নাম" })
  @IsString()
  @MinLength(2)
  name: string;

  @ApiProperty({ example: "rahim@example.com" })
  @IsEmail()
  email: string;

  @ApiProperty({ example: "secret123", minLength: 6 })
  @IsString()
  password: string;
}

Controller-Level Decorator

import { ApiTags, ApiBearerAuth, ApiResponse } from "@nestjs/swagger";

@ApiTags("users") // section grouping
@Controller("users")
export class UsersController {
  @Get(":id")
  @ApiBearerAuth()
  @ApiResponse({ status: 200, description: "সফল", type: User })
  @ApiResponse({ status: 404, description: "User নেই" })
  findOne(@Param("id") id: string) {
    return this.usersService.findOne(id);
  }
}
# docs URL
http://localhost:3000/api      # swagger UI

# JSON spec
http://localhost:3000/api-json

Production-এ Docs

// production-এ docs বন্ধ রাখা
const app = await NestFactory.create(AppModule);

if (process.env.NODE_ENV !== "production") {
  SwaggerModule.setup("api", app, SwaggerModule.createDocument(
    app,
    new DocumentBuilder().setTitle("API").build(),
  ));
}
Auto-detection

Swagger auto DTO থেকে properties detect করে — শুধু @ApiProperty যোগ করলে docs uicreate হয়, প্রায় ফ্রি।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরNestJS MicroservicesপরেরNestJS Testing
এই পেজে
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com