1.2.1 • Published 10 months ago

mock-convert v1.2.1

Weekly downloads
14
License
ISC
Repository
gitlab
Last release
10 months ago

mock convert

将idoc上的接口数据转换为mock数据

安装

npm i mock-convert --save-dev

使用

写好配置文件,然后执行,配置文件参考下一节

mock-convert -c config/config.js;

配置文件

config.js

module.exports = {
    projectJsonUrl: "http://api.demo", // 项目文档接口地址,必须
    outOpt: {
        outPath: "mock/data.js", // 生成mock文件输出的路径,必须
        singleFile: true, // 生成单个文件,默认为false
        fileNames: {
            '登录': 'login',
            '行情': 'market',
        } // 文件名
    }
    parseOpt: [ // 可选配置
        {
            dataType: "string", // 参数类型,支持多个参数类型,类型之间用,分隔开
            identifier: "price", // 参数变量名
            ignoreCase: true, // 匹配时候是否忽略大小写,匹配内容为identifier的值
            fullMatch: false, // 全字匹配,匹配内容为identifier的值
            target: '\"$identifier$\|3000-5000.1-2\": 3000', // 生成目标,identifier为占位符,在转换过程中会替换为identifier的值
        },
        {
            dataType: "int,string",
            identifier: "retcode",
            ignoreCase: true,
            fullMatch: true,
            target: 'retcode: 200'
        },
    ]
}

在可选配置中,可以对转换做定制化操作:

{
    dataType: "string",
    id: 49384,
    identifier: "buyPrice",
    isNecessary: 1,
    mock: "",
    name: "买入价",
    parameterList: [ ],
    remark: "精确到小数点2位 没有有效行情下是0",
    validator: ""
},
// 匹配到第一个规则,配置中$identifier$为占位符,实际使用中会替换为identifier的值,这里最终转换的结果为:"buyPrice|3000-5000.1-2": 3000
{
    dataType: "string",
    id: 49024,
    identifier: "retcode",
    isNecessary: 1,
    mock: "",
    name: "返回码",
    parameterList: [ ],
    remark: "200为成功,错误对应相应的错误代码 9011(交易密码错误,登录失败) 9018(账号或密码错误,无密码剩余次数记录)",
    validator: ""
}
// dataType支持多种数据类型,这里匹配到第二个规则,会转换为: retcode: 200

mock规则

mock规则可参考 http://mockjs.com/

1.2.1

10 months ago

1.2.0

4 years ago

1.1.0

5 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago