MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / hoistDefinitions

Function hoistDefinitions

packages/core/sdk/src/schema-refs.ts:62–85  ·  view source on GitHub ↗
(
  schema: unknown,
)

Source from the content-addressed store, hash-verified

60 * definitions and `defs` is a flat map of definition name → schema.
61 */
62export 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.

Callers 2

buildWrappedObjectSchemaFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected