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

openapi2api

v1.1.46

Published

openapi生成api工具

Readme

openapi2Api

openapi 生成 api 工具

使用

npm i openapi2Api -D

import { genApi } from 'openapi2api'

genApi({
  apiJsonData,
  outDir: "/example/api/modules/ambition",
  apiOutDir: "modules",
  exportApiName: "ambitionApi",
  interfaceOutDir: "interfaces",
  requestUrl: "@/utils/service",
  customUrlPlugin: (url, tags) => {
    let serviceName = "";
    if (tags?.[0]) {
      serviceName = tags[0].split("/")[0];
    }
    switch (serviceName) {
      case "user":
        return "/ambition-api/user" + url;
      case "thing":
        return "/ambition-api/thing" + url;
      default:
        return url;
    }
  },
});

genApi({
  swaggerJsonUrl: "http://172.18.14.28:5010/swagger/Bearer/swagger.json",
  outDir: "/example/api/modules/editor",
  apiOutDir: "modules",
  exportApiName: "editorApi",
  interfaceOutDir: "interfaces",
  requestUrl: "@/utils/service",
  customUrlPlugin: (url, tags) => {
    return url.replace("/graphics/bearer", "");
  },
});

参数

| 参数名 | 描述 | |------------------------------|------------------------------------------------------------------------------------------------------| | swaggerJsonUrl | api json 地址,swagger 文档中按 F12 可看到 json 请求地址,和 apiJsonData 传入一个即可 | | apiJsonData | api 的 json 数据,和 swaggerJsonUrl 传入一个即可 | | baseUrl | baseUrl 会添加到生成的 url 前面 | | outDir | 文件输出目录,如/src/api | | exportApiName | 导出的 api 集合名称 | | apiOutDir | api 输出目录名 | | interfaceOutDir | interface 输出目录名 | | requestImportStr | request 引入地址字符串,传入完整 import 导入字符串 | | needExtendTemplate | 是否需要拓展 api 的模板,并且在 api 中会自动引入拓展文件 | | exposeParamsName | 需要直接暴露返回值中的参数,如果不存在或返回值不是对象,则会返回原始数据 | | customUrlPlugin | 自定义 url 插件,参数 1:原始 url,参数 2:tags,需要返回格式化后的 url | | customGroupPlugin | 自定义 group 插件,参数:格式化后的 url,需要返回当前 url 的分组,用于创建文件分组 | | customReqNamePlugin | 自定义请求方法名称插件,参数 1:格式化后的 url,参数 2:默认生成的 name 名称,需要返回自定义的 name | | customInterFacePlugin | 自定义 interface 内容插件,参数 interface 数据,包含名称,参数类型,是否必填,需要返回对象,key 是 interface 名,value 是对应 interface{}里的内容 | | customAbnormalTypeNamePlugin | 自定义异常类型名称插件,请求类型和返回类型名称异常处理 |

Feature

  • 输出目录简化
  • 自动格式化
  • 优化参数判断逻辑 √
  • 支持自定义格式化 url √
  • 优化分组实现逻辑
  • 使用模板来替换文件字符写入
  • 直接暴露指定参数 √
  • 自定义输出文件名 √

Record

  • 1.1.41 customResponsesTypePlugin 方法名修改为 customAbnormalTypeNamePlugin