Spaces:
Sleeping
Sleeping
Normalización de paths de endpoints externos
Browse files- app/parser.py +7 -1
app/parser.py
CHANGED
|
@@ -119,16 +119,22 @@ def parse_endpoint(spec: dict, path: str, method: str, operation: dict) -> Endpo
|
|
| 119 |
)
|
| 120 |
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
async def fetch_and_parse(spec_url: str, path: str | None = None, method: str | None = None) -> list[EndpointInfo]:
|
| 123 |
async with httpx.AsyncClient() as client:
|
| 124 |
resp = await client.get(str(spec_url), follow_redirects=True)
|
| 125 |
resp.raise_for_status()
|
| 126 |
spec = resp.json()
|
| 127 |
|
|
|
|
| 128 |
endpoints: list[EndpointInfo] = []
|
| 129 |
|
| 130 |
for ep_path, methods in spec.get("paths", {}).items():
|
| 131 |
-
if
|
| 132 |
continue
|
| 133 |
for ep_method, operation in methods.items():
|
| 134 |
if ep_method in ("parameters", "summary", "description", "servers"):
|
|
|
|
| 119 |
)
|
| 120 |
|
| 121 |
|
| 122 |
+
def _normalize_path(p: str) -> str:
|
| 123 |
+
"""Strip trailing slashes for consistent comparison, but keep root '/'."""
|
| 124 |
+
return p.rstrip("/") or "/"
|
| 125 |
+
|
| 126 |
+
|
| 127 |
async def fetch_and_parse(spec_url: str, path: str | None = None, method: str | None = None) -> list[EndpointInfo]:
|
| 128 |
async with httpx.AsyncClient() as client:
|
| 129 |
resp = await client.get(str(spec_url), follow_redirects=True)
|
| 130 |
resp.raise_for_status()
|
| 131 |
spec = resp.json()
|
| 132 |
|
| 133 |
+
normalized_path = _normalize_path(path) if path else None
|
| 134 |
endpoints: list[EndpointInfo] = []
|
| 135 |
|
| 136 |
for ep_path, methods in spec.get("paths", {}).items():
|
| 137 |
+
if normalized_path and _normalize_path(ep_path) != normalized_path:
|
| 138 |
continue
|
| 139 |
for ep_method, operation in methods.items():
|
| 140 |
if ep_method in ("parameters", "summary", "description", "servers"):
|