Add swagger-drogon generator
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def load_contract(path: Path) -> dict[str, Any]:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
try:
|
||||
return json.loads(text)
|
||||
except json.JSONDecodeError:
|
||||
try:
|
||||
import yaml # type: ignore[import-untyped]
|
||||
except ImportError as error:
|
||||
raise ValueError(
|
||||
f"{path}: install PyYAML or use JSON-compatible YAML syntax"
|
||||
) from error
|
||||
data = yaml.safe_load(text)
|
||||
if not isinstance(data, dict):
|
||||
raise ValueError(f"{path}: contract root must be an object")
|
||||
return data
|
||||
Reference in New Issue
Block a user