api-documentation-generator by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill api-documentation-generator从您的代码库自动生成清晰、全面的 API 文档。此技能帮助您创建专业的文档,包括端点描述、请求/响应示例、身份验证详情、错误处理和使用指南。
非常适合 REST API、GraphQL API 和 WebSocket API。
首先,我将检查您的 API 代码库以了解:
对于每个端点,我将创建包含以下内容的文档:
端点详情:
请求规范:
响应规范:
代码示例:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
我将包括:
清晰的错误文档,包括:
在可能的情况下,我将提供:
## 创建用户
创建一个新的用户账户。
**端点:** `POST /api/v1/users`
**身份验证:** 必需(Bearer token)
**请求体:**
\`\`\`json
{
"email": "user@example.com", // 必需:有效的电子邮件地址
"password": "SecurePass123!", // 必需:最少 8 个字符,1 个大写字母,1 个数字
"name": "John Doe", // 必需:2-50 个字符
"role": "user" // 可选:"user" 或 "admin"(默认:"user")
}
\`\`\`
**成功响应(201 Created):**
\`\`\`json
{
"id": "usr_1234567890",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"createdAt": "2026-01-20T10:30:00Z",
"emailVerified": false
}
\`\`\`
**错误响应:**
- `400 Bad Request` - 无效的输入数据
\`\`\`json
{
"error": "VALIDATION_ERROR",
"message": "无效的电子邮件格式",
"field": "email"
}
\`\`\`
- `409 Conflict` - 电子邮件已存在
\`\`\`json
{
"error": "EMAIL_EXISTS",
"message": "使用此电子邮件的账户已存在"
}
\`\`\`
- `401 Unauthorized` - 缺少或无效的身份验证令牌
**示例请求(cURL):**
\`\`\`bash
curl -X POST https://api.example.com/api/v1/users \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123!",
"name": "John Doe"
}'
\`\`\`
**示例请求(JavaScript):**
\`\`\`javascript
const response = await fetch('https://api.example.com/api/v1/users', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'SecurePass123!',
name: 'John Doe'
})
});
const user = await response.json();
console.log(user);
\`\`\`
**示例请求(Python):**
\`\`\`python
import requests
response = requests.post(
'https://api.example.com/api/v1/users',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
json={
'email': 'user@example.com',
'password': 'SecurePass123!',
'name': 'John Doe'
}
)
user = response.json()
print(user)
\`\`\`
## 用户查询
通过 ID 获取用户信息。
**查询:**
\`\`\`graphql
query GetUser($id: ID!) {
user(id: $id) {
id
email
name
role
createdAt
posts {
id
title
publishedAt
}
}
}
\`\`\`
**变量:**
\`\`\`json
{
"id": "usr_1234567890"
}
\`\`\`
**响应:**
\`\`\`json
{
"data": {
"user": {
"id": "usr_1234567890",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"createdAt": "2026-01-20T10:30:00Z",
"posts": [
{
"id": "post_123",
"title": "我的第一篇帖子",
"publishedAt": "2026-01-21T14:00:00Z"
}
]
}
}
}
\`\`\`
**错误:**
\`\`\`json
{
"errors": [
{
"message": "未找到用户",
"extensions": {
"code": "USER_NOT_FOUND",
"userId": "usr_1234567890"
}
}
]
}
\`\`\`
## 身份验证
所有 API 请求都需要使用 Bearer 令牌进行身份验证。
### 获取令牌
**端点:** `POST /api/v1/auth/login`
**请求:**
\`\`\`json
{
"email": "user@example.com",
"password": "your-password"
}
\`\`\`
**响应:**
\`\`\`json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"refreshToken": "refresh_token_here"
}
\`\`\`
### 使用令牌
在 Authorization 头中包含令牌:
\`\`\`
Authorization: Bearer YOUR_TOKEN
\`\`\`
### 令牌过期
令牌在 1 小时后过期。使用刷新令牌获取新的访问令牌:
**端点:** `POST /api/v1/auth/refresh`
**请求:**
\`\`\`json
{
"refreshToken": "refresh_token_here"
}
\`\`\`
介绍
身份验证
快速开始
端点
数据模型
错误处理
速率限制
变更日志
SDK 和工具
症状: 示例无法工作,参数错误,端点返回不同的数据 解决方案:
症状: 用户不知道如何处理错误,支持工单增加 解决方案:
症状: 用户无法开始使用,挫败感增加 解决方案:
症状: 用户发送无效请求,验证错误 解决方案:
生成交互式文档:
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/users:
post:
summary: Create a new user
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateUserRequest'
导出集合以便于测试:
{
"info": {
"name": "My API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create User",
"request": {
"method": "POST",
"url": "{{baseUrl}}/api/v1/users"
}
}
]
}
@doc-coauthoring - 用于协作编写文档@copywriting - 用于清晰、用户友好的描述@test-driven-development - 用于确保 API 行为与文档匹配@systematic-debugging - 用于故障排除 API 问题专业提示: 尽可能让您的 API 文档贴近代码。使用从代码注释生成文档的工具,以确保它们保持同步!
每周安装数
289
代码仓库
GitHub 星标数
23.4K
首次出现
Jan 25, 2026
安全审计
安装于
opencode234
gemini-cli223
codex217
claude-code211
github-copilot197
cursor183
Automatically generate clear, comprehensive API documentation from your codebase. This skill helps you create professional documentation that includes endpoint descriptions, request/response examples, authentication details, error handling, and usage guidelines.
Perfect for REST APIs, GraphQL APIs, and WebSocket APIs.
First, I'll examine your API codebase to understand:
For each endpoint, I'll create documentation including:
Endpoint Details:
Request Specification:
Response Specification:
Code Examples:
I'll include:
Clear error documentation including:
Where possible, I'll provide:
## Create User
Creates a new user account.
**Endpoint:** `POST /api/v1/users`
**Authentication:** Required (Bearer token)
**Request Body:**
\`\`\`json
{
"email": "user@example.com", // Required: Valid email address
"password": "SecurePass123!", // Required: Min 8 chars, 1 uppercase, 1 number
"name": "John Doe", // Required: 2-50 characters
"role": "user" // Optional: "user" or "admin" (default: "user")
}
\`\`\`
**Success Response (201 Created):**
\`\`\`json
{
"id": "usr_1234567890",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"createdAt": "2026-01-20T10:30:00Z",
"emailVerified": false
}
\`\`\`
**Error Responses:**
- `400 Bad Request` - Invalid input data
\`\`\`json
{
"error": "VALIDATION_ERROR",
"message": "Invalid email format",
"field": "email"
}
\`\`\`
- `409 Conflict` - Email already exists
\`\`\`json
{
"error": "EMAIL_EXISTS",
"message": "An account with this email already exists"
}
\`\`\`
- `401 Unauthorized` - Missing or invalid authentication token
**Example Request (cURL):**
\`\`\`bash
curl -X POST https://api.example.com/api/v1/users \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123!",
"name": "John Doe"
}'
\`\`\`
**Example Request (JavaScript):**
\`\`\`javascript
const response = await fetch('https://api.example.com/api/v1/users', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'SecurePass123!',
name: 'John Doe'
})
});
const user = await response.json();
console.log(user);
\`\`\`
**Example Request (Python):**
\`\`\`python
import requests
response = requests.post(
'https://api.example.com/api/v1/users',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
json={
'email': 'user@example.com',
'password': 'SecurePass123!',
'name': 'John Doe'
}
)
user = response.json()
print(user)
\`\`\`
## User Query
Fetch user information by ID.
**Query:**
\`\`\`graphql
query GetUser($id: ID!) {
user(id: $id) {
id
email
name
role
createdAt
posts {
id
title
publishedAt
}
}
}
\`\`\`
**Variables:**
\`\`\`json
{
"id": "usr_1234567890"
}
\`\`\`
**Response:**
\`\`\`json
{
"data": {
"user": {
"id": "usr_1234567890",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"createdAt": "2026-01-20T10:30:00Z",
"posts": [
{
"id": "post_123",
"title": "My First Post",
"publishedAt": "2026-01-21T14:00:00Z"
}
]
}
}
}
\`\`\`
**Errors:**
\`\`\`json
{
"errors": [
{
"message": "User not found",
"extensions": {
"code": "USER_NOT_FOUND",
"userId": "usr_1234567890"
}
}
]
}
\`\`\`
## Authentication
All API requests require authentication using Bearer tokens.
### Getting a Token
**Endpoint:** `POST /api/v1/auth/login`
**Request:**
\`\`\`json
{
"email": "user@example.com",
"password": "your-password"
}
\`\`\`
**Response:**
\`\`\`json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"refreshToken": "refresh_token_here"
}
\`\`\`
### Using the Token
Include the token in the Authorization header:
\`\`\`
Authorization: Bearer YOUR_TOKEN
\`\`\`
### Token Expiration
Tokens expire after 1 hour. Use the refresh token to get a new access token:
**Endpoint:** `POST /api/v1/auth/refresh`
**Request:**
\`\`\`json
{
"refreshToken": "refresh_token_here"
}
\`\`\`
Introduction
Authentication
Quick Start
Endpoints
Data Models
Error Handling
Rate Limiting
Changelog
Symptoms: Examples don't work, parameters are wrong, endpoints return different data Solution:
Symptoms: Users don't know how to handle errors, support tickets increase Solution:
Symptoms: Users can't get started, frustration increases Solution:
Symptoms: Users send invalid requests, validation errors Solution:
Generate interactive documentation:
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/users:
post:
summary: Create a new user
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateUserRequest'
Export collection for easy testing:
{
"info": {
"name": "My API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create User",
"request": {
"method": "POST",
"url": "{{baseUrl}}/api/v1/users"
}
}
]
}
@doc-coauthoring - For collaborative documentation writing@copywriting - For clear, user-friendly descriptions@test-driven-development - For ensuring API behavior matches docs@systematic-debugging - For troubleshooting API issuesPro Tip: Keep your API documentation as close to your code as possible. Use tools that generate docs from code comments to ensure they stay in sync!
Weekly Installs
289
Repository
GitHub Stars
23.4K
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode234
gemini-cli223
codex217
claude-code211
github-copilot197
cursor183
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
20,700 周安装
Go语言测试模式指南:TDD、表驱动测试、模糊测试与性能基准测试
2,800 周安装
LangChain create_agent 智能体创建教程 - 构建AI助手与工具集成
2,900 周安装
Tauri v2 开发技能:使用 Web 前端和 Rust 构建跨平台桌面/移动应用
2,800 周安装
Prisma CLI 7.x 完整命令参考:数据库迁移、客户端生成与开发工具指南
2,900 周安装
Spring Boot工程师技能指南:微服务架构、安全加固与云原生开发实战
2,800 周安装
Slidev:基于Vite和Vue的开发者演示工具,支持Markdown、代码高亮与交互
2,900 周安装
SDKs and Tools