(obj, segments, operationId)
| 29 | // Build nested object structure from path segments. |
| 30 | // When a leaf (operationId string) would get children, promote to nested object. When multiple ops share a path, use action keys. |
| 31 | function buildNestedObject(obj, segments, operationId) { |
| 32 | if (segments.length === 0) return operationId |
| 33 | |
| 34 | const [first, ...rest] = segments |
| 35 | const key = toCamelCase(first) |
| 36 | |
| 37 | if (rest.length === 0) { |
| 38 | const existing = obj[key] |
| 39 | if (typeof existing === 'string') |
| 40 | obj[key] = { [toActionKey(existing)]: existing, [toActionKey(operationId)]: operationId } |
| 41 | else if (existing && typeof existing === 'object' && !Array.isArray(existing)) |
| 42 | obj[key][toActionKey(operationId)] = operationId |
| 43 | else obj[key] = operationId |
| 44 | |
| 45 | return obj |
| 46 | } |
| 47 | |
| 48 | const existing = obj[key] |
| 49 | if (typeof existing === 'string') obj[key] = { [toActionKey(existing)]: existing } |
| 50 | |
| 51 | if (!obj[key] || typeof obj[key] === 'string') obj[key] = {} |
| 52 | |
| 53 | buildNestedObject(obj[key], rest, operationId) |
| 54 | return obj |
| 55 | } |
| 56 | |
| 57 | // Generate TypeScript code for nested object |
| 58 | function generateNestedObject(obj, indent = 0) { |
no test coverage detected