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

swagger2ts-rust-cli

v0.0.4

Published

According to the data model of swagger generated typescript interface by Rust

Downloads

10

Readme

Swagger2TS-Rust_Cli

这是一个根据远程swagger文档来生成 Typescript interface 的命令行工具。 使用 Rust 编写,速度够快。

参数

Simple program to generate the typescript interface by swagger json
Options:
  -C, --config <config file path> path for config file
  -h, --help                 Print help
  -V, --version              Print version

安装

npm i swagger2ts-rust-cli -D

yarn add swagger2ts-rust-cli -D

使用

{
	"scripts": {
		"trans-swagger": "swagger2ts --C <config file path>"
	}
}
yarn trans-swagger
// or
npm run trans-swagger

Config 配置

默认会在项目的根目录下查询swagger2ts.json文件,可手动传入配置文件

| 配置项 | 子配置 | 描述 | 默认值 | 类型 | | -------------- | ----------------- | ----------------------------------------------------------------- | ------ | --------- | | filename | - | 存储 interface 的文件名 | 无 | string | | url | - | swagger json 文件的请求地址 | 无 | string | | outdir | - | 输出的目录 | 无 | string | | request | - | 是否同时生成 api 请求函数 | 无 | boolean | | request_config | | 生成 api 函数的配置 | 无 | | | - | function_template | api 函数模板,示例模板请看下方 | 无 | string | | - | ignore_path | 需要忽略的 url 前缀 | 无 | string | | - | prefix | 需要在 api 函数文件头部添加的字符串,可以在此处传入需要导入的东西 | 无 | string | | - | split | 是否要根据模块拆分成不同的文件(待实现) | 无 | boolean |

function_template

{
	"function_template": "//{description}\nexport function {name} (params?:{parameter})  {\n return http.{method}<{response}>({url},params);\n}\n"
}

在程序运行的时候会将{xxx}替换成对应的数据

| 参数 | 解读 | | ----------- | -------------- | | description | 接口描述 | | name | 接口名称 | | parameter | 接口参数类型 | | method | 请求方式 | | response | 接口返回值类型 | | url | 接口请求地址 |

~~默认会在运行的目录下的api文件中生成一个index.d.ts文件,里面包含了 swagger 的 definitions 或 openapi 的 components/schemas 里定义的数据结构,只转化名称为全英文的 definitions/schemas~~

目前除了 interface 是指定存放目录以外,api 函数统一输出在 config.outdir 下面的api.ts文件中。

非合法的 interface 名称会转换成Interface_{名称hash后后6位}