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

Method parse_url

modules/apisec/openapi_parser.py:69–92  ·  view source on GitHub ↗

Parse OpenAPI spec from URL. Args: url: URL to OpenAPI JSON/YAML spec Returns: Parsed API specification

(self, url: str)

Source from the content-addressed store, hash-verified

67
68 async def parse_url(self, url: str) -> ParsedAPI:
69 """Parse OpenAPI spec from URL.
70
71 Args:
72 url: URL to OpenAPI JSON/YAML spec
73
74 Returns:
75 Parsed API specification
76 """
77 self.logger.info(f"Fetching OpenAPI spec from {url}")
78
79 async with httpx.AsyncClient(timeout=30.0) as client:
80 response = await client.get(url)
81 response.raise_for_status()
82
83 content_type = response.headers.get("content-type", "")
84 content = response.text
85
86 if "yaml" in content_type or url.endswith((".yaml", ".yml")):
87 spec = yaml.safe_load(content)
88 else:
89 spec = json.loads(content)
90
91 return self._parse_spec(spec, url)
92
93 def parse_file(self, path: str) -> ParsedAPI:
94 """Parse OpenAPI spec from file.
95

Callers 3

runFunction · 0.95
_execute_apisec_scanFunction · 0.95
parse_specFunction · 0.95

Calls 2

_parse_specMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected