File size: 850 Bytes
08040eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)