MCPcopy Index your code
hub / github.com/simstudioai/sim / extractFieldsFromSchema

Function extractFieldsFromSchema

apps/sim/lib/core/utils/response-format.ts:18–52  ·  view source on GitHub ↗
(schema: any)

Source from the content-addressed store, hash-verified

16 * Handles both legacy format with fields array and new JSON Schema format
17 */
18export function extractFieldsFromSchema(schema: any): Field[] {
19 if (!schema || typeof schema !== 'object') {
20 return []
21 }
22
23 // Handle legacy format with fields array
24 if (Array.isArray(schema.fields)) {
25 return schema.fields
26 }
27
28 // Handle new JSON Schema format
29 const schemaObj = schema.schema || schema
30 if (!schemaObj || !schemaObj.properties || typeof schemaObj.properties !== 'object') {
31 return []
32 }
33
34 // Extract fields from schema properties
35 return Object.entries(schemaObj.properties).map(([name, prop]: [string, any]) => {
36 // Handle array format like ['string', 'array']
37 if (Array.isArray(prop)) {
38 return {
39 name,
40 type: prop.includes('array') ? 'array' : prop[0] || 'string',
41 description: undefined,
42 }
43 }
44
45 // Handle object format like { type: 'string', description: '...' }
46 return {
47 name,
48 type: prop.type || 'string',
49 description: prop.description,
50 }
51 })
52}
53
54/**
55 * Helper function to safely parse response format

Callers 1

getResponseFormatOutputsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected