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

perry-openapi2ts

v1.0.4

Published

A minimal OpenAPI to TypeScript code generator

Downloads

2

Readme

perry-openapi2ts

一个简单的OpenAPI到TypeScript代码生成器,可以从OpenAPI 3.0规范生成TypeScript接口和API调用代码。

功能

  • 从OpenAPI 3.0规范生成TypeScript接口定义
  • 生成完整的API调用函数
  • 支持路径参数、查询参数和请求体
  • 支持自定义请求库

安装

全局安装

npm install -g perry-openapi2ts

项目中安装

npm install --save-dev perry-openapi2ts

从源码安装

# 克隆仓库
git clone https://github.com/yourusername/perry-openapi2ts.git
cd perry-openapi2ts

# 安装依赖
npm install

# 构建项目
npm run build

# 链接到全局
npm link

使用方法

  1. 创建配置文件 openapi.config.json
{
  "schemaPath": "./openapi.json",
  "outputDir": "./src/services",
  "namespace": "API",
  "requestImportStatement": "import { request } from '../utils/request';"
}
  1. 运行代码生成器:
# 如果全局安装
perry-openapi2ts

# 如果项目中安装
npx perry-openapi2ts

# 如果从源码运行
npm run start

配置选项

| 选项 | 说明 | 类型 | 是否必须 | |------|------|------|----------| | schemaPath | OpenAPI规范的路径(本地文件或URL) | string | 是 | | outputDir | 生成代码的输出目录 | string | 是 | | namespace | 生成的TypeScript命名空间 | string | 否 | | requestImportStatement | 自定义请求库导入语句 | string | 否 |

项目结构

perry-openapi2ts/
├── src/
│   ├── index.ts         # 主入口
│   ├── cli.ts           # CLI工具
│   ├── serviceGenerator.ts # 服务生成器
│   ├── types.ts         # 类型定义
│   └── request.ts       # 示例请求库
├── templates/
│   ├── interface.njk    # 接口模板
│   ├── service.njk      # 服务模板
│   └── index.njk        # 索引模板
├── openapi.config.json  # 示例配置
└── example-openapi.json # 示例OpenAPI规范

示例

本项目包含一个示例OpenAPI文件和配置,运行以下命令可以生成示例代码:

npm run start

生成的代码将被放置在 ./generated 目录中。