Files
api-checker/yamlreaders/__init__.py
T
Black_Raven bf47218831 feat(yamlreaders): Added __init__.py with get_reader() helper
Exports all readers and provides get_reader() function
that auto-detects file format and returns appropriate reader
2026-08-24 16:03:42 +03:00

25 lines
647 B
Python

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
path = Path(source)
if not path.exists():
raise FileNotFoundError(f"File not found: {path}")
with open(path, "r", encoding="utf-8") as f:
first_line = f.readline().strip()
if '"openapi"' in first_line or "openapi:" in first_line:
return OpenAPIReader()
if '"info"' in first_line and '"item"' in first_line:
return PostmanReader()
return YamlReader()