APIAuto Documentation

repository·master·Indexed 25 days ago

https://github.com/tommylemon/apiauto

An 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.

Tokens
2.2K
Snippets
1
Records
14
Agent score
81%

What's inside APIAuto

  1. Quickstart APIAuto

    master

    APIAuto is a pure static SPA (Single Page Application) web tool. You can run it using several methods:

    1. Local Browser: Download the source code, unzip it, and open index.html in a browser (Chrome or Firefox are recommended; Safari, Edge, and IE may have compatibility issues).
    2. IDE: Open the project folder in Webstorm, IntelliJ IDEA, or Eclipse.
    3. Web Server: Deploy the source to a server using Nginx or Node.js, or place the source in the resources/static directory of a SpringBoot project.
    4. Online: Access the official website at http://apijson.cn/api or http://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 Database type and Schema.
    • Default Admin: Username 13000082001, Password 123456.
  2. Run APIAuto in Headless CI/CD Mode

    master

    For 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:

    1. Install Node.js environment.
    2. Install dependencies (using koa as an example):
      nvm install 7
      npm i koa
    3. Start the HTTP Service:
      cd js
      node server.js
      If you encounter a missing package xxx error, run npm i xxx and restart.

    Usage:

    If your service is deployed via APIJSONBoot-MultiDataSource, you can append /api to the host to perform batch executions. For example: http://localhost:3000/api/test/start

    nvm install 7
    npm i koa
    
    cd js
    node server.js
  3. Importing API Test Cases

    master

    You can add new test cases to APIAuto using the following methods:

    1. Import from Third-party Tools: Click Login (top right) > Settings (top right) > Import Third-party Documentation (导入第三方文档). Enter the platform URL and click Upload.
    2. 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.
    3. Using /delegate Proxy: Call the /delegate proxy interface to record request methods, parameters, headers, and responses.
    4. Share Links: Open a generated share link to automatically populate the URL, JSON parameters, headers, and injection configurations.
    5. 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).

  4. Run regression testing with 'Compare with Before'

    master

    You 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:

    1. Automatically test all test cases (excluding login and logout).
    2. Compare the results of the current request against the previous request.
    3. Provide conclusions such as: Result Correct, New Field, Missing Field, Value Changed, Value Type Changed, or Status 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.
  5. Generate comments for JSON fields

    master

    Using 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:

    • parseComment
    • getComment4Request
    • getCommentFromDoc
  6. Generate code for Entities, Requests, and Responses

    master

    APIAuto 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.

  7. Perform automatic static checking on JSON

    master

    The parseComment method in CodeUtil.js provides 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.
  8. Use Machine Learning for interface testing

    master

    Machine 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:

    1. Click the 3rd icon button in the right area (View Shared) to enter the test case interface.
    2. Click the toggle button to switch machine learning status (e.g., 机器学习:已关闭 to enable).
    3. Click the icon button on the far right of the left area (Regression Test).
  9. Troubleshoot CORS and API Access Issues

    master

    1. 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.
  10. Reference: Machine Learning testing methods

    master

    The 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.
  11. Start auto testing via HTTP

    master

    You can trigger the automated regression testing process by sending a GET request to the /test/start endpoint.

    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 sets App.testCaseCount to 1000, App.randomCount to 200, and App.randomSubCount to 500.