You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.8 KiB
70 lines
2.8 KiB
# -*- coding: utf-8 -*-
|
|
"""重建端点 dump(旧机 tmp/dump_api.py 未随仓,本版重写)。
|
|
扫 crm-customer / crm-rule / crm-preference 全部 *Controller.java:
|
|
输出 类级前缀 + 动词 + 方法级路径 + 签名行,供 API-SUMMARY 对账基准。
|
|
用法:py -3 -X utf8 .scratch/customer-rework/dump_api.py
|
|
"""
|
|
import io
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
|
|
|
ROOT = Path(r"e:\code\crm-backend-matt")
|
|
MODULES = ["crm-customer", "crm-rule", "crm-preference"]
|
|
OUT = ROOT / ".scratch" / "customer-rework" / "dump_api_out.txt"
|
|
OUT_PARAMS = ROOT / ".scratch" / "customer-rework" / "dump_params_out.txt"
|
|
|
|
CLASS_RE = re.compile(r'@RequestMapping\s*\(\s*(?:value\s*=\s*)?"([^"]*)"')
|
|
METHOD_RE = re.compile(r'@(Get|Post|Put|Delete|Patch|Request)Mapping\s*(?:\(\s*(?:value\s*=\s*)?"([^"]*)"[^)]*\)|(?![\w(]))?')
|
|
SIGN_RE = re.compile(r"public\s+[\w<>,.\[\]\s]+\s+\w+\s*\(([^)]*)\)")
|
|
|
|
|
|
def norm_prefix(p: str) -> str:
|
|
p = p.strip()
|
|
if p and not p.startswith("/"):
|
|
p = "/" + p
|
|
return p.rstrip("/")
|
|
|
|
|
|
def join(prefix: str, sub: str) -> str:
|
|
sub = (sub or "").strip()
|
|
if sub and not sub.startswith("/"):
|
|
sub = "/" + sub
|
|
if sub == "/":
|
|
sub = ""
|
|
return prefix + sub
|
|
|
|
|
|
lines = []
|
|
param_lines = []
|
|
for mod in MODULES:
|
|
module_lines = [f"######## MODULE {mod}"]
|
|
module_params = [f"######## MODULE {mod}"]
|
|
for f in sorted((ROOT / mod).rglob("*Controller.java")):
|
|
src = f.read_text(encoding="utf-8")
|
|
cm = CLASS_RE.search(src)
|
|
prefix = norm_prefix(cm.group(1)) if cm else ""
|
|
# 只扫类声明之后:类级 @RequestMapping 不算端点
|
|
cls_idx = src.find("public class")
|
|
body = src[cls_idx:] if cls_idx != -1 else src
|
|
module_lines.append(f"==== {f.name} prefix={prefix!r}")
|
|
module_params.append(f"==== {f.name} prefix={prefix!r}")
|
|
# 逐注解→方法块扫描
|
|
for m in METHOD_RE.finditer(body):
|
|
verb = m.group(1).upper() if m.group(1) != "Request" else "ANY"
|
|
sub = m.group(2) or ""
|
|
# 方法签名:从注解结束到第一个 ") ->"
|
|
tail = src[m.end(): m.end() + 600]
|
|
sm = re.search(r"public\s+[\w<>,.\[\]\s]+?\s+\w+\s*\(([^)]*)\)", tail)
|
|
sig = " ".join(sm.group(1).split()) if sm else "(?)"
|
|
full = join(prefix, sub)
|
|
module_lines.append(f"{verb} {full} ({sig})")
|
|
module_params.append(f"{verb} {full}")
|
|
lines.extend(module_lines)
|
|
param_lines.extend(module_params)
|
|
|
|
OUT.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
OUT_PARAMS.write_text("\n".join(param_lines) + "\n", encoding="utf-8")
|
|
print(f"OK controllers dump -> {OUT} ({len(lines)} lines) / params-only -> {OUT_PARAMS}")
|
|
|