Files
enbw-recharge/scripts/inventory-api-interfaces.py

29 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Extract Retrofit declarations from JADX Java output.
Usage:
python3 scripts/inventory-api-interfaces.py [jadx-source-root]
The script emits a Markdown inventory. It performs no network access and does
not read credentials or runtime captures.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
root = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("apk/jadx-out/sources")
pattern = re.compile(r"@retrofit2\.http\.(GET|POST|PUT|PATCH|DELETE|HEAD)\(\"([^\"]+)\"\)")
rows: list[tuple[str, str, str]] = []
for path in sorted(root.glob("com/enbw/**/api/*.java")):
rel = path.relative_to(root).as_posix()
for method, endpoint in pattern.findall(path.read_text(errors="replace")):
rows.append((rel, method, endpoint))
print("# Retrofit API interface inventory\n")
print(f"Generated from `{root}`; interfaces: {len({r[0] for r in rows})}; declarations: {len(rows)}.\n")
print("| Interface | HTTP | Path |\n|---|---:|---|\n")
for interface, method, endpoint in rows:
print(f"| `{interface}` | `{method}` | `{endpoint}` |")