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

zwx-api-gen

v1.0.4

Published

从 Swagger 文档自动生成 API 调用代码,支持 Basic Auth 认证

Downloads

20

Readme

Swagger API 生成器

从 Swagger 文档自动生成 API 调用代码,支持 JavaScript 和 TypeScript,可以处理需要 Basic Auth 认证的 Swagger 文档。

特性

  • 支持 JavaScript 和 TypeScript 代码生成
  • 支持 Basic Auth 认证
  • 根据 Swagger 标签自动组织 API 文件结构
  • 自动生成接口类型定义
  • 友好的命令行界面
  • 可配置的输出目录

安装

全局安装

npm install -g zwx-api-gen

项目内安装

npm install --save-dev zwx-api-gen

使用方法

命令行使用

# 使用默认配置生成 JavaScript API 文件
zwx-api-gen

# 生成 TypeScript API 文件
zwx-api-gen --typescript

# 指定 Swagger 文档 URL
zwx-api-gen --url http://example.com/v3/api-docs

# 指定 Basic Auth 认证令牌
zwx-api-gen --auth YOUR_AUTH_TOKEN

# 指定输出目录
zwx-api-gen --output ./src/api

# 查看帮助
zwx-api-gen --help

在项目中使用

package.json 中添加脚本:

{
  "scripts": {
    "gen-api": "zwx-api-gen --typescript"
  }
}

然后运行:

npm run gen-api

配置

package.json 配置

你可以在项目的 package.json 中添加 zwxApiGen 配置项:

{
  "name": "your-project",
  "version": "1.0.0",
  "zwxApiGen": {
    "url": "http://example.com/v3/api-docs",
    "auth": "YOUR_AUTH_TOKEN",
    "typescript": true
  }
}

命令行选项

| 选项 | 简写 | 描述 | 默认值 | | ---------------- | ---- | ------------------------ | -------------------- | | --typescript | -t | 生成 TypeScript 代码 | false | | --url <url> | -u | 指定 Swagger 文档 URL | 从 package.json 读取 | | --auth <token> | -a | 指定 Basic Auth 认证令牌 | 从 package.json 读取 |

输出结构

生成的 API 文件结构如下:

api/
├── 分类1/
│   ├── 模块1.js
│   └── 模块2.js
└── 分类2/
    ├── 模块3.js
    └── 模块4.js

如果使用 TypeScript 模式,每个模块会生成两个文件:

api/
├── 分类1/
│   ├── 模块1/
│   │   ├── index.ts
│   │   └── types.ts
│   └── 模块2/
│       ├── index.ts
│       └── types.ts
└── 分类2/
    └── ...

开发

安装依赖

npm install

运行开发版本

npm start

构建

npm run build

许可证

MIT