Add mockapi source files and tests
This commit is contained in:
@@ -18,12 +18,7 @@ class SpecLoader:
|
|||||||
SUPPORTED_EXTENSIONS = {".yaml", ".yml", ".json"}
|
SUPPORTED_EXTENSIONS = {".yaml", ".yml", ".json"}
|
||||||
|
|
||||||
def __init__(self, spec_path: str, fmt: Optional[str] = None):
|
def __init__(self, spec_path: str, fmt: Optional[str] = None):
|
||||||
"""Initialize the spec loader.
|
"""Initialize the spec loader."""
|
||||||
|
|
||||||
Args:
|
|
||||||
spec_path: Path to the OpenAPI spec file
|
|
||||||
fmt: Force format (yaml or json), auto-detected if None
|
|
||||||
"""
|
|
||||||
self.spec_path = Path(spec_path)
|
self.spec_path = Path(spec_path)
|
||||||
self.fmt = fmt or self._detect_format()
|
self.fmt = fmt or self._detect_format()
|
||||||
|
|
||||||
@@ -46,14 +41,7 @@ class SpecLoader:
|
|||||||
return "yaml"
|
return "yaml"
|
||||||
|
|
||||||
def load(self) -> Dict[str, Any]:
|
def load(self) -> Dict[str, Any]:
|
||||||
"""Load and parse the OpenAPI specification.
|
"""Load and parse the OpenAPI specification."""
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dictionary containing the parsed spec
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
SpecLoaderError: If loading or parsing fails
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
with open(self.spec_path, "r", encoding="utf-8") as f:
|
with open(self.spec_path, "r", encoding="utf-8") as f:
|
||||||
if self.fmt == "yaml":
|
if self.fmt == "yaml":
|
||||||
@@ -90,4 +78,4 @@ class SpecLoader:
|
|||||||
servers = self.load().get("servers", [])
|
servers = self.load().get("servers", [])
|
||||||
if servers:
|
if servers:
|
||||||
return servers[0].get("url", "http://localhost:8080")
|
return servers[0].get("url", "http://localhost:8080")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user