APIAuto Documentation
repository·master·Indexed 25 days ago
https://github.com/tommylemon/apiautoAn all-in-one HTTP interface tool for agile development, automated API management, and zero-code testing. APIAuto features machine learning-driven regression testing, automatic code generation for multiple languages (Java, Kotlin, Swift, C#, PHP, Go, JS, TS, Python), and static JSON checking. It can be deployed as a static SPA or run in a headless CI/CD mode via a Node.js server to execute test cases and monitor progress through HTTP APIs.
What's inside APIAuto
- CodeMirror is a JavaScript component designed to provide a code editor within a web browser. It supports syntax highlighting (coloring code) and optional indentation assistance when a specific language mode is available for the language being edited.
Quickstart APIAuto
masterAPIAuto is a pure static SPA (Single Page Application) web tool. You can run it using several methods:
- Local Browser: Download the source code, unzip it, and open
index.htmlin a browser (Chrome or Firefox are recommended; Safari, Edge, and IE may have compatibility issues). - IDE: Open the project folder in Webstorm, IntelliJ IDEA, or Eclipse.
- Web Server: Deploy the source to a server using Nginx or Node.js, or place the source in the
resources/staticdirectory of a SpringBoot project. - Online: Access the official website at
http://apijson.cn/apiorhttp://apijson.cn:8080.
Configuration:
- Change the Base URL in the left URL input box to your host address (e.g.,
http://localhost:8080). - In the top-right Settings (设置) dropdown, modify the
Databasetype andSchema. - Default Admin: Username
13000082001, Password123456.
- Local Browser: Download the source code, unzip it, and open
Run APIAuto in Headless CI/CD Mode
masterFor CI/CD pipelines (like Jenkins or BlueDefender) that do not support UI testing, APIAuto provides a Headless mode. You can execute test cases and view progress by calling HTTP APIs.
Setup Steps:
- Install Node.js environment.
- Install dependencies (using
koaas an example):nvm install 7 npm i koa - Start the HTTP Service:
If you encounter acd js node server.jsmissing package xxxerror, runnpm i xxxand restart.
Usage:
If your service is deployed via
APIJSONBoot-MultiDataSource, you can append/apito the host to perform batch executions. For example:http://localhost:3000/api/test/startnvm install 7 npm i koa cd js node server.jsImporting API Test Cases
masterYou can add new test cases to APIAuto using the following methods:
- Import from Third-party Tools: Click Login (top right) > Settings (top right) > Import Third-party Documentation (导入第三方文档). Enter the platform URL and click Upload.
- Copy/Paste from Browser/Tools: Copy request information from the Browser Network tab or tools like Charles and paste it directly into the URL input box.
- Using /delegate Proxy: Call the
/delegateproxy interface to record request methods, parameters, headers, and responses. - Share Links: Open a generated share link to automatically populate the URL, JSON parameters, headers, and injection configurations.
- Manual Entry: Manually fill in the URL, JSON parameters, and headers in the UI and click the upload/share button.
Note: To use 'Automatic Document Generation' and 'Automatic Test Case Management', you must deploy an APIJSON backend (e.g., using APIJSONBoot series).
Run regression testing with 'Compare with Before'
masterYou can perform automated interface regression testing without writing any code. By clicking the regression test icon (the refresh-like icon in the top right of the left area), APIAuto will:
- Automatically test all test cases (excluding login and logout).
- Compare the results of the current request against the previous request.
- Provide conclusions such as:
Result Correct,New Field,Missing Field,Value Changed,Value Type Changed, orStatus Code Changed.
UI Controls per test case:
- Left button: Show test results and toggle between before/after request views.
- Right button: Error correction (纠错).
- Middle button: Download both requests.
- [对的,纠错] (Correct, Fix) button: If the current result is correct, click this to upload the new result as the standard for future comparisons.
- Background color: Indicates the severity of the interface change.
Generate comments for JSON fields
masterUsing
CodeUtil.js, APIAuto can automatically generate documentation comments for your JSON structures:- Request JSON: Automatically generates the field type, length, and description on the right side of every line in the request JSON.
- Response JSON: Automatically displays the type, length, and description when the cursor moves to a specific field in the result JSON.
Key methods involved:
parseCommentgetComment4RequestgetCommentFromDoc
Generate code for Entities, Requests, and Responses
masterAPIAuto can automatically generate code for various programming languages including Java, Kotlin, Swift, C#, PHP, Go, JavaScript, TypeScript, and Python. It generates code for:
- Model classes (Entities)
- Encapsulated Request JSONs
- Parsed Result JSONs
Core logic is located in
CodeUtil.js.Perform automatic static checking on JSON
masterThe
parseCommentmethod inCodeUtil.jsprovides automatic static analysis to ensure data integrity:- Validates that the Request JSON follows correct JSON formatting.
- Checks if fields within table objects actually exist in the corresponding tables.
- Verifies that values corresponding to APIJSON keywords are valid.
Use Machine Learning for interface testing
masterMachine learning testing builds upon the 'Compare with Before' feature by using statistical analysis and scenario optimization to extract a validation model for the Response JSON. This model includes key-value pair names, types, lengths, and value ranges for every layer, including precise positioning within arrays (e.g.,
[]/7/Comment/id).As you use the 'Correct, Fix' feature, the model becomes more accurate. Typically, after 12 corrections per test case, the model reaches a level of precision comparable to a senior test engineer's manual test code.
How to enable and use Machine Learning testing:
- Click the 3rd icon button in the right area (View Shared) to enter the test case interface.
- Click the toggle button to switch machine learning status (e.g.,
机器学习:已关闭to enable). - Click the icon button on the far right of the left area (Regression Test).
Troubleshoot CORS and API Access Issues
master1. Unable to access interfaces (CORS issues)
- Browser Restrictions: Chrome 90+ prohibits carrying Cookies in CORS requests, and Chrome 80-89 enforces same-site Cookie policies. See APIAuto Issue #9 for solutions.
- Third-party API Restrictions: If the target API does not support CORS, enable the Hosted Server Proxy (托管服务器代理) in the top-right Settings. The default hosted server is
http://apijson.cn:9090(public only). For internal networks, deploy an APIJSON backend internally and update the hosted server address.
2. Documents not generating
- Ensure the Settings in the top-right match your actual database configuration.
3. Hosted server issues
- If the proxy cannot proxy interfaces, show documents, or correct assertion results, check APIAuto Issue #12.
Reference: Machine Learning testing methods
masterThe following methods are used for machine learning-based validation in
JSONResponse.js:compareWithStandard: Compares the current response against the extracted machine learning model.updateStandard: Updates the validation model based on corrected results.
Start auto testing via HTTP
masterYou can trigger the automated regression testing process by sending a GET request to the
/test/startendpoint.If a test is already running, the server will return a 200 status with the message:
Already started auto testing in node, please wait for minutes....Optional Query Parameter:
key: If provided and not empty, the server setsApp.testCaseCountto 1000,App.randomCountto 200, andApp.randomSubCountto 500.