doke-nest
v1.0.1
Published
Simple and beautiful API documentation generator for NestJS
Downloads
75
Maintainers
Readme
Doke
API documentation generator for NestJS applications with beautiful UI 🎨
Features
- Simple API endpoint decorators
- Beautiful and customizable documentation UI
- Easy to use and integrate
- Automatic metadata extraction
- Customizable themes and layouts
Packages
This repository is a monorepo containing the following packages:
@doke/core- Core package for generating API documentation@doke/ui- UI package for rendering beautiful documentation
Installation
# Install core package
npm install @doke/core
# Install UI package (optional) (Not support yet)
npm install @doke/uiQuick Start
1. Prepare docs data and package.json
// package.json
"scripts": {
...
"generate-docs": "ts-node -r tsconfig-paths/register ./src/utils/generate-docs.ts", // <- Add this line
}// /docs/create-user.docs.ts
import { ApiDocsEndpoint } from '@doke/core'
export const DocsCreateUser = () => {
const metadata: EndpointDecoratorMetadata<{
body: 'email' | 'name'
response: 'id' | 'email' | 'name'
}> = {
description: 'Create a new user',
request: {
body: {
properties: {
email: {
type: 'string',
description: 'User email address',
required: true
},
name: {
type: 'string',
description: 'User full name',
required: false
}
},
}
},
response: {
example: {
id: "98874008-8915-4d53-9239-3913f7ee2089",
email: "[email protected]",
name: "benny"
}
}
}
return ApiDocsEndpoint(metadata)
}2. Add Decorators to Your Controllers
import { Controller, Post, Body } from '@nestjs/common'
import { ApiDocsController } from '@doke/core'
import { DocsCreateUser } from '/docs'
@Controller('users')
@ApiDocsController({
description: 'User management endpoints',
tags: ['users']
})
export class UserController {
constructor(...somethin) {}
@Post()
@DocsCreateUser() // use decorator make in /docs
async createUser(@Body() createUserDto: CreateUserDto) {}
}3. Generate Documentation
// docs.ts
import { ApiDocsGenerator } from '@doke/core'
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
async function generateDocs() {
const app = await NestFactory.create(AppModule)
const generator = new ApiDocsGenerator(
{
name: 'My API',
description: 'API documentation for my awesome project',
version: '1.0.0'
},
'./docs'
)
const discoveryService = app.get(DiscoveryService)
await new ApiDocsGenerator(info, './', discoveryService).generate()
await app.close()
}
generateDocs()4. Run command
npm run generate-docs
or
yarn generate-docs5. View Documentation (with @doke/ui) (Not support yet)
# Install doke UI globally
npm install -g @doke/ui
# Start documentation server
doke serve ./docsExamples (Not support yet)
You can find more examples in our examples directory.
Contributing
We welcome contributions! Please see our contributing guide for details.
