doc4nestjs
v1.0.2
Published
NestJS apidocs for enhanced Swagger/OpenAPI documentation with support for both Express and Fastify adapters. Provides a powerful API documentation UI.
Readme
Description
NestJS 的 Swagger UI 增强工具.同时支持 Express 和 Fastify 两种主流 HTTP 适配器. 感谢 @NextDoc4j 开源提供的webui.
📦 Installation
# Install the package
npm install doc4nestjs @nestjs/swagger
# For Fastify adapter, also install:
npm install @fastify/static🔄 Compatibility Matrix
| @fastify/static version | Fastify version |
| ----------------------- | --------------- |
| ^8.x | ^5.x |
| ^7.x | ^4.x |
| ^5.x | ^3.x |
| ^2.x | ^2.x |
| ^1.x | ^1.x |
🚀 Usage
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
import { Doc4Nestjs } from 'doc4nestjs'
// To use this with Fastify, first install @fastify/static. Please ensure version compatibility.
async function bootstrap() {
const options = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build()
const document = SwaggerModule.createDocument(app, options)
SwaggerModule.setup('api', app, document)
Doc4Nestjs(app, [
{
name: '2.0 version',
url: `/api-json`,
},
])
await app.listen(3000)
}启动后访问 http://127.0.0.1:3000/doc.html
UI预览图

