abc-apifox
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseABC Apifox Skill
ABC Apifox Skill
本 skill 提供 ABC 医疗云 API 文档查询功能。
This skill provides ABC Medical Cloud API document query functionality.
环境配置
Environment Configuration
必需的环境变量
Required Environment Variables
使用前需要配置 Apifox Access Token:
bash
undefinedBefore use, you need to configure the Apifox Access Token:
bash
undefined设置 Apifox Access Token(必需)
设置 Apifox Access Token(必需)
export APIFOX_ACCESS_TOKEN="你的 Apifox Access Token"
export APIFOX_ACCESS_TOKEN="你的 Apifox Access Token"
设置项目 ID(可选,默认为 4105462)
设置项目 ID(可选,默认为 4105462)
export APIFOX_PROJECT_ID="4105462"
undefinedexport APIFOX_PROJECT_ID="4105462"
undefined获取 Apifox Access Token
Obtain Apifox Access Token
- 登录 Apifox
- 进入账号设置 > API 访问令牌
- 创建新的访问令牌
- 复制 Token 并配置到环境变量
- Log in to Apifox
- Go to Account Settings > API Access Token
- Create a new access token
- Copy the Token and configure it in the environment variable
依赖安装
Dependency Installation
bash
undefinedbash
undefined安装 Python 依赖
安装 Python 依赖
pip3 install requests
undefinedpip3 install requests
undefined工作原理
Working Principle
缓存架构:按模块拆分的缓存结构
- 首次使用:从 Apifox API 获取 OpenAPI 文档
- 智能拆分:
- 接口按模块拆分(api.stocks、rpc.advice 等)
- Schema 按首字母分组(A-Z + 非字母)
- 按需加载:查询时只加载相关模块文件
- 缓存持久:缓存永久有效,需要手动刷新获取最新文档
Cache Architecture: Module-split Cache Structure
- First Use: Retrieve OpenAPI documents from Apifox API
- Intelligent Splitting:
- Interfaces are split by module (api.stocks, rpc.advice, etc.)
- Schemas are grouped by initial letter (A-Z + non-letters)
- On-demand Loading: Only load relevant module files during queries
- Persistent Cache: The cache is permanently valid, and manual refresh is required to get the latest documents
使用方式
Usage
bash
./scripts/apifox <command> [参数]所有命令默认返回 JSON 格式输出。
bash
./scripts/apifox <command> [参数]All commands return JSON format output by default.
命令列表
Command List
接口查询
Interface Query
| 命令 | 说明 |
|---|---|
| 获取接口详情(自动推断模块) |
| 获取 Schema 定义 |
| 搜索接口(关键词匹配) |
| 列出所有模块 |
| 获取模块的所有接口 |
| Command | Description |
|---|---|
| Get interface details (automatically infers module) |
| Get Schema definitions |
| Search interfaces (keyword matching) |
| List all modules |
| Get all interfaces of a module |
文档管理
Document Management
| 命令 | 说明 |
|---|---|
| 刷新 OpenAPI 文档 |
| 查看缓存状态 |
| 清除本地缓存(需要 |
| Command | Description |
|---|---|
| Refresh OpenAPI documents |
| View cache status |
| Clear local cache (requires |
使用示例
Usage Examples
获取接口详情
Get Interface Details
bash
undefinedbash
undefined获取接口详情(自动推断模块)
获取接口详情(自动推断模块)
./scripts/apifox get_path
--path "/api/v3/goods/stocks/check/orders"
--method POST
--path "/api/v3/goods/stocks/check/orders"
--method POST
./scripts/apifox get_path
--path "/api/v3/goods/stocks/check/orders"
--method POST
--path "/api/v3/goods/stocks/check/orders"
--method POST
获取接口并解析 $ref 引用
获取接口并解析 $ref 引用
./scripts/apifox get_path
--path "/api/v3/goods/stocks/check/orders"
--method POST
--include_refs true
--path "/api/v3/goods/stocks/check/orders"
--method POST
--include_refs true
undefined./scripts/apifox get_path
--path "/api/v3/goods/stocks/check/orders"
--method POST
--include_refs true
--path "/api/v3/goods/stocks/check/orders"
--method POST
--include_refs true
undefined获取 Schema 定义
Get Schema Definitions
bash
undefinedbash
undefined获取 Schema 定义
获取 Schema 定义
./scripts/apifox get_schema --name CreateGoodsStockCheckOrderReq
undefined./scripts/apifox get_schema --name CreateGoodsStockCheckOrderReq
undefined搜索接口
Search Interfaces
bash
undefinedbash
undefined搜索盘点相关接口
搜索盘点相关接口
./scripts/apifox search_paths --keyword "盘点"
./scripts/apifox search_paths --keyword "盘点"
搜索特定模块的接口
搜索特定模块的接口
./scripts/apifox search_paths --keyword "库存" --module api.stocks
./scripts/apifox search_paths --keyword "库存" --module api.stocks
按方法过滤
按方法过滤
./scripts/apifox search_paths --keyword "order" --method POST --limit 10
undefined./scripts/apifox search_paths --keyword "order" --method POST --limit 10
undefined模块查询
Module Query
bash
undefinedbash
undefined列出所有模块
列出所有模块
./scripts/apifox list_modules
./scripts/apifox list_modules
获取特定模块的所有接口
获取特定模块的所有接口
./scripts/apifox get_module --module api.stocks
undefined./scripts/apifox get_module --module api.stocks
undefined文档管理
Document Management
bash
undefinedbash
undefined查看缓存状态
查看缓存状态
./scripts/apifox status
./scripts/apifox status
刷新文档(从 Apifox 获取最新数据)
刷新文档(从 Apifox 获取最新数据)
./scripts/apifox refresh_oas
./scripts/apifox refresh_oas
清除缓存
清除缓存
./scripts/apifox clear_cache --force
undefined./scripts/apifox clear_cache --force
undefined输出格式
Output Format
所有命令返回 JSON 格式:
json
{
"success": true,
"data": "返回的数据"
}错误时返回:
json
{
"success": false,
"error": "错误信息"
}All commands return JSON format:
json
{
"success": true,
"data": "返回的数据"
}Returns on error:
json
{
"success": false,
"error": "错误信息"
}Claude 使用方式
Usage with Claude
当用户需要查询 API 文档时:
- 理解需求:确定要查询的接口或 Schema
- 构建命令:根据需求选择合适的命令
- 执行脚本:使用 Bash 工具运行
- 分析结果:解析返回的接口/Schema 定义
示例工作流:
用户: "查看盘点单接口的定义"
Claude:
1. ./scripts/apifox search_paths --keyword "盘点"
2. 从结果中找到相关接口路径
3. ./scripts/apifox get_path --path "/api/v3/goods/stocks/check/orders" --method POST
4. 分析返回的请求体 CreateGoodsStockCheckOrderReq
5. 如需查看 Schema: ./scripts/apifox get_schema --name CreateGoodsStockCheckOrderReqWhen users need to query API documents:
- Understand Requirements: Determine the interface or Schema to query
- Build Command: Select the appropriate command based on requirements
- Execute Script: Run using Bash tools
- Analyze Results: Parse the returned interface/Schema definitions
Example Workflow:
User: "View the definition of the inventory check interface"
Claude:
1. ./scripts/apifox search_paths --keyword "盘点"
2. Find the relevant interface path from the results
3. ./scripts/apifox get_path --path "/api/v3/goods/stocks/check/orders" --method POST
4. Analyze the returned request body CreateGoodsStockCheckOrderReq
5. If Schema viewing is needed: ./scripts/apifox get_schema --name CreateGoodsStockCheckOrderReq缓存结构
Cache Structure
cache/
├── meta.json # 元数据 + 全局索引
├── modules/ # 按模块拆分的接口数据
│ ├── api.stocks.json # 库存相关接口
│ ├── rpc.advice.json # 医嘱相关接口
│ └── ...
└── schemas/ # Schema 定义缓存(按首字母分组)
├── a.json # A 开头的 Schema
├── b.json
├── ...
└── _.json # 非字母开头的 Schema(中文、数字等)cache/
├── meta.json # 元数据 + 全局索引
├── modules/ # 按模块拆分的接口数据
│ ├── api.stocks.json # 库存相关接口
│ ├── rpc.advice.json # 医嘱相关接口
│ └── ...
└── schemas/ # Schema 定义缓存(按首字母分组)
├── a.json # A 开头的 Schema
├── b.json
├── ...
└── _.json # 非字母开头的 Schema(中文、数字等)模块命名规则
Module Naming Rules
| 路径格式 | 模块名 | 示例 |
|---|---|---|
| | 库存模块 |
| | 医嘱模块 |
| | 认证模块 |
| Path Format | Module Name | Example |
|---|---|---|
| | Inventory Module |
| | Medical Advice Module |
| | Authentication Module |
文件结构
File Structure
scripts/
├── apifox # 命令行工具入口
├── apifox.py # Python CLI 实现
├── apifox_client.py # 客户端
├── cache_manager.py # 缓存管理器
├── requirements.txt # Python 依赖
├── check_env.py # 环境检查脚本
└── test_apifox.py # 功能测试脚本scripts/
├── apifox # 命令行工具入口
├── apifox.py # Python CLI 实现
├── apifox_client.py # 客户端
├── cache_manager.py # 缓存管理器
├── requirements.txt # Python 依赖
├── check_env.py # 环境检查脚本
└── test_apifox.py # 功能测试脚本首次使用
First Use
bash
undefinedbash
undefined配置环境变量后首次运行
配置环境变量后首次运行
./scripts/apifox status
./scripts/apifox status
自动从 Apifox 获取文档并建立缓存
自动从 Apifox 获取文档并建立缓存
正在从 Apifox 获取项目 4105462 的 OpenAPI 文档...
正在从 Apifox 获取项目 4105462 的 OpenAPI 文档...
正在清空旧缓存...
正在清空旧缓存...
正在按模块拆分接口...
正在按模块拆分接口...
正在保存 Schema(分组格式)...
正在保存 Schema(分组格式)...
导入完成!
导入完成!
undefinedundefined开发工具
Development Tools
环境检查 (check_env.py
)
check_env.pyEnvironment Check (check_env.py
)
check_env.py检查环境配置和 API 连接状态:
bash
python3 scripts/check_env.py检查项目:
- 环境变量是否配置
- Python 依赖是否安装
- 缓存状态
- API 连接测试
使用场景:
- 首次配置后验证环境
- API 连接异常时诊断
- 修改环境变量后确认生效
Check environment configuration and API connection status:
bash
python3 scripts/check_env.pyCheck Items:
- Whether environment variables are configured
- Whether Python dependencies are installed
- Cache status
- API connection test
Usage Scenarios:
- Verify environment after initial configuration
- Diagnose when API connection is abnormal
- Confirm effectiveness after modifying environment variables
功能测试 (test_apifox.py
)
test_apifox.pyFunction Test (test_apifox.py
)
test_apifox.py冒烟测试套件,验证核心功能正常:
bash
python3 scripts/test_apifox.py测试内容:
- 缓存加载
- 搜索性能(平均应 < 100ms)
- 模块过滤
- 方法过滤
- 接口详情获取
- Schema 获取
- 模块列表
使用场景:
- 修改代码后必须运行,确保功能正常
- 部署前的回归测试
- 性能退化检测
Smoke test suite to verify normal core functions:
bash
python3 scripts/test_apifox.pyTest Content:
- Cache loading
- Search performance (average should be < 100ms)
- Module filtering
- Method filtering
- Interface details retrieval
- Schema retrieval
- Module list
Usage Scenarios:
- Must run after modifying code to ensure normal functionality
- Regression testing before deployment
- Performance degradation detection
依赖安装 (requirements.txt
)
requirements.txtDependency Installation (requirements.txt
)
requirements.txtbash
undefinedbash
undefined安装依赖
安装依赖
pip3 install -r scripts/requirements.txt
undefinedpip3 install -r scripts/requirements.txt
undefined开发工作流
Development Workflow
修改功能后必须执行冒烟测试:
bash
undefinedSmoke tests must be executed after modifying functions:
bash
undefined1. 修改代码
1. 修改代码
vim scripts/cache_manager.py
vim scripts/cache_manager.py
2. 运行测试(必须)
2. 运行测试(必须)
python3 scripts/test_apifox.py
python3 scripts/test_apifox.py
3. 测试通过后提交
3. 测试通过后提交
git add scripts/cache_manager.py
git commit -m "fix: ..."
**测试失败时**:
- 检查修改是否破坏了现有功能
- 运行 `check_env.py` 诊断环境问题
- 修复后重新测试直到通过git add scripts/cache_manager.py
git commit -m "fix: ..."
**When Tests Fail**:
- Check if modifications have broken existing functionality
- Run `check_env.py` to diagnose environment issues
- Fix and retest until passed