npm install parsec-codegen根据 openapi.json 生成接口代码,推荐配合 useRequest 一起使用。
``shell script`
yarn add parsec-codegen -D
在项目根目录新建 parsec.config.json 文件, openapi 填入 openapi.json 的 url 地址:
`json`
{
"openapi": "http://mock.scutum.alpha.lyd.parsec.com.cn/openapi.json"
}
输入命令:
`shell script`
parsec-codegen
生成的目录如下:
`bash`
├── configs
│ ├── codegen
│ │ ├── api.ts
│ │ ├── base.ts
│ │ ├── configuration.ts
│ │ ├── git_push.sh
│ │ └── index.ts
codegen/index.ts 会导出 DefaultApixxx` 等构造方法,初始化后即可使用。