MCPcopy Create free account
hub / github.com/TheSecuredAnalyst/security-suite / parse_spec

Function parse_spec

api/routers/apisec.py:169–189  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

167async 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")
191async def discover_spec(request: DiscoverRequest) -> dict:
192 """

Callers

nothing calls this directly

Calls 3

parse_urlMethod · 0.95
OpenAPIParserClass · 0.90
APISpecInfoClass · 0.85

Tested by

no test coverage detected