← 返回
未分类 中文

API Mock Generator

Generate mock API servers from OpenAPI 3.x and Swagger 2.0 specs. Use when creating mock/stub APIs for frontend development, testing, demos, or CI. Generates...
Generate mock API servers from OpenAPI 3.x and Swagger 2.0 specs. Use when creating mock/stub APIs for frontend development, testing, demos, or CI. Generates...
charlie-morrison charlie-morrison 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 426
下载
💾 1
安装
1
版本
#latest

概述

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]

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 patternGenerated data
--------------------------------
emailrealistic email
namefirst/last/full name
phoneformatted phone
url, websitehttps URL
city, countryreal city/country
id, uuidUUID v4
price, amountcurrency-like number
image, avatarpicsum.photos URL
description, biolorem paragraph
statusactive/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

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 04:19 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Devcontainer Validator

charlie-morrison
在 VS Code 开发容器中验证 devcontainer.json 的语法、结构、功能、端口、生命周期脚本、定制项及安全最佳实践。
★ 0 📥 470

Slack Messaging

charlie-morrison
Slack 消息—通过 CLI 和 API 发送消息、管理频道、上传文件、添加反应并自动化团队通知。
★ 0 📥 462

Pyproject Toml Validator

charlie-morrison
依据 PEP 517/621 规则校验 pyproject.toml 文件,验证项目元数据、构建系统和工具配置,并提供详细报告。
★ 0 📥 473