API Mock Generator

👤 charlie-morrison 📦 v1.0.1 ⭐ 4.4 ⬇️ 786 下载
💻 开发编程 免费

📖 技能介绍

API Mock Generator

Generate mock API servers and static fixtures from OpenAPI/Swagger specs. Contextual fake data (emails, names, UUIDs, etc.) based on property names and schema types.

Quick Start

# Start a live mock server
python3 scripts/generate_mock.py serve api.json

# Generate static JSON mock files
python3 scripts/generate_mock.py generate api.json -o mocks/

# List discovered routes
python3 scripts/generate_mock.py routes api.json

# Generate sample response for a specific endpoint
python3 scripts/generate_mock.py sample api.json /users

Commands

serve — Live Mock Server

python3 scripts/generate_mock.py serve spec.json [options]

小葱技能7w4.net持续更新中。

Options:

  • --port, -p — port (default: 3000)
  • --host — host (default: 127.0.0.1)
  • --delay, -d — response delay in ms (simulate latency)
  • --error-rate, -e — random error rate 0.0-1.0 (simulate failures)

Features: CORS headers on all responses, path parameter matching, JSON responses with Content-Type headers.

generate — Static Mock Files

python3 scripts/generate_mock.py generate spec.json -o output_dir/

Creates one JSON file per route + manifest.json with route mapping. Useful for test fixtures or frontend stubs.

routes — Discover Endpoints

python3 scripts/generate_mock.py routes spec.json [--format text|json]

sample — Single Endpoint Preview

python3 scripts/generate_mock.py sample spec.json /users --method GET

Supported Specs

  • OpenAPI 3.x (JSON)
  • Swagger 2.0 (JSON)
  • YAML (requires pip install pyyaml)

Fake Data Generation

Property-name-aware generation:

Property pattern Generated data
*email* realistic email
*name* first/last/full name
*phone* formatted phone
*url*, *website* https URL
*city*, *country* real city/country
*id*, *uuid* UUID v4
*price*, *amount* currency-like number
*image*, *avatar* picsum.photos URL
*description*, *bio* lorem paragraph
*status* active/inactive/pending

Schema-aware: respects enum, example, default, format (date, date-time, email, uri, uuid, ipv4), minimum/maximum, minLength/maxLength, $ref, oneOf/anyOf/allOf.

Exit Codes

  • 0 — success
  • 1 — route not found (sample command)
  • 2 — spec parse error or system error

🤖 AI 评测

质量较好,能满足快速创建模拟 API 的需求。文档清晰易懂,功能设计实用,生成的假数据智能且真实。实时服务器和静态文件两种模式覆盖面广,但缺少示例文件,上手需要自己准备 API 规范。整体适合开发者使用,文档和功能实现都较为专业。

📊 多维度评分

适应性4.6
规范性4.3
有效性4.5
可靠性4.5
可信度4.4

📁 包含文件 (3 个)

📄 SKILL.md 2.8 KB
📄 _meta.json 137 B
📄 scripts/generate_mock.py 20.5 KB