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 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger-to-api-v3

v1.0.6

Published

将swagger2.0的json转化为Typescript请求代码

Downloads

6

Readme

swagger2.0 接口自动化转化方案

转化swagger 2.0 json配置 为axios风格api接口 安装

npm install swagger-to-api-v3
or
pnpm add swagger-to-api-v3

使用样例

在项目目录下新建 :parseapi.js

const GenerateSwaggerApi = require("swagger-to-api-v3")
// 请求 url 生成请求api
const createApi = new GenerateSwaggerApi({
  url: "https://petstore.swagger.io/v2/swagger.json",
})
createApi.generate_api()

|参数 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | | readJsonMode | String | url | json 读取模式 网络地址 | 文件路径 "url"|"file" 默认url 模式 | | url | String | | readJsonMode 为 url 时,读取网络swagger配置json,本地文件可以利用Live Server插件启动本地文件服务 | | path | String | | readJsonMode 为 file 时,读取本地swagger配置json | | basedir | String | swagger-api/ | 可选: 存放api的目录 默认项目目录下 swagger-api/文件夹 | | requirePath | String | import { request } from "@/utils/service"\n\n | 可选: 引用request请求函数的路径 | | generateFuncNameMode | String | simple | 可选: 函数名及接口模型生成模式(数据源)1.简单模式 2.url 全链解析模式 3.唯一ID operationId模式 默认 simple, "simple"| "url" | "operationId" | | ignorePrefix | Array | ["api", "front"] | 可选: generateFuncNameMode 为url时,函数名处理掉公共前缀(函数名生成规则:接口path拼接 /api/front/appController/getPag ),处理后appControllerGetPag | | replaceRule | Map | new Map() | 可选: 自定义替换规则,例如:new Map([["object", "any"]]), 将object替换为any | | publicHeader | Object | {} | 可选: 自定义公共请求头,例如:Record<string, string>, 将请求体内会生成相关请求头信息 | | useExample | Boolean | false | 可选: 使用 swagger 的example数据辅助生成类型 例如:某Long类型 标识为{ example: String},就将其处理为string类型,此处理优先级较高 | | urlPrefix | String | "" | 可选:给请求的实际api添加 前缀 |

在package.json内添加scripts命令

  "scripts": {
    "create:api": "node parseapi.js"
  }

键入

npm run create:api
or
pnpm create:api