/** * OpenAPI Path Validator * * Basic smoke test to verify all OpenAPI paths are reachable. * Does NOT replace proper API testing! * * For comprehensive testing, consider: * - Dredd (npm install -g dredd) - Contract testing against OpenAPI spec * - Postman/Newman - Import openapi.json and run automated tests * - Prism (npm install -g @stoplight/prism-cli) - Mock server + validation * - Jest/Supertest - Full integration tests with schema validation * * This script only checks if paths respond (basic reachability check). */ const fs = require('fs'); const path = require('path'); // Read generated openapi.json const specPath = path.join(__dirname, 'docs', 'openapi.json'); const spec = JSON.parse(fs.readFileSync(specPath, 'utf8')); const baseUrl = 'http://localhost:5000'; const paths = Object.keys(spec.paths || {}); console.log(`šŸ” Testing ${paths.length} paths from openapi.json against ${baseUrl}\n`); async function testPath(path, methods) { const method = Object.keys(methods)[0]; // take first method (usually GET) const url = `${baseUrl}${path}`; return new Promise((resolve) => { const http = require('http'); const req = http.request(url, { method: method.toUpperCase() }, (res) => { const status = res.statusCode; const statusEmoji = status === 200 ? 'āœ…' : status === 404 ? 'āŒ' : 'āš ļø'; console.log(`${statusEmoji} ${method.toUpperCase()} ${path} → ${status}`); resolve({ path, status, ok: status === 200 }); }); req.on('error', (err) => { console.log(`šŸ’„ ${method.toUpperCase()} ${path} → ERROR: ${err.message}`); resolve({ path, status: 'ERROR', ok: false }); }); req.end(); }); } (async () => { const results = []; for (const p of paths) { const result = await testPath(p, spec.paths[p]); results.push(result); } const failed = results.filter(r => !r.ok); console.log(`\nšŸ“Š Summary: ${results.length} paths tested, ${failed.length} failed\n`); if (failed.length > 0) { console.log('āŒ Failed paths (likely missing route prefixes):'); failed.forEach(f => console.log(` ${f.path} → ${f.status}`)); console.log('\nšŸ’” Hint: Generator scanned route files without mount prefixes.'); console.log(' Check backend/src/routes/index.js for app.use() calls with prefixes like /api/admin'); } })();