flipped-aurora/gin-vue-admin · error
无法解析API项 %q,期望 "/path" 或 "METHOD /path"
Error message
无法解析API项 %q,期望 "/path" 或 "METHOD /path"
What it means
The role-API batch assigner parses each API item string expecting either a bare path `/path` or a `METHOD /path` pair. A string that splits into more than two whitespace-separated fields cannot be interpreted, so parsing aborts with this error naming the offending item.
Source
Thrown at server/mcp/role_api_batch_assigner.go:209
if _, ok := seen[key]; ok {
continue
}
seen[key] = struct{}{}
deduped = append(deduped, item)
}
return deduped, nil
}
// parseAPIItemString 解析"METHOD /path"或"/path"形式的单条API,方法缺省为POST
func parseAPIItemString(s string) (path, method string, err error) {
fields := strings.Fields(strings.TrimSpace(s))
switch len(fields) {
case 1:
return fields[0], "", nil
case 2:
return fields[1], fields[0], nil
default:
return "", "", fmt.Errorf("无法解析API项 %q,期望 \"/path\" 或 \"METHOD /path\"", s)
}
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Remove extra tokens so each item is exactly `/path` or `METHOD /path` (e.g. `POST /api/user`)
- Check for full-width or invisible whitespace characters and replace them with nothing or a single ASCII space
- Strip any comments or annotations from each item string
- If method and path are supplied separately, use only the `/path` form and set the method elsewhere
Example fix
// before
items := []string{"POST /api/user comment", "/api/user"}
// after
items := []string{"POST /api/user", "/api/user"} Defensive patterns
Strategy: validation
Validate before calling
func validAPIItem(s string) bool {
fields := strings.Fields(s)
if len(fields) == 1 {
return strings.HasPrefix(fields[0], "/")
}
if len(fields) == 2 {
return isHTTPMethod(fields[0]) && strings.HasPrefix(fields[1], "/")
}
return false
} Type guard
func normalizeAPIItem(s string) (string, error) {
s = strings.Join(strings.Fields(s), " ")
if !validAPIItem(s) {
return "", fmt.Errorf("invalid API item %q", s)
}
return s, nil
} Prevention
- Pass items as `/path` or `METHOD /path` only
- Strip comments and trailing whitespace from each item
- Beware of full-width (U+3000) spaces when copying from Chinese docs
- Split method and path fields programmatically rather than hand-formatting
When it happens
Trigger: Passing an item like `POST /api/user extra` or an item containing accidental spaces/tabs/newlines to the APIs list of the batch assign tool.
Common situations: Copy-pasting a curl command line into the API item field; a stray comma converted to space; trailing comment after the path; Chinese full-width space mistaken as separator.
Related errors
- apis 需为JSON数组或逗号分隔字符串
- 单次分配的部门/岗位数量各不能超过 %d 个
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
- 未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root
- go.mod 中未找到 module 定义
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/69a38cd11df39c0f.
Report an issue: GitHub.