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

@wwtest/swagger2ts

v1.2.5

Published

> swagger文档转ts的小工具

Downloads

6

Readme

@wwtest/swagger2ts

swagger文档转ts工具

全局安装

npm i @wwtest/swagger2ts -g

安装好后查看版本

swagger2ts -V

使用方式

在项目根目录创建 swagger2ts.config.js 配置文件

文件内容如下(配置项参考下文):

module.exports = {
  url: "http://192.168.3.200:10052/v2/api-docs",
  typesDir: "./src/types",
  servicesDir: "./src/service",
};

在项目根目录运行

swagger2ts

默认配置文件内容如下

// 默认配置
module.exports = {
  // url: 'http://192.168.3.200:10052/v2/api-docs', // swagger文档地址
  typesDir: "./src/types", // 类型定义输出目录 必填
  servicesDir: "./src/service", // services输出目录 必填
  ignoreKeys: ["Authorization", "Tenant-Id"], // 忽略掉的传参字段
  ignoreType: ["header"], // 忽略掉的传参位置
  ignoreUrl: [], // 忽略掉的接口url
  ignoreUrlPrefix: [], // 忽略掉的接口url前缀
  typeTopConfig: ``, // type文件顶部公用内容
  serviceTopConfig: `import request from '@/utils'\n`, // service文件顶部公用内容
  getTem: `return request.get($requestUrl, $params)`, // get方法body代码模版
  postTem: `return request.post($requestUrl, $params)`, // post方法body代码模版
  exportApiTem: `export const $apiName = (params: $reqInterface): $resInterface => {
      $body
  }
  `, // serviceApiType 为 default 时生效
  serviceApiType: 'default', // default 默认 class class形式输出
};

指令

swagger2ts --version (-V) // 查看版本号
swagger2ts --help (-h) // 查看帮助信息
swagger2ts --config (-c) // 指定配置文件

注意事项

目前只支持swagger2.0版本

只支持 get 和 post 请求方式,可根据项目不同 配置 get 和 post 请求模板

使用该工具前,请务必保证您的请求方法封装完成

目前返回信息中只导出data字段类型定义

更新事项

2023-07-14

v1.1.4

fix: 修复重复输出interface的问题

2023-07-14

v1.2.0

feat: types和service层分离

2023-07-14

v1.2.3

fix: 修复某些场景service引入types缺少的问题

2023-07-18

v1.2.4

feat: 支持class service形式输出