npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mazhu/mockapi

v1.0.0

Published

智能 API Mock 服务器 - 根据 OpenAPI/Swagger 规范自动生成 Mock,支持动态响应

Readme

🛠️ MockAPI

智能 API Mock 服务器 - 根据 OpenAPI/Swagger 规范自动生成 Mock,支持动态响应

English | 中文

✨ 特性

  • 📄 OpenAPI 3.0 / Swagger 2.0 - 完美支持主流 API 规范
  • 🚀 零配置启动 - 一条命令即可启动 Mock 服务器
  • 🎭 动态场景切换 - 轻松切换成功/失败/慢速响应
  • 📊 Faker.js 集成 - 生成真实感数据
  • � schemas 支持 - 完整的 JSON Schema 类型支持
  • 响应延迟模拟 - 轻松测试网络延迟场景

📦 安装

npm install -g @mazhu/mockapi

或使用 npx:

npx @mazhu/mockapi init

🚀 快速开始

1. 初始化项目

mockapi init --name my-api
cd my-api

2. 启动 Mock 服务器

mockapi start
# 或指定端口
mockapi start --port 8080

3. 从 OpenAPI 规范生成 Mock

mockapi generate openapi.yaml -o mock.json

📚 命令

mockapi init

从模板初始化一个新的 Mock 项目。

mockapi init --name my-project --output ./my-project

mockapi start

启动 Mock 服务器。

mockapi start [options]

选项:
  -p, --port <port>    服务器端口 (默认: 3000)
  -f, --file <path>    Mock 数据文件路径 (默认: ./mock.json)
  --delay <ms>          全局响应延迟(毫秒)

mockapi generate

从 OpenAPI 规范生成 Mock 数据。

mockapi generate <spec.yaml> [options]

参数:
  spec                  OpenAPI 规范文件路径

选项:
  -o, --output <path>  输出文件路径 (默认: ./mock.json)
  -f, --format <format> 输出格式 json/yaml (默认: json)

mockapi delay

设置响应延迟模拟网络延迟。

mockapi delay <ms> [options]

参数:
  ms                   延迟时间(毫秒)

选项:
  -p, --port <port>    目标端口 (默认: 3000)

mockapi scenario

切换响应场景。

mockapi scenario <name> [options]

参数:
  name                 场景名称 (success/failure/slow)

选项:
  -p, --port <port>    目标端口 (默认: 3000)

🎭 场景模式

| 场景 | 描述 | |------|------| | success | 返回正常的成功响应 | | failure | 返回模拟的错误响应 (4xx/5xx) | | slow | 添加模拟网络延迟 |

📝 示例

创建 OpenAPI 规范

openapi: 3.0.0
info:
  title: 用户 API
  version: 1.0.0
paths:
  /users:
    get:
      summary: 获取用户列表
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        email:
          type: string
          format: email

启动并测试

# 启动服务器
mockapi start --port 3000

# 测试 API
curl http://localhost:3000/users

# 切换到失败场景
mockapi scenario failure

# 设置 2 秒延迟
mockapi delay 2000

🛠️ API 管理端点

服务器启动后提供以下管理端点:

  • GET /__health - 健康检查
  • POST /__scenario - 切换场景
  • POST /__delay - 设置延迟

📁 项目结构

mock-project/
├── openapi.yaml     # OpenAPI 规范文件
├── mock.json        # Mock 数据文件
└── README.md        # 使用文档

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License


Made with ❤️ by Mike Wang