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/apiforge

v1.0.0

Published

API Development Toolkit - Test, Mock, Document, Validate OpenAPI specs

Readme

APIForge

API Development Toolkit - 一站式 API 开发工具:测试、Mock、文档生成、格式验证。

安装

npm install -g apiforge

功能

1. 生成测试 (apiforge test)

从 OpenAPI spec 自动生成 API 测试代码:

# 生成 Jest 测试
apiforge test api.yaml --format jest --output ./tests

# 生成 Mocha 测试
apiforge test api.yaml --format mocha --output ./tests

# 指定 Base URL
apiforge test api.yaml --base-url https://api.example.com

选项:

  • -o, --output <dir> - 输出目录 (默认: ./tests)
  • -f, --format <format> - 测试格式 jest|mocha (默认: jest)
  • --base-url <url> - API Base URL

2. 启动 Mock 服务器 (apiforge mock)

根据 OpenAPI spec 启动本地 Mock 服务器:

# 默认端口 3000
apiforge mock api.yaml

# 指定端口和主机
apiforge mock api.yaml --port 8080 --host 0.0.0.0

# 监听文件变化自动重载
apiforge mock api.yaml --watch

选项:

  • -p, --port <port> - 端口 (默认: 3000)
  • -h, --host <host> - 主机 (默认: localhost)
  • -w, --watch - 监听变化并重载

3. 生成文档 (apiforge doc)

从 OpenAPI spec 生成 Markdown 文档:

# 生成 API.md
apiforge doc api.yaml

# 指定输出文件
apiforge doc api.yaml --output ./docs/API.md

# 不包含示例
apiforge doc api.yaml --no-examples

选项:

  • -o, --output <file> - 输出文件 (默认: ./API.md)
  • --toc - 包含目录 (默认: true)
  • --examples - 包含请求/响应示例 (默认: true)

4. 验证 Spec (apiforge validate)

验证 OpenAPI spec 格式是否正确:

# 标准验证
apiforge validate api.yaml

# 严格模式 (检查 operationId、examples 等)
apiforge validate api.yaml --strict

选项:

  • --strict - 严格验证模式

示例

使用项目自带的 Pet Store 示例:

# 验证 spec
npx ts-node src/index.ts validate examples/petstore.yaml

# 生成文档
npx ts-node src/index.ts doc examples/petstore.yaml --output examples/API.md

# 启动 Mock 服务器
npx ts-node src/index.ts mock examples/petstore.yaml --port 3001

# 生成测试
npx ts-node src/index.ts test examples/petstore.yaml --output examples/tests

技术栈

  • Node.js + TypeScript
  • Commander - CLI 框架
  • Express - Mock 服务器
  • @apidevtools/swagger-parser - OpenAPI 解析
  • OpenAPI 3.0 支持

License

MIT