nestjs-api-docs
v1.0.1
Published
Beautiful API documentation UI for NestJS, powered by OpenAPI/Swagger
Maintainers
Readme
nestjs-api-docs
Beautiful, interactive API documentation UI for NestJS. Drop-in replacement for Swagger UI with a modern design, built-in debugger, and code snippet generation.
Features
- 🎨 Clean light-theme UI with syntax highlighting
- 🐛 Built-in API debugger (drawer panel)
- 💻 Code snippets: cURL / fetch / axios / HTTPie
- 📦 Data models viewer
- 🔑 Global Bearer Token configuration (persisted to localStorage)
- ⚡ Zero network requests — spec injected directly from NestJS
- 📋 Collapsible JSON viewer
Installation
npm install nestjs-api-docsUsage
// main.ts
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { useApiDocs } from 'nestjs-api-docs';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('My API')
.setDescription('API documentation')
.setVersion('1.0.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
// Mount the docs UI
app.use('/docs', useApiDocs({ document }));
await app.listen(3000);
}
bootstrap();Then visit http://localhost:3000/docs 🎉
Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| document | object | required | OpenAPI document from SwaggerModule.createDocument() |
| title | string | from document.info.title | Browser tab title |
| customCss | string | undefined | Extra CSS to inject |
| removeCSP | boolean | true | Remove Content-Security-Policy header for the docs route |
Development vs Production
// Only expose docs in non-production
if (process.env.NODE_ENV !== 'production') {
app.use('/docs', useApiDocs({ document }));
}