0.0.4 • Published 11 months ago

swagger2ts-rust-cli v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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_templateapi 函数模板,示例模板请看下方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位}

0.0.3

12 months ago

0.0.4

11 months ago

0.0.2

12 months ago

0.0.1

12 months ago