diff --git a/yamlreaders/__init__.py b/yamlreaders/__init__.py new file mode 100644 index 0000000..9904c2b --- /dev/null +++ b/yamlreaders/__init__.py @@ -0,0 +1,24 @@ +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()