auto-api-ts
v1.4.3
Published
```bash npm install -g auto-api-ts ```
Downloads
87
Readme
AUTO API TS
Description
自动将swagger接口转换为ts类型
This is a simple tool to generate typescript interfaces from a json schema
Installation
npm install -g auto-api-ts
Use in Scripts
项目根目录下新建.env
文件
# swagger地址
BASE_URL="https://api.xxx.dev"
# swagger版本(可选)
API_VERSION="/api/v1/xxx/api-docs"
# swagger请求头
COOKIE="xxx"
# 生成的文件夹路径
OUTPUT="./apis"
# 请求方法的导入路径
IMPORT="import { request } from '@/request'"
# api前缀
PREFIX="/api/v1"
# api名称压缩等级 'none' | 'normal' | 'highest'
MINIFY_API_NAME="highest"
在package.json
中添加脚本
{
"scripts": {
"api": "auto-api-ts"
}
}
运行脚本
npm run api
Use in typescript
import { build } 'auto-api-ts';
build({
BASE_URL: `https://api.xxx.dev`,
COOKIE: `xxx`,
OUTPUT: `./apis`,
IMPORT: `import { request } from '@/request'`,
PREFIX: `/api/v1`,
MINIFY_API_NAME: `highest`,
});