(value: unknown)
| 1413 | }; |
| 1414 | |
| 1415 | const rewrite = (value: unknown): unknown => { |
| 1416 | if (Array.isArray(value)) { |
| 1417 | return value.map((item) => rewrite(item)); |
| 1418 | } |
| 1419 | |
| 1420 | if (!value || typeof value !== "object") { |
| 1421 | return value; |
| 1422 | } |
| 1423 | |
| 1424 | const source = value as Record<string, unknown>; |
| 1425 | const result: Record<string, unknown> = {}; |
| 1426 | for (const [childKey, childValue] of Object.entries(source)) { |
| 1427 | if ((childKey === "definitions" || childKey === "$defs") && childValue && typeof childValue === "object" && !Array.isArray(childValue)) { |
| 1428 | const definitions: Record<string, unknown> = {}; |
| 1429 | for (const [definitionName, definitionValue] of Object.entries(childValue as Record<string, unknown>)) { |
| 1430 | if (preserveDefinitions || !sharedNames.has(definitionName)) { |
| 1431 | definitions[definitionName] = rewrite(definitionValue); |
| 1432 | } |
| 1433 | } |
| 1434 | result[childKey] = definitions; |
| 1435 | continue; |
| 1436 | } |
| 1437 | |
| 1438 | result[childKey] = rewrite(childValue); |
| 1439 | } |
| 1440 | |
| 1441 | if (typeof result.$ref === "string") { |
| 1442 | result.$ref = rewriteRef(result.$ref); |
| 1443 | } |
| 1444 | |
| 1445 | return result; |
| 1446 | }; |
| 1447 | |
| 1448 | return rewrite(schema) as T; |
| 1449 | } |
no test coverage detected
searching dependent graphs…