# yapi2ts-serve **Repository Path**: HadiChan/yapi2ts-serve ## Basic Information - **Project Name**: yapi2ts-serve - **Description**: 通过yapi接口文档生成ts类型文件 - **Primary Language**: Unknown - **License**: LGPL-2.1 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-06-21 - **Last Updated**: 2023-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: yapi, TypeScript ## README # yapi2ts-server > 根据 yapi 的接口定义生成 TypeScript 的接口类型 ## 脚本开发 ```js // 安装依赖,建议使用npm npm i yarn pnpm install ``` 1、启动脚本说明: ```js // 开启开发模式,带有watch npm run dev // 将ts编译为js文件 npm run build // 直接运行ts脚本 npm run start ``` 2、配置说明: > `yapi2ts-server` 依赖配置文件(`.js|.json`) 生成 **Ts 接口类型**,测试开发使用 `npm run dev // or npm run start`启动脚本若检测无配置文件将询问是否生成(`yapi2ts.js`)。 配置项: | 参数 | 类型 | 是否必须 | 说明 | | -------------- | ------ | -------- | ----------------------------------------- | | serverUrl | string | 是 | YApi 服务地址,使用https://yapi.baibu.la/ | | outputFilePath | string | 否 | 输出的文件夹,默认 './src/api' | | projects | array | 是 | 对应的项目配置 **projects-item** | **projects-item**: | 参数 | 类型 | 是否必须 | 说明 | | ------------- | ------------------ | -------- | --------------------------------------------------------- | | token | string | 是 | YApi 项目 token;进入对应项目 -> 设置 -> token 配置中复制 | | excludeCatIds | number or number[] | 否 | 需要排除的接口分类 id | | excludeApiIds | number or number[] | 否 | 需要排除的接口 id | | getApiDir | function | 否 | 处理输出 api 目录,ps:基于 outputFilePath 下的目录 | | getApiNames | function | 否 | 自定义接口函数名称、出参入参数据类型名称 | ## 作为 cli 使用(未发布npm) ```js // 生成配置模板 yapi2ts-server init // 生成ts接口描述. 可选-c 配置文件,默认./yapi2ts.js yapi2ts-server -c[path] ```