openapi-parser / app /routes.py
Moibe's picture
gitignore
08040eb
raw
history blame contribute delete
850 Bytes
from fastapi import APIRouter, HTTPException, Query
from .parser import fetch_and_parse
from .schemas import ParseResponse
router = APIRouter()
@router.get("/parse", response_model=ParseResponse)
async def parse_spec(
spec_url: str = Query(..., description="URL del openapi.json a parsear"),
path: str | None = Query(None, description="Path específico, ej: /whatsapp"),
method: str | None = Query(None, description="Método HTTP, ej: GET, POST"),
):
try:
endpoints = await fetch_and_parse(
spec_url=spec_url,
path=path,
method=method,
)
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
if not endpoints:
raise HTTPException(status_code=404, detail="No matching endpoints found")
return ParseResponse(endpoints=endpoints)