api-documentation
0
总安装量
41
周安装量
安装命令
npx skills add https://github.com/supercent-io/skills-template --skill api-documentation
Agent 安装分布
opencode
35
gemini-cli
31
claude-code
31
github-copilot
25
antigravity
21
Skill 文档
API Documentation
When to use this skill
- API ê°ë°: ì ìëí¬ì¸í¸ ì¶ê° ì
- ì¸ë¶ ê³µê°: Public API ì¶ì
- í íì : íë¡ í¸ìë-ë°±ìë ì¸í°íì´ì¤ ì ì
Instructions
Step 1: OpenAPI (Swagger) ì¤í
openapi: 3.0.0
info:
title: User Management API
version: 1.0.0
description: API for managing users
contact:
email: api@example.com
servers:
- url: https://api.example.com/v1
description: Production
- url: https://staging-api.example.com/v1
description: Staging
paths:
/users:
get:
summary: List all users
description: Retrieve a paginated list of users
tags:
- Users
parameters:
- name: page
in: query
schema:
type: integer
default: 1
- name: limit
in: query
schema:
type: integer
default: 20
maximum: 100
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/User'
pagination:
$ref: '#/components/schemas/Pagination'
'401':
$ref: '#/components/responses/Unauthorized'
post:
summary: Create a new user
tags:
- Users
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateUserRequest'
responses:
'201':
description: User created
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
$ref: '#/components/responses/BadRequest'
components:
schemas:
User:
type: object
properties:
id:
type: string
format: uuid
email:
type: string
format: email
name:
type: string
createdAt:
type: string
format: date-time
required:
- id
- email
- name
CreateUserRequest:
type: object
properties:
email:
type: string
format: email
name:
type: string
minLength: 2
maxLength: 50
password:
type: string
minLength: 8
required:
- email
- name
- password
Pagination:
type: object
properties:
page:
type: integer
limit:
type: integer
total:
type: integer
responses:
Unauthorized:
description: Unauthorized
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: "Authentication required"
BadRequest:
description: Bad Request
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: "Invalid input"
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []
Step 2: ì½ëìì 문ì ìì± (JSDoc/Decorators)
Express + TypeScript:
/**
* @swagger
* /api/users:
* post:
* summary: Create a new user
* tags: [Users]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - name
* - password
* properties:
* email:
* type: string
* format: email
* name:
* type: string
* password:
* type: string
* minLength: 8
* responses:
* 201:
* description: User created successfully
* 400:
* description: Invalid input
*/
router.post('/users', async (req, res) => {
const { email, name, password } = req.body;
const user = await userService.createUser({ email, name, password });
res.status(201).json(user);
});
Step 3: ì¸í°ëí°ë¸ 문ì
Swagger UI ì¤ì :
import swaggerUi from 'swagger-ui-express';
import YAML from 'yamljs';
const swaggerDocument = YAML.load('./openapi.yaml');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, {
customCss: '.swagger-ui .topbar { display: none }',
customSiteTitle: "My API Documentation"
}));
Step 4: ìì ë° ê°ì´ë
## API Documentation
### Authentication
All API requests require authentication using JWT tokens.
#### Getting a Token
\`\`\`bash
curl -X POST https://api.example.com/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "yourpassword"}'
\`\`\`
Response:
\`\`\`json
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "..."
}
\`\`\`
#### Using the Token
\`\`\`bash
curl -X GET https://api.example.com/v1/users \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
\`\`\`
### Creating a User
**Endpoint**: `POST /v1/users`
**Request Body**:
\`\`\`json
{
"email": "john@example.com",
"name": "John Doe",
"password": "SecurePass123!"
}
\`\`\`
**Success Response** (201):
\`\`\`json
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "john@example.com",
"name": "John Doe",
"createdAt": "2025-01-15T10:00:00Z"
}
\`\`\`
**Error Response** (400):
\`\`\`json
{
"error": "Email already exists"
}
\`\`\`
### Rate Limiting
- 100 requests per 15 minutes per IP
- Header: `X-RateLimit-Remaining`
### Pagination
\`\`\`
GET /v1/users?page=2&limit=20
\`\`\`
Response includes pagination info:
\`\`\`json
{
"data": [...],
"pagination": {
"page": 2,
"limit": 20,
"total": 157,
"pages": 8
}
}
\`\`\`
### Error Codes
- `400` - Bad Request (validation error)
- `401` - Unauthorized (missing/invalid token)
- `403` - Forbidden (insufficient permissions)
- `404` - Not Found
- `409` - Conflict (duplicate resource)
- `429` - Too Many Requests (rate limit)
- `500` - Internal Server Error
Output format
API 문ì 구조
docs/
âââ README.md # Overview
âââ getting-started.md # Quick start guide
âââ authentication.md # Auth guide
âââ api-reference/
â âââ users.md # Users endpoints
â âââ auth.md # Auth endpoints
â âââ products.md # Products endpoints
âââ guides/
â âââ pagination.md
â âââ error-handling.md
â âââ rate-limiting.md
âââ examples/
â âââ curl.md
â âââ javascript.md
â âââ python.md
âââ openapi.yaml # OpenAPI spec
Constraints
íì ê·ì¹ (MUST)
- ì¤ì ìì : ëìíë ì½ë ìì ì ê³µ
- ìë¬ ì¼ì´ì¤: ì±ê³µë¿ë§ ìëë¼ ì¤í¨ ì¼ì´ì¤ë 문ìí
- ìµì ì ì§: API ë³ê²½ ì 문ìë í¨ê» ì ë°ì´í¸
ê¸ì§ ì¬í (MUST NOT)
- ìì ì ì¤ì í¤: ìì ì ì¤ì API í¤/ë¹ë°ë²í¸ ì¬ì© ê¸ì§
- 모í¸í ì¤ëª : “ë°ì´í°ë¥¼ ë°íí©ë뤔 ê°ì ë¶ëª íí ì¤ëª
Best practices
- Try It Out: ì¸í°ëí°ë¸ 문ì ì ê³µ (Swagger UI)
- SDK ì ê³µ: 주ì ì¸ì´ë³ SDK ë° ìì
- Changelog: API ë³ê²½ ì¬í 문ìí
References
Metadata
ë²ì
- íì¬ ë²ì : 1.0.0
- ìµì¢ ì ë°ì´í¸: 2025-01-01
- í¸í íë«í¼: Claude, ChatGPT, Gemini
íê·¸
#API-documentation #OpenAPI #Swagger #REST #developer-docs #documentation