api-mocker
Skill0 starsChanged 46 days agoMITView on GitHub
根据 OpenAPI/Swagger、接口文档或描述生成简单资源的本地 Express mock API。用于请求模拟后端或前端联调假接口。
- Installs packages
In this repository9 other files it gives its agents.
- codebase-cartographerSkill
- commit-poetSkill
- data-detectiveSkill
- doc-archaeologistSkill
- env-guardianSkill
- git-storytellerSkill
- regex-wizardSkill
- svg-icon-forgeSkill
- terminal-dashboardSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 14 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈14
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Use the source already provided.
- Distinctive: line 25
Run the parsing script on the user's spec file:
- Distinctive: line 35
When the user describes their API verbally (e.g., "I need a user management API with CRUD plus an orders endpoint"):
- Distinctive: line 37
Ask clarifying questions if needed (what resources?
- Distinctive: line 70
Run the fake data generator:
- Distinctive: line 80
Run the server generator:
- Distinctive: line 96
Run the server when local verification is part of the task.
- Distinctive: line 108
All available endpoints with methods
- Distinctive: line 118
Always generate realistic data: Use field name inference (name -> person name, email -> valid email, price -> reasonable dollar amount, …
- Distinctive: line 119
Maintain referential integrity: If orders reference user_id, those IDs must exist in the users data.
- Distinctive: line 123
CORS enabled: All origins allowed by default for local frontend dev.
- Distinctive: line 128
If the OpenAPI spec is invalid, report the specific parsing error and ask the user to fix it.
- Distinctive: line 129
If a field type is unknown, default to generating a random string.
- Distinctive: line 130
If the user's spec uses features not supported (e.g., oneOf, allOf), simplify and inform the user.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
api-mocker Skill
Resolve <skill_dir> to the directory containing this SKILL.md. Use absolute helper paths, keep project/output paths separate, and generate only the outputs needed for the user's request.
You are an API mocking expert. Your job is to generate a fully runnable Mock API server from API specifications or verbal descriptions, complete with realistic fake data.
Workflow
Step 1: Determine the API Source
Use the source already provided. Ask only when the source is missing:
- OpenAPI/Swagger spec file -- The user has a
.yamlor.jsonspec file. Proceed to Step 2A. - Verbal description -- The user describes the API they need in natural language. Proceed to Step 2B.
- Existing code or docs -- The user points to backend code, README, or other documentation. Read those files, extract the API surface, and build a route description JSON manually. Then proceed to Step 3.
Step 2A: Parse an OpenAPI Spec
Run the parsing script on the user's spec file:
python3 "<skill_dir>/scripts/parse_openapi.py" <spec_file> -o /tmp/api-mocker/routes.jsonThis produces a standardized routes.json describing all routes, methods, parameters, and response schemas. Review parsed routes against the source; clarify only material ambiguities.
Step 2B: Build Routes from Verbal Description
When the user describes their API verbally (e.g., "I need a user management API with CRUD plus an orders endpoint"):
- Ask clarifying questions if needed (what resources? what fields? any relationships?).
- Manually create a
routes.jsonfile at/tmp/api-mocker/routes.jsonfollowing this schema:
{
"info": { "title": "...", "version": "1.0.0" },
"routes": [
{
"path": "/api/users",
"method": "GET",
"summary": "List all users",
"parameters": [],
"response": {
"status": 200,
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
}
}
}
}
}
]
}Step 3: Generate Fake Data
Run the fake data generator:
python3 "<skill_dir>/scripts/fake_data.py" /tmp/api-mocker/routes.json -o /tmp/api-mocker/dataThis creates JSON data files in /tmp/api-mocker/data/ with realistic values (names, emails, prices, dates, etc.) and referential consistency across resources.
Step 4: Generate the Mock Server
Run the server generator:
node "<skill_dir>/scripts/generate_server.js" /tmp/api-mocker/routes.json /tmp/api-mocker/data -o <output_dir>Where <output_dir> is the user's desired output directory (default: ./mock-server).
This produces:
server.js-- Main Express.js entry pointroutes/-- One route file per resourcedata/-- Fake data JSON files (copied from Step 3)package.json-- With express dependency
Step 5: Start the Server
Run the server when local verification is part of the task; stop it after checks unless the user needs it running. The generated server currently binds all network interfaces, so keep it in an isolated development environment.
cd <output_dir>
npm install
node server.jsThe server runs on port 3456 by default (configurable via PORT env var).
Tell the user:
- The server URL (e.g.,
http://localhost:3456) - All available endpoints with methods
- How to customize: edit data files, change port, add delay with
DELAY_MSenv var - CORS is enabled by default for frontend development
Step 6: Verify
Curl a few key endpoints to verify the server works, then present the results to the user.
Key Behaviors
- Always generate realistic data: Use field name inference (name -> person name, email -> valid email, price -> reasonable dollar amount, created_at -> recent ISO date).
- Maintain referential integrity: If orders reference user_id, those IDs must exist in the users data.
- Simple resource model: The generator uses in-memory list/detail routes and methods found in the specification. Review nested routes and custom operations before claiming endpoint parity.
- Pagination: List endpoints support
?page=1&limit=10query parameters. - Configurable latency:
DELAY_MS=200env var simulates network delay. - CORS enabled: All origins allowed by default for local frontend dev.
- In-memory store: Data is loaded from JSON files at startup and mutated in memory. Restart resets data.
Error Handling
- If the OpenAPI spec is invalid, report the specific parsing error and ask the user to fix it.
- If a field type is unknown, default to generating a random string.
- If the user's spec uses features not supported (e.g., oneOf, allOf), simplify and inform the user.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

