(n: dict)
| 444 | """ |
| 445 | |
| 446 | def visit(n: dict): |
| 447 | if isinstance(n, list): |
| 448 | return [visit(x) for x in n] |
| 449 | elif isinstance(n, dict): |
| 450 | ref = n.get("$ref") |
| 451 | if ref is not None and ref not in self._refs: |
| 452 | if ref.startswith("https://"): |
| 453 | assert self._allow_fetch, ( |
| 454 | "Fetching remote schemas is not allowed (use --allow-fetch for force)" |
| 455 | ) |
| 456 | import requests |
| 457 | |
| 458 | frag_split = ref.split("#") |
| 459 | base_url = frag_split[0] |
| 460 | |
| 461 | target = self._refs.get(base_url) |
| 462 | if target is None: |
| 463 | target = self.resolve_refs( |
| 464 | requests.get(ref).json(), base_url |
| 465 | ) |
| 466 | self._refs[base_url] = target |
| 467 | |
| 468 | if len(frag_split) == 1 or frag_split[-1] == "": |
| 469 | return target |
| 470 | elif ref.startswith("#/"): |
| 471 | target = schema |
| 472 | ref = f"{url}{ref}" |
| 473 | n["$ref"] = ref |
| 474 | else: |
| 475 | raise ValueError(f"Unsupported ref {ref}") |
| 476 | |
| 477 | for sel in ref.split("#")[-1].split("/")[1:]: |
| 478 | assert target is not None and sel in target, ( |
| 479 | f"Error resolving ref {ref}: {sel} not in {target}" |
| 480 | ) |
| 481 | target = target[sel] |
| 482 | |
| 483 | self._refs[ref] = target |
| 484 | else: |
| 485 | for v in n.values(): |
| 486 | visit(v) |
| 487 | |
| 488 | return n |
| 489 | |
| 490 | return visit(schema) |
| 491 |
no test coverage detected