diff --git a/yamlreaders/__init__.py b/yamlreaders/__init__.py index 9904c2b..48e2afc 100644 --- a/yamlreaders/__init__.py +++ b/yamlreaders/__init__.py @@ -6,6 +6,7 @@ from .openapi_reader import OpenAPIReader def get_reader(source: str) -> BaseReader: from pathlib import Path + import yaml path = Path(source) @@ -13,12 +14,22 @@ def get_reader(source: str) -> BaseReader: raise FileNotFoundError(f"File not found: {path}") with open(path, "r", encoding="utf-8") as f: - first_line = f.readline().strip() + content = f.read(2048) - if '"openapi"' in first_line or "openapi:" in first_line: - return OpenAPIReader() + if "openapi:" in content: + try: + data = yaml.safe_load(content) + if isinstance(data, dict) and "openapi" in data: + return OpenAPIReader() + except Exception: + pass - if '"info"' in first_line and '"item"' in first_line: - return PostmanReader() + 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()