erpopenapi-listed
Install: claude install-skill shuangying0001-beep/parse-api-doc
# parse-api-doc —— 接口文档字段智能解析
> 把任意格式的接口/字段文档,解析成结构化字段清单 + 字段映射,用于对接第三方系统。
> 纯函数���现(Node ESM,零依赖),可直接 import 使用,也可作为 AI 抽取字段映射的参考实现。
## 适用场景
- 拿到一份 ERP / 开放平台 / 内部中台的接口说明,要快速知道「有哪些字段、什么类型、哪些必填」
- 要把对方文档字段映射到自己的采集/存储字段(字段名不一致时的别名模糊匹配)
- 从 Markdown 表格、JSON Schema、示例 JSON、纯文本字段列表里批量提取字段
## 支持的输入格式(自动探测)
1. **Markdown 表格**:`| 字段 | 类型 | 必填 | 说明 |`
2. **JSON Schema**:含 `"properties"` + `"type"`
3. **示例 JSON**:`{ "asin": "B0XXX", "title": "标题" }`
4. **纯文本字段列表**:`asin: 商品ID` / `title (string) 商品标题`
## 用法
```js
import { parseErpDocument, matchField, loadVocabulary } from './scripts/doc-parser.mjs';
const doc = `
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| asin | string | 是 | 商品ID |
| title | string | 否 | 商品标题 |
`;
const result = parseErpDocument(doc);
console.log(result.detectedFormat); // markdown_table
console.log(result.productFields); // [{name,type,required,description}]
console.log(result.fieldMappings); // [{erpField,erpType,erpRequired,erpDescription,collectorField}]
console.log(result.endpoint); // 自动推断的 方法+路径
```
## 核心 API
- `parseErpDocument(content, options?)` → `DocParseResult`
- `options.vocabulary`:自定��字段词汇表(默认内置一组常见电商/API 字段,可注入你自己的)
- 返回:`{ success, detectedFormat, productFields[], endpoint, requestStructure, responseStructure, fieldMappings[], error? }`
- `matchField(name, vocabulary?)` → 命中的标准字段 key(模糊/别名匹配,归一化大小写与 `_-`)
- `loadVocabulary(text)` → 从文本构建词汇表(便于按需扩展)
## 字段映射词汇表(可注入)
默认词汇表覆盖常见字段(asin/title/price/rating/bsr/ima