Parse OpenAPI spec from URL. Args: url: URL to OpenAPI JSON/YAML spec Returns: Parsed API specification
(self, url: str)
| 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 |
no test coverage detected