5759c1862e
M0-M7 已完成:核心网关(身份/RBAC/TOTP/OIDC/SAML/Provider/配额/路由/内容策略/审计/定价)+ 资源市场(MCP/Skills/数字员工)。 含 22 个 PostgreSQL 迁移、管理端/门户端前端源码、OpenAPI 契约、部署 compose。 Co-Authored-By: Claude <noreply@anthropic.com>
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Fail when a literal Go ServeMux route is absent from the OpenAPI contract."""
|
|
from __future__ import annotations
|
|
import re
|
|
from pathlib import Path
|
|
import yaml
|
|
|
|
ROUTE = re.compile(r'HandleFunc\("(GET|POST|PUT|PATCH|DELETE) ([^" ]+)"')
|
|
PARAM = re.compile(r"\{[^{}]+\}")
|
|
|
|
|
|
def normalized(method: str, path: str) -> tuple[str, str]:
|
|
return method.upper(), PARAM.sub("{}", path)
|
|
|
|
|
|
document = yaml.safe_load(Path("api/openapi/gateway.yaml").read_text())
|
|
contract = {normalized(method, path) for path, value in document["paths"].items() for method in value if method.lower() in {"get", "post", "put", "patch", "delete"}}
|
|
implemented = set()
|
|
for source in list(Path("internal").rglob("*.go")) + list(Path("cmd").rglob("*.go")):
|
|
for method, path in ROUTE.findall(source.read_text()):
|
|
implemented.add((normalized(method, path), str(source)))
|
|
missing = sorted((route, source) for route, source in implemented if route not in contract)
|
|
for (method, path), source in missing:
|
|
print(f"{method} {path} ({source})")
|
|
if missing:
|
|
raise SystemExit(f"{len(missing)} implemented literal routes are missing from OpenAPI")
|
|
print(f"OpenAPI covers {len(implemented)} literal Go routes")
|