(value: unknown)
| 1498 | } |
| 1499 | |
| 1500 | const rewriteInlinedRefs = (value: unknown): unknown => { |
| 1501 | if (Array.isArray(value)) { |
| 1502 | return value.map((item) => rewriteInlinedRefs(item)); |
| 1503 | } |
| 1504 | |
| 1505 | if (!value || typeof value !== "object") { |
| 1506 | return value; |
| 1507 | } |
| 1508 | |
| 1509 | const result: Record<string, unknown> = {}; |
| 1510 | for (const [key, child] of Object.entries(value as Record<string, unknown>)) { |
| 1511 | result[key] = rewriteInlinedRefs(child); |
| 1512 | } |
| 1513 | |
| 1514 | if (typeof result.$ref === "string") { |
| 1515 | const localRef = parseLocalDefinitionRef(result.$ref); |
| 1516 | const externalRef = parseExternalSchemaRef(result.$ref); |
| 1517 | const mappedName = |
| 1518 | localRef ? nameMap.get(localRef) : |
| 1519 | externalRef?.schemaFile === externalSchemaFile ? nameMap.get(externalRef.definitionName) : |
| 1520 | undefined; |
| 1521 | if (mappedName) { |
| 1522 | result.$ref = `#/definitions/${mappedName}`; |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | return result; |
| 1527 | }; |
| 1528 | |
| 1529 | for (const name of [...reachableDefinitions].sort()) { |
| 1530 | const definition = externalDefinitions[name]; |
no test coverage detected
searching dependent graphs…