nestjs-openapi
v0.1.4
Published
Static code analysis tool to generate OpenAPI specifications from NestJS applications
Maintainers
Readme
Documentation · Quick Start · Report Bug
Motivation
@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:
// 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.
Quick start
pnpm add -D nestjs-openapiCreate openapi.config.ts:
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:
npx nestjs-openapi generateDocumentation
Full documentation at nestjs-openapi.vercel.app
Contributing
See CONTRIBUTING.md.
