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

openapi-request-generator

v0.0.2

Published

基于 OpenApi 规范生成前端的请求方法

Readme

Openapi-To-Ts

功能说明

  • 通过 OpenAPI 文档生成 TypeScript 类型和接口方法

所有的命令

  1. npx openapi init 在根目录创建配置文件
  2. npx openapi 根据openapi生成对应API的TS文件

配置参数说明

| 字段名 | 类型 | 默认值 | 说明 | | -------------------------- | ------------------------------------------- | ------------------------ | ---------------------------------------------------------------------------- | | label | string | - | 名称 | | schemaPath | string | - | swagger json 路径 | | schemaPaths | Array<Omit<Configuration, 'schemaPaths'>> | - | 多个 swagger json 路径( 每个项目都可以单独配置其他属性) | | serversPath | string | "./src/services" | 生成的文件夹路径,会追加一层命名空间文件夹,如 ./src/services/${namespace} | | namespace | string | "API" | ts 类型声明的命名空间名称 | | requestLibPath | string | "@/utils/request" | 请求库的路径;以 import 开头则替换整个 import,否则只替换路径 | | requestConfigType | string | "{[key: string]: any}" | 请求方法的 config 参数类型 | | requestConfigTypeLibPath | string | - | 引入请求方法 config 参数类型的路径 | | serviceTemplate | ServiceTemplate | "serviceController1" | service 函数模板 | | templatesFolder | string | - | 自定义模板文件夹路径 | | nullable | boolean | false | 是否使用 null 代替可选字段 | | enumStyle | 'string-literal' \| 'enum' | "string-literal" | 枚举类型生成风格 | | apiPrefix | string \| ApiPrefixFn | - | api 的统一前缀,支持字符串或变量函数 | | dataFields | string[] | - | response 中数据字段,如 ['result', 'res'] | | overrideMode | 'all' \| 'skip-same' \| 'over-same' | "skip-same" | 同名方法或类型的处理方式 | | splitDeclare | boolean | true | 是否拆分类型声明文件 | | isCamelCase | boolean | true | 是否使用小驼峰命名文件和请求函数 | | includes | Array<{ path: string; method: string }> | - | 只生成指定路径和方法的接口 | | declareType | 'type' \| 'interface' | - | interface 类型声明方式 | | exportType | 'merge' \| 'alone' \| 'all' | "merge" | index 文件的导出方式 | | hooks | object | - | 自定义 hooks 配置 |

参数额外说明

  1. serviceTemplate

    // 预设了三种模板,不可以自定义
    // serviceController1
    request(url, {method, data, params, ...config})
    // serviceController2
    request.post(url, {data, params, ...config})
    // serviceController3
    request.post(url, data/params, config)
  2. requestLibPath

    • 如果以import开头则替换掉整个表达式,
    • 否则只替换掉路径,import request from ${requestLibPath}
  3. requestConfigTypeLibPath

    • 如果config的类型与request方法在同一个文件导出, 可以与 requestLibPath 一同设置
  4. enumStyle

    // `string-literal` 使用字符串字面量
    type Direction = "UP" | "DOWN"
    // `enum` 使用枚举类型
    enum Direction { Up = "UP", Down = "DOWN"}
  5. hooks

    | 字段名 | 类型 | 说明 | | --------------------------- | ------------------------------------------------------------- | --------------------- | | customClassName | (tagName: string) => string | 自定义类名 | | customTypeName | (data: APIDataType) => string | 自定义类型名称 | | customFileNames | (data: APIDataType) => string[] | 自定义生成文件名 | | customFunctionName | (data: APIDataType) => string | 自定义方法名 | | customType | (schemaObject, namespace, originGetType) => string | 自定义类型生成逻辑 | | customOptionsDefaultValue | (data: OperationObject) => Record<string, any> \| undefined | 自定义 options 默认值 |