@apisorcery/autoapi
v1.2.1
Published
Auto API
Readme
@apisorcery/autoapi
Installation
Using npm:
npm i @apisorcery/autoapi -g
npm i @apisorcery/autoapi --save-devUsage
Initialization
// Initialize in a Dart project
autoapi init -l dart
// Initialize in a TypeScript project
autoapi init -l ts
// Initialize in a ArkTS project
autoapi init -l arkTs
// Initialize in a Uniapp project
autoapi init -l uniappThis command will generate the AutoAPI configuration file [.autoapirc.json] in the project root directory. Taking a Dart project as an example, the content is as follows:
{
"application": {
"language": "ts",
"outputDir": "./src/apis/auto"
},
"servers": [
{
"code": "demo",
"token": "72735b33815c4e5c9c2a924a8f4907ef",
"version": 3,
"enabled": true,
"source": "https://apisorcery.com/demo-api/swagger-json",
"returnLevel": "second",
"returnSecondField": "data",
"baseStrategy": "once",
"httpClientStrategy": "once"
}
]
}Register Device
autoapi register --token xxx
//Or
autoapi register -t xxxGenerate API
autoapi generateThis command will generate the following content:
### % autoapi generate
Starting to parse configuration file
Configuration file path: /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/.autoapirc.json
Application name: DemoApplication
Application target language: dart
Application API output directory: ./lib/apis/auto
Configuration file parsing completed: 1 services found
----------------------------------------
Starting to process service #1
----------------------------------------
Starting service configuration validation
Service code: demo
Service name: DemoService
Service source: https://apisorcery.com/demo-api/swagger-json
Service configuration validation completed
Starting to clean service output files
Original output directory: /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo
Keep base file due to strategy 'once': /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo/base.dart
Keep HttpClient files due to strategy 'once': /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo/httpClient
Service output files cleanup completed
Starting to fetch Swagger file
Swagger file fetching completed
Starting to parse Swagger file
Swagger file parsing completed
Starting to generate Model files
Starting to generate custom classes
Starting to generate request parameter classes
Starting to generate response parameter classes
Starting to generate schema classes
Starting to output model file
Output file path: /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo/model.dart
Model files generation completed
Starting to generate Base files
Output file path: /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo/base.dart
Base file already exists and strategy is 'once', skip
Base files generation completed
Starting to generate HttpClient files
All HttpClient files already exists and strategy is 'once', skip
HttpClient files generation completed
Starting to generate API files
Output directory: /Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter/lib/apis/auto/demo
Starting to generate API class: ApiUser
Starting to generate API class: ApiFile
API files generation completed
----------------------------------------
Service #1 processing completed
----------------------------------------
Starting to generate model.g.dart files for all services
Resolving dependencies in `/Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter`...
Downloading packages...
Got dependencies in `/Users/markhe/Code/hk-business/ruoqing/examples/autoapi_example_flutter`.
Building package executable...
Built build_runner:build_runner.
[INFO] Generating build script completed, took 196ms
[INFO] Reading cached asset graph completed, took 69ms
[INFO] Checking for updates since last build completed, took 569ms
[INFO] Running build completed, took 14.0s
[INFO] Caching finalized dependency graph completed, took 90ms
[INFO] Succeeded after 14.2s with 843 outputs (1697 actions)
model.g.dart files generation completed
All auto-generation tasks completed, thanks for using!