Static code analysis tool to generate OpenAPI specifications from NestJS applications
npm install nestjs-openapi
Static OpenAPI generation for NestJS.
Analyzes TypeScript source directly—no build step, no app bootstrap.


@nestjs/swagger relies on reflect-metadata at runtime, which only exposes basic type signatures. Unions, generics, and literal types are erased. To work around this, you duplicate type information in decorators:
``typescript
// You already have this type
status: 'pending' | 'shipped' | 'delivered';
// But you also need this decorator to make the spec accurate
@ApiProperty({ enum: ['pending', 'shipped', 'delivered'] })
status: 'pending' | 'shipped' | 'delivered';
`
When they drift apart, your spec lies about your API.
nestjs-openapi reads your TypeScript source directly using the AST. Your types are your spec—no duplication, no drift.
`bash`
pnpm add -D nestjs-openapi
Create openapi.config.ts:
`typescript
import { defineConfig } from 'nestjs-openapi';
export default defineConfig({
output: 'openapi.json',
files: {
entry: 'src/app.module.ts',
},
openapi: {
info: { title: 'My API', version: '1.0.0' },
},
});
`
Generate:
`bash``
npx nestjs-openapi generate
Full documentation at nestjs-openapi.vercel.app
- Configuration
- Security schemes
- Serving specs at runtime
- Migration from @nestjs/swagger
- CI/CD recipe
- FAQ
See CONTRIBUTING.md.