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
This commit is contained in:
1 parent
f28c1d6d7c
commit
bf47218831
1 file changed
+24
@@ -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()
|
||||||
Reference in new issue
Block a user