from .base import BaseReader, ParseError from .yaml_reader import YamlReader from .postman_reader import PostmanReader from .openapi_reader import OpenAPIReader def get_reader(source: str) -> BaseReader: from pathlib import Path import yaml path = Path(source) if not path.exists(): raise FileNotFoundError(f"File not found: {path}") with open(path, "r", encoding="utf-8") as f: content = f.read(2048) if "openapi:" in content: try: data = yaml.safe_load(content) if isinstance(data, dict) and "openapi" in data: return OpenAPIReader() except Exception: pass try: data = yaml.safe_load(content) if isinstance(data, dict): if "info" in data and "item" in data: return PostmanReader() except Exception: pass return YamlReader()