api-documenter
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAPI Documenter
API 文档生成工具
Specialist in creating comprehensive API documentation using OpenAPI/Swagger specifications.
专门使用OpenAPI/Swagger规范创建全面的API文档。
When This Skill Activates
本技能的激活场景
Activates when you:
- Ask to document an API
- Create OpenAPI/Swagger specs
- Need API reference documentation
- Mention "API docs"
当你进行以下操作时激活:
- 要求编写API文档
- 创建OpenAPI/Swagger规范
- 需要API参考文档
- 提及"API docs"
OpenAPI Specification Structure
OpenAPI规范结构
yaml
openapi: 3.0.3
info:
title: API Title
version: 1.0.0
description: API description
servers:
- url: https://example.com/api/v1
paths:
/users:
get:
summary: List users
operationId: listUsers
tags:
- users
parameters: []
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: stringyaml
openapi: 3.0.3
info:
title: API Title
version: 1.0.0
description: API description
servers:
- url: https://example.com/api/v1
paths:
/users:
get:
summary: List users
operationId: listUsers
tags:
- users
parameters: []
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: stringEndpoint Documentation
端点文档
For each endpoint, document:
针对每个端点,需编写以下内容:
Required Fields
必填字段
- summary: Brief description
- operationId: Unique identifier
- description: Detailed explanation
- tags: For grouping
- responses: All possible responses
- summary: 简要描述
- operationId: 唯一标识符
- description: 详细说明
- tags: 用于分组
- responses: 所有可能的响应
Recommended Fields
推荐字段
- parameters: All parameters with details
- requestBody: For POST/PUT/PATCH
- security: Authentication requirements
- deprecated: If applicable
- parameters: 包含详细信息的所有参数
- requestBody: 适用于POST/PUT/PATCH请求
- security: 认证要求
- deprecated: (如适用)标记是否已弃用
Example
示例
yaml
/users/{id}:
get:
summary: Get a user by ID
operationId: getUserById
description: Retrieves a single user by their unique identifier
tags:
- users
parameters:
- name: id
in: path
required: true
schema:
type: string
description: The user ID
responses:
'200':
description: User found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'yaml
/users/{id}:
get:
summary: Get a user by ID
operationId: getUserById
description: Retrieves a single user by their unique identifier
tags:
- users
parameters:
- name: id
in: path
required: true
schema:
type: string
description: The user ID
responses:
'200':
description: User found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'Schema Documentation
Schema文档
Best Practices
最佳实践
- Use references for shared schemas
- Add descriptions to all properties
- Specify format for strings (email, uuid, date-time)
- Add examples for complex schemas
- Mark required fields
- 使用引用共享Schema
- 添加描述到所有属性
- 指定格式字符串类型(邮箱、uuid、日期时间)
- 添加示例到复杂Schema
- 标记必填字段
Example
示例
yaml
components:
schemas:
User:
type: object
required:
- id
- email
properties:
id:
type: string
format: uuid
description: Unique user identifier
example: "550e8400-e29b-41d4-a716-446655440000"
email:
type: string
format: email
description: User's email address
example: "user@example.com"
createdAt:
type: string
format: date-time
description: Account creation timestampyaml
components:
schemas:
User:
type: object
required:
- id
- email
properties:
id:
type: string
format: uuid
description: Unique user identifier
example: "550e8400-e29b-41d4-a716-446655440000"
email:
type: string
format: email
description: User's email address
example: "user@example.com"
createdAt:
type: string
format: date-time
description: Account creation timestampAuthentication Documentation
认证文档
Document auth requirements:
yaml
security:
- bearerAuth: []
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: Use your JWT token from /auth/login编写认证要求:
yaml
security:
- bearerAuth: []
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: Use your JWT token from /auth/loginError Responses
错误响应
Standard error format:
yaml
components:
schemas:
Error:
type: object
properties:
error:
type: string
description: Error message
code:
type: string
description: Application-specific error code
details:
type: object
description: Additional error detailsCommon HTTP status codes:
- 200: Success
- 201: Created
- 204: No Content
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 409: Conflict
- 422: Unprocessable Entity
- 500: Internal Server Error
标准错误格式:
yaml
components:
schemas:
Error:
type: object
properties:
error:
type: string
description: Error message
code:
type: string
description: Application-specific error code
details:
type: object
description: Additional error details常见HTTP状态码:
- 200: 成功
- 201: 创建成功
- 204: 无内容
- 400: 请求错误
- 401: 未授权
- 403: 禁止访问
- 404: 资源未找到
- 409: 冲突
- 422: 无法处理的请求实体
- 500: 服务器内部错误
Scripts
脚本
Generate OpenAPI spec from code:
bash
python scripts/generate_openapi.pyValidate OpenAPI spec:
bash
python scripts/validate_openapi.py openapi.yaml从代码生成OpenAPI规范:
bash
python scripts/generate_openapi.py验证OpenAPI规范:
bash
python scripts/validate_openapi.py openapi.yamlReferences
参考资料
- - OpenAPI template
references/openapi-template.yaml - - API documentation examples
references/examples/ - OpenAPI Specification
- - OpenAPI模板
references/openapi-template.yaml - - API文档示例
references/examples/ - OpenAPI Specification - OpenAPI规范