Skip to content

快速上手

安装 AutoAPI注册设备 之后,您就可以在项目中开始使用 AutoAPI 了。

初始化

在项目根目录下执行如下命令:

全局命令:

shell
apisorcery init -f react -l ts
shell
apisorcery init -f vue -l ts
shell
apisorcery init -f svelte -l ts
shell
apisorcery init -f angular -l ts
shell
apisorcery init -f flutter -l dart
shell
apisorcery init -f harmonyos -l arkTs
shell
apisorcery init -f uniapp -l ts

局部命令:

shell
npx @apisorcery/cli init -f react -l ts
shell
npx @apisorcery/cli init -f vue -l ts
shell
npx @apisorcery/cli init -f svelte -l ts
shell
npx @apisorcery/cli init -f angular -l ts
shell
npx @apisorcery/cli init -f flutter -l dart
shell
npx @apisorcery/cli init -f harmonyos -l arkTs
shell
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个服务处理完成
----------------------------------------