Mark controllers with @WithDocs()
Flag which controllers have a companion file, then run generate.
Mark your controllers
users.controller.ts
// users.controller.ts
import { Controller, Get, Post, Body } from "@nestjs/common";
import { WithDocs } from "nestjs-docfy";
@WithDocs()
@Controller("users")
export class UsersController {
// route handlers only: no Swagger decorators here
}Generate the companion files
Run the CLI to scan your project and generate a pre-filled *.controller.docs.ts for each controller:
bash
npx nestjs-docfy generateThe CLI uses static analysis only (no code execution) and auto-detects your project's layout: monorepos, Nx workspaces, and Nest CLI monorepos are all supported.
To preview without touching the filesystem:
bash
npx nestjs-docfy generate --dry-runFill in the docs file
The generated file comes pre-filled with inferred summaries, response types, and common error responses:
users.controller.docs.ts
// Generated by nestjs-docfy: edit freely, use --force to merge new methods
import { docs } from "nestjs-docfy";
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from "@nestjs/swagger";
import { UsersController } from "./users.controller";
import { CreateUserDto } from "./dto/create-user.dto";
import { UserEntity } from "./entities/user.entity";
docs(UsersController, {
classDecorators: [ApiTags("users")],
methods: {
// GET / → async findAll(): Promise<UserEntity[]>
findAll: [
ApiOperation({ summary: "Find all" }),
ApiResponse({ status: 200, description: "OK", type: [UserEntity] }),
],
// POST / → async create(dto: CreateUserDto): Promise<UserEntity>
create: [
ApiOperation({ summary: "Create" }),
ApiBody({ type: CreateUserDto }),
ApiResponse({ status: 201, description: "Created", type: UserEntity }),
ApiResponse({ status: 400, description: "Bad Request" }),
],
},
});Edit the file freely: your changes are safe. Running generate again skips existing files. Use --force to merge in only new methods without touching existing ones.