#!/usr/bin/env node /** * Test parameter extraction for login endpoint specifically */ import fs from 'fs'; import path from 'path'; // Read the endpoints file const endpointsPath = path.join(process.cwd(), 'src/config/endpoints.js'); const content = fs.readFileSync(endpointsPath, 'utf8'); // Find the login endpoint block const loginRegex = /\{\s*path:\s*["']\/api\/login["'][\s\S]*?\}/; const loginMatch = content.match(loginRegex); if (loginMatch) { console.log('Found login endpoint block:'); console.log(loginMatch[0]); console.log('\n' + '='.repeat(50) + '\n'); // Extract parameters section const paramMatch = loginMatch[0].match(/parameters:\s*\{([\s\S]*?)\}(?:\s*,|\s*\})/); if (paramMatch) { console.log('Parameters section:'); console.log(paramMatch[1]); console.log('\n' + '='.repeat(50) + '\n'); // Test the new extraction method const parametersText = paramMatch[1]; const parameters = []; let braceCount = 0; let currentParam = ''; let paramName = ''; let inParam = false; console.log('Testing new extraction method...'); for (let i = 0; i < parametersText.length; i++) { const char = parametersText[i]; // Look for parameter name followed by colon if (!inParam && /\w/.test(char)) { const remaining = parametersText.slice(i); const paramMatch = remaining.match(/^(\w+):\s*\{/); if (paramMatch) { paramName = paramMatch[1]; console.log(`Found parameter: ${paramName}`); i += paramMatch[0].length - 1; // Skip to opening brace inParam = true; braceCount = 1; currentParam = ''; continue; } } if (inParam) { if (char === '{') braceCount++; if (char === '}') braceCount--; if (braceCount > 0) { currentParam += char; } else { console.log(`Parameter content for ${paramName}: ${currentParam}`); // End of parameter, extract details const typeMatch = currentParam.match(/type:\s*["']([^"']+)["']/); const type = typeMatch ? typeMatch[1] : "string"; const requiredMatch = currentParam.match(/required:\s*(true|false)/); const required = requiredMatch ? requiredMatch[1] === "true" : false; const descMatch = currentParam.match(/description:\s*["']([^"']*?)["']/); const description = descMatch ? descMatch[1] : ""; parameters.push({ name: paramName.trim(), type: type.trim(), required, description: description.trim(), }); console.log(`Extracted: ${paramName} (${type}, required: ${required})`); inParam = false; currentParam = ''; paramName = ''; } } } console.log('\nFinal extracted parameters:'); console.log(JSON.stringify(parameters, null, 2)); // Test formatting const required = parameters.filter(p => p.required); const optional = parameters.filter(p => !p.required); let result = ''; if (required.length > 0) { result += '**Required:** ' + required.map(p => `${p.name} (${p.type})`).join(', '); } if (optional.length > 0) { if (result) result += ', '; result += '**Optional:** ' + optional.map(p => `${p.name} (${p.type})`).join(', '); } console.log('\nFormatted parameters:'); console.log(result || 'No parameters'); } } else { console.log('Login endpoint not found!'); }