fix(yamlreaders): Improve format auto-detection in get_reader()

Now properly detects Postman and OpenAPI formats by parsing YAML content
This commit is contained in:
Black_Raven committed 2026-08-24 16:46:29 +03:00
1 parent 805b28e344
commit 6ae350b48c
1 file changed
+14 -3
+14 -3
View File
@@ -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:
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:
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()