(schema: unknown)
| 995 | } |
| 996 | |
| 997 | export function collectExternalSchemaRefNames(schema: unknown): Map<string, Set<string>> { |
| 998 | const refs = new Map<string, Set<string>>(); |
| 999 | |
| 1000 | const visit = (value: unknown): void => { |
| 1001 | if (Array.isArray(value)) { |
| 1002 | for (const item of value) visit(item); |
| 1003 | return; |
| 1004 | } |
| 1005 | |
| 1006 | if (!value || typeof value !== "object") return; |
| 1007 | |
| 1008 | const node = value as Record<string, unknown>; |
| 1009 | if (typeof node.$ref === "string") { |
| 1010 | const externalRef = parseExternalSchemaRef(node.$ref); |
| 1011 | if (externalRef) { |
| 1012 | let bucket = refs.get(externalRef.schemaFile); |
| 1013 | if (!bucket) { |
| 1014 | bucket = new Set<string>(); |
| 1015 | refs.set(externalRef.schemaFile, bucket); |
| 1016 | } |
| 1017 | bucket.add(externalRef.definitionName); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | for (const child of Object.values(node)) visit(child); |
| 1022 | }; |
| 1023 | |
| 1024 | visit(schema); |
| 1025 | return refs; |
| 1026 | } |
| 1027 | |
| 1028 | /** Resolve a `$ref` path against a definitions map, returning the referenced schema. */ |
| 1029 | export function resolveRef( |
no test coverage detected
searching dependent graphs…