(schema: any)
| 16 | * Handles both legacy format with fields array and new JSON Schema format |
| 17 | */ |
| 18 | export 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 |
no outgoing calls
no test coverage detected