From 6ae350b48c3efa5129b268e818956a6e35ad89d1 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 24 Aug 2026 16:46:29 +0300 Subject: [PATCH] fix(yamlreaders): Improve format auto-detection in get_reader() Now properly detects Postman and OpenAPI formats by parsing YAML content --- yamlreaders/__init__.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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()