v0.4.0 for @nestjs/swagger
Clean controllers.
Swagger in another file.
nestjs-docfy separates Swagger/OpenAPI documentation from controller logic using a companion file naming convention, the same way Nest already does with *.controller.spec.ts.
Installation
npm install nestjs-docfy
# peer deps
npm install @nestjs/common @nestjs/swagger reflect-metadataCompanion file by convention
users.controller.ts → users.controller.docs.ts. The same pattern Nest already uses for *.controller.spec.ts.
CLI with CI gates
check, coverage --min, lint and patch-spec. Fail the build when documentation is missing.
Automatic type inference
Interfaces, class-validator, and @HttpCode() become an OpenAPI schema without extra decorators.
docfy-ui AI-first
A reference UI with a Copy for AI button on every endpoint, ideal for pasting into LLMs.
What it looks like in practice
Before: a controller buried in decorators. After: just routes, with the documentation living alongside it, in a companion file.
users.controller.ts
@WithDocs()
@Controller('users')
export class UsersController {
constructor(private readonly users: UsersService) {}
@Get(':id')
findOne(@Param('id') id: string) {
return this.users.findOne(id);
}
}users.controller.docs.ts
import { docs } from 'nestjs-docfy';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { UsersController } from './users.controller';
docs(UsersController, {
classDecorators: [ApiTags('users')],
methods: {
findOne: [
ApiOperation({ summary: 'Get user by id' }),
ApiResponse({ status: 200, description: 'OK', type: UserDto }),
ApiResponse({ status: 404, description: 'User not found' }),
],
},
});