""" Controller 端点解析模块(纯 Python,无需 Java)。 """ from pathlib import Path from typing import Dict, List from models import ApiEndpoint, ApiParameter def endpoints_to_map(endpoints: List[ApiEndpoint]) -> Dict[str, ApiEndpoint]: """端点列表转字典,key 为 endpoint_key。""" return {ep.endpoint_key: ep for ep in endpoints} def filter_endpoints_by_files( endpoints: List[ApiEndpoint], changed_files: List[str] ) -> List[ApiEndpoint]: """仅保留变更文件中的端点。""" if not changed_files: return endpoints changed_set = {f.replace("\\", "/") for f in changed_files} return [ep for ep in endpoints if ep.source_file in changed_set] def parse_endpoints_from_files( repo_root: Path, source_subdirs: List[str], file_paths: List[str], file_contents: Dict[str, str], ) -> List[ApiEndpoint]: """ 解析指定 Controller 文件,提取接口参数(仅解析传入文件,不全量扫描)。 :param repo_root: 仓库根 :param source_subdirs: 源码目录列表(相对仓库根) :param file_paths: 文件路径列表 :param file_contents: 路径 -> 源码内容 :return: ApiEndpoint 列表 """ from controller_ast_parser import parse_controller_files return parse_controller_files(repo_root, source_subdirs, file_paths, file_contents)