import json, re with open("scripts/openapi.json", encoding="utf-8") as f: spec = json.load(f) real_paths = set() for p, methods in spec.get("paths", {}).items(): for m in methods: real_paths.add(p) # Load api.ts with open("src/api/api.ts", encoding="utf-8") as f: text = f.read() lines = text.splitlines() func_re = re.compile(r"^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(") # static literal request path static_req = re.compile(r"request(?:<[^>]*>)?\(\s*['\"]([^'\"]+)['\"]") # template literal request path like request(`/x/${..}`) tmpl_req = re.compile(r"request(?:<[^>]*>)?\(\s*`([^`]*)`") cur = None funcs = {} # name -> {static:[], tmpl:[], dai:bool, line} for i, ln in enumerate(lines): m = func_re.match(ln) if m: cur = m.group(1) funcs[cur] = {"static": [], "tmpl": [], "dai": False, "line": i+1} if cur: for sm in static_req.finditer(ln): funcs[cur]["static"].append(sm.group(1)) for tm in tmpl_req.finditer(ln): funcs[cur]["tmpl"].append(tm.group(1)) if "【待确认】" in ln: funcs[cur]["dai"] = True # Determine if a guessed path has ANY real backing (prefix match ignoring method) def has_real_backing(path): # exact if path in real_paths: return True # base segment match: first 2 segments segs = [s for s in path.split("/") if s and not "{" in s and not "$" in s] if len(segs) >= 1: base = "/" + segs[0] if any(rp.startswith(base + "/") or rp == base for rp in real_paths): return "partial" return False phantom_static = [] ok_static = [] partial_static = [] tmpl_funcs = [] for name, info in funcs.items(): if not info["static"] and not info["tmpl"]: continue for sp in info["static"]: b = has_real_backing(sp) if b is True: ok_static.append((name, sp)) elif b == "partial": partial_static.append((name, sp)) else: phantom_static.append((name, sp)) for tp in info["tmpl"]: tmpl_funcs.append((name, tp)) print("DISTINCT FUNCTIONS WITH request():", sum(1 for n,i in funcs.items() if i["static"] or i["tmpl"])) print() print("=== PHANTOM STATIC PATHS (no OpenAPI backing at all) ===") for n, p in sorted(set(phantom_static)): dai = "【待确认】" if funcs[n]["dai"] else "(已标'已校正'但仍是幽灵!)" print(f" {n:42} -> {p:48} {dai}") print(f"\nPHANTOM count (unique fn-path): {len(set(phantom_static))}") print(f"OK count: {len(set(ok_static))}") print(f"PARTIAL count: {len(set(partial_static))}") print() print("=== PARTIAL (base domain exists, path differs) ===") for n, p in sorted(set(partial_static)): print(f" {n:42} -> {p}") print() print("=== TEMPLATE-LITERAL request paths (need manual method check) ===") for n, p in sorted(set(tmpl_funcs)): print(f" {n:42} -> {p}")