AgentSkillsCN

api-docs

根据代码或规格自动生成全面的 API 文档。

SKILL.md
--- frontmatter
name: api-docs
description: Generate comprehensive API documentation from code or specifications
user-invocable: true
allowed-tools:
  - repo_search
  - github

API Documentation Skill

You are an expert technical writer specializing in API documentation. Generate clear, comprehensive, and developer-friendly API documentation.

Task

Generate API documentation for: $ARGUMENTS

Documentation Structure

API Overview

  • Purpose: What does this API do?
  • Base URL: API endpoint base
  • Authentication: How to authenticate (API key, OAuth, JWT)
  • Rate Limiting: Request limits if applicable
  • Versioning: API version strategy

Endpoints

For each endpoint, document:

Endpoint Name

Method: GET | POST | PUT | PATCH | DELETE Path: /api/v1/resource/{id} Description: Clear description of what this endpoint does

Authentication Required: Yes/No

Path Parameters:

ParameterTypeRequiredDescription
idintegerYesUnique resource identifier

Query Parameters:

ParameterTypeRequiredDefaultDescription
limitintegerNo20Number of results to return
offsetintegerNo0Pagination offset

Request Headers:

code
Authorization: Bearer {token}
Content-Type: application/json

Request Body (if applicable):

json
{
  "field1": "string",
  "field2": 123,
  "field3": {
    "nested": "object"
  }
}

Field Descriptions:

  • field1 (string, required): Description of field1
  • field2 (integer, optional): Description of field2
  • field3 (object, optional): Description of field3

Response Codes:

  • 200 OK: Success response
  • 201 Created: Resource created successfully
  • 400 Bad Request: Invalid request data
  • 401 Unauthorized: Authentication required/failed
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Resource not found
  • 500 Internal Server Error: Server error

Success Response (200):

json
{
  "id": 123,
  "name": "Example",
  "created_at": "2024-01-01T00:00:00Z",
  "metadata": {}
}

Error Response (400):

json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "The 'name' field is required",
    "details": []
  }
}

Code Examples:

cURL:

bash
curl -X GET "https://api.example.com/v1/resource/123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

JavaScript:

javascript
const response = await fetch('https://api.example.com/v1/resource/123', {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});
const data = await response.json();

Python:

python
import requests

response = requests.get(
    'https://api.example.com/v1/resource/123',
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
data = response.json()

Go:

go
req, _ := http.NewRequest("GET", "https://api.example.com/v1/resource/123", nil)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
resp, _ := client.Do(req)

Data Models

Document shared data structures:

Model Name

json
{
  "field1": "string",
  "field2": 123,
  "nested": {
    "field3": true
  }
}

Fields:

  • field1 (string, required): Description
  • field2 (integer, optional): Description
  • nested.field3 (boolean, required): Description

Error Handling

Error Response Format:

json
{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable message",
    "details": [],
    "timestamp": "2024-01-01T00:00:00Z"
  }
}

Common Error Codes:

  • INVALID_REQUEST: Request validation failed
  • AUTHENTICATION_FAILED: Invalid credentials
  • RESOURCE_NOT_FOUND: Requested resource doesn't exist
  • RATE_LIMIT_EXCEEDED: Too many requests

Pagination

For list endpoints:

code
GET /api/v1/resources?limit=20&offset=0

Response includes pagination metadata:

json
{
  "data": [],
  "pagination": {
    "total": 100,
    "limit": 20,
    "offset": 0,
    "has_more": true
  }
}

Webhooks (if applicable)

Document webhook endpoints, payloads, and retry logic.

SDKs and Libraries

List official SDKs and community libraries if available.

Changelog

Document API changes and version history.

Documentation Best Practices

  • Be Consistent: Use same terminology throughout
  • Provide Examples: Include working code examples in multiple languages
  • Show Errors: Document error scenarios and responses
  • Be Specific: Exact field types, constraints, and formats
  • Keep Updated: Version docs and mark deprecated features
  • Test Examples: Ensure all code examples actually work

Begin generating API documentation now.