快速上手
在 安装 AutoAPI 并 注册设备 之后,您就可以在项目中开始使用 AutoAPI 了。
初始化
在项目根目录下执行如下命令:
全局命令:
shell
apisorcery init -f react -l tsshell
apisorcery init -f vue -l tsshell
apisorcery init -f svelte -l tsshell
apisorcery init -f angular -l tsshell
apisorcery init -f flutter -l dartshell
apisorcery init -f harmonyos -l arkTsshell
apisorcery init -f uniapp -l ts局部命令:
shell
npx @apisorcery/cli init -f react -l tsshell
npx @apisorcery/cli init -f vue -l tsshell
npx @apisorcery/cli init -f svelte -l tsshell
npx @apisorcery/cli init -f angular -l tsshell
npx @apisorcery/cli init -f flutter -l dartshell
npx @apisorcery/cli init -f harmonyos -l arkTsshell
npx @apisorcery/cli init -f uniapp -l ts该命令会在项目根目录下生成 ApiSorcery 的配置文件【.apisorceryrc.json】,以 Dart 项目以例,内容如下:
json
{
"application": {
"framework": "flutter",
"language": "dart",
"outputDir": "./lib/apis/auto"
},
"services": [
{
"code": "product",
"source": "http://localhost:9002/swagger-json",
"version": 3
}
]
}生成 API
shell
apisorcery generate该命令会生成如下内容:
shell
### % apisorcery generate
开始解析配置文件
配置文件地址: ./.apisorceryrc.json
配置文件解析完成: 共有 1 个服务
----------------------------------------
开始处理第1个服务
----------------------------------------
开始解析Swagger文件
Swagger文件解析完成
开始生成Model文件
开始生成自定义类
开始生成请求参数类
开始生成响应参数类
开始生成schema类
开始输出model文件
输出文件地址: ./src/api/auto/product/model.ts
Model文件生成完成
开始生成Base文件
输出文件地址: ./src/api/auto/product/base.ts
Base文件生成完成
开始生成API文件
输出文件目录:./src/api/auto/product
开始生成API类: ApiUser
开始生成API类: ApiAuth
开始生成API类: ApiApplication
开始生成API类: ApiServer
开始生成API类: ApiReport
API文件生成完成
----------------------------------------
第1个服务处理完成
----------------------------------------