( schema: unknown, )
| 60 | * definitions and `defs` is a flat map of definition name → schema. |
| 61 | */ |
| 62 | export const hoistDefinitions = ( |
| 63 | schema: unknown, |
| 64 | ): { stripped: unknown; defs: Record<string, unknown> } => { |
| 65 | if (schema == null || typeof schema !== "object") { |
| 66 | return { stripped: schema, defs: {} }; |
| 67 | } |
| 68 | const obj = schema as Obj; |
| 69 | const defs: Record<string, unknown> = {}; |
| 70 | |
| 71 | if (obj.$defs && typeof obj.$defs === "object") { |
| 72 | for (const [k, v] of Object.entries(obj.$defs as Obj)) { |
| 73 | defs[k] = v; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if (obj.definitions && typeof obj.definitions === "object") { |
| 78 | for (const [k, v] of Object.entries(obj.definitions as Obj)) { |
| 79 | defs[k] = v; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | const { $defs: _a, definitions: _b, ...rest } = obj; |
| 84 | return { stripped: rest, defs }; |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * Walk a schema and collect all $ref target names transitively. |
no outgoing calls
no test coverage detected