(param, allParams, options = {})
| 510 | } |
| 511 | |
| 512 | function generateObjectInterface(param, allParams, options = {}) { |
| 513 | // Check if this is an object parameter (either required or optional) |
| 514 | const isObjectParam = param.type && ( |
| 515 | (param.type.type === 'OptionalType' && param.type.expression?.name === 'Object') || |
| 516 | (param.type.type === 'NameExpression' && param.type.name === 'Object') |
| 517 | ); |
| 518 | |
| 519 | if (!isObjectParam || !param.name) { |
| 520 | return null; |
| 521 | } |
| 522 | |
| 523 | let nestedParams = []; |
| 524 | |
| 525 | |
| 526 | // First, check if the parameter has a properties array (JSDoc properties field) |
| 527 | if (param.properties && Array.isArray(param.properties)) { |
| 528 | nestedParams = param.properties.filter(prop => |
| 529 | prop.name && prop.name.startsWith(param.name + '.') |
| 530 | ); |
| 531 | } |
| 532 | |
| 533 | // Fallback: Look for nested parameters with dot notation in allParams |
| 534 | if (nestedParams.length === 0) { |
| 535 | nestedParams = allParams.filter(p => |
| 536 | p.name && p.name.startsWith(param.name + '.') && p.name !== param.name |
| 537 | ); |
| 538 | } |
| 539 | |
| 540 | if (nestedParams.length === 0) { |
| 541 | return null; |
| 542 | } |
| 543 | |
| 544 | // Generate interface properties |
| 545 | const properties = nestedParams.map(nestedParam => { |
| 546 | const propName = nestedParam.name.substring(param.name.length + 1); // Remove 'paramName.' prefix |
| 547 | const propType = nestedParam.type ? convertTypeToTypeScript(nestedParam.type, options) : 'any'; |
| 548 | // Properties are optional if they have a default value or are explicitly marked as optional |
| 549 | const isOptional = nestedParam.optional || nestedParam.type?.type === 'OptionalType' || nestedParam.default !== undefined; |
| 550 | return `${propName}${isOptional ? '?' : ''}: ${propType}`; |
| 551 | }); |
| 552 | |
| 553 | return `{ ${properties.join('; ')} }`; |
| 554 | } |
| 555 | |
| 556 | function generateParamDeclaration(param, options = {}, allParams = []) { |
| 557 | if (!param) return ''; |
no test coverage detected