Fetch and parse an OpenAPI/Swagger spec URL, returning a summary of what was found. Useful for inspecting an API before deciding which tests to run.
(request: DiscoverRequest)
| 167 | async def parse_spec(request: DiscoverRequest) -> APISpecInfo: |
| 168 | """ |
| 169 | Fetch and parse an OpenAPI/Swagger spec URL, returning a summary of what was found. |
| 170 | Useful for inspecting an API before deciding which tests to run. |
| 171 | """ |
| 172 | try: |
| 173 | from modules.apisec import OpenAPIParser |
| 174 | parser = OpenAPIParser() |
| 175 | api = await parser.parse_url(request.base_url) |
| 176 | |
| 177 | return APISpecInfo( |
| 178 | title=api.title, |
| 179 | version=api.version, |
| 180 | base_url=api.base_url, |
| 181 | servers=api.servers, |
| 182 | endpoint_count=len(api.endpoints), |
| 183 | security_schemes=list(api.security_schemes.keys()), |
| 184 | description=api.description, |
| 185 | ) |
| 186 | except Exception as e: |
| 187 | raise HTTPException(status_code=400, detail=f"Failed to parse spec: {e}") from e |
| 188 | |
| 189 | |
| 190 | @router.post("/discover", summary="Discover OpenAPI spec locations") |
| 191 | async def discover_spec(request: DiscoverRequest) -> dict: |
| 192 | """ |
nothing calls this directly
no test coverage detected