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

Function schemaExample

apps/cli/src/tooling.ts:288–328  ·  view source on GitHub ↗
(schema: unknown, depth = 0)

Source from the content-addressed store, hash-verified

286};
287
288const schemaExample = (schema: unknown, depth = 0): unknown => {
289 if (!isRecord(schema) || depth > 4) return {};
290
291 if (Array.isArray(schema.enum) && schema.enum.length > 0) {
292 return schema.enum[0];
293 }
294
295 const candidate = Array.isArray(schema.oneOf)
296 ? schema.oneOf[0]
297 : Array.isArray(schema.anyOf)
298 ? schema.anyOf[0]
299 : Array.isArray(schema.allOf)
300 ? schema.allOf[0]
301 : undefined;
302
303 if (candidate !== undefined) {
304 return schemaExample(candidate, depth + 1);
305 }
306
307 if (schema.type === "string") return "<string>";
308 if (schema.type === "number" || schema.type === "integer") return 0;
309 if (schema.type === "boolean") return false;
310 if (schema.type === "array") return [];
311
312 const properties = isRecord(schema.properties) ? schema.properties : undefined;
313 if (schema.type === "object" || properties) {
314 const required = Array.isArray(schema.required)
315 ? schema.required.filter((key): key is string => typeof key === "string")
316 : undefined;
317 const keys = Object.keys(properties ?? {});
318 const selectedKeys = required && required.length > 0 ? required : keys;
319 const result: Record<string, unknown> = {};
320 for (const key of selectedKeys) {
321 const value = properties?.[key];
322 result[key] = schemaExample(value, depth + 1);
323 }
324 return result;
325 }
326
327 return {};
328};
329
330export const buildResumeContentTemplate = (
331 requestedSchema: Record<string, unknown> | undefined,

Callers 1

Calls 1

isRecordFunction · 0.70

Tested by

no test coverage detected