xxx-swagger-generator-to-ts
v1.1.5
Published
swagger转to文件
Downloads
41
Readme
xxx-swagger-generator-to-ts
根据swagger文档自动生成ts接口文件
安装
yarn add xxx-swagger-generator-to-ts
#or
npm i xxx-swagger-generator-to-ts
使用
# 生成配置文件
gws3 init
配置文件
支持swagger v3 和 v2
module.exports = {
// 入口文件 swagger的openapi json地址
entry: {
API_V3: "https://api.xxx.com/v3/api-docs",
API_V2: "https://api.xxx.com/v2/api-docs"
},
// 输入目录
output: "/src/api",
// 排除列表
exclude: {
// 排除的接口
interfaces: ["ResponseResult"],
// 排除的函数名称
functions: ["focusCallBack"],
},
// 返回类型替换 如后端返回类型为ResponseResult<PageList<xxxVo>>
responseReplace:[
// 第一个对象为form:ResponseResult位置,to:Result转换位置
{from: "ResponseResult",to: "Result"},
// 第二个对象为form:PageList位置,to:List转换位置
{from: "PageList",to: "List"}
],
// 替换
replace: {
// 替换命名空间的规则
namespaces: [
// 把namespace a 替换成 b
{form: "a", to: "b"}
],
interfaces: [
// 把interface a 替换成 b
{form: "a", to: "b"}
],
functions: [
// 把function a 替换成 b
{form: "a", to: "b"}
]
},
// 导入规则
imports: [
{
// 导入文件的路径
path: "../utils/request",
members: [
// 导入成员
"request",
],
},
],
// ajax请求方法名称
ajaxVariableName: "request",
// 自定义函数名称前缀
methodNamePrefix: {
post: "",
get: "",
put: "",
delete: "",
},
}
# 根据配置文件规则生成接口文档
gws3 gens