|
| 1 | +import { readFileSync } from 'node:fs'; |
| 2 | +import path from 'node:path'; |
| 3 | + |
| 4 | +interface Operation { |
| 5 | + summary?: string; |
| 6 | + description?: string; |
| 7 | + operationId?: string; |
| 8 | + tags?: string[]; |
| 9 | +} |
| 10 | + |
| 11 | +const openapiPath = path.join(__dirname, '../../../packages/docs/openapi.json'); |
| 12 | +const doc = JSON.parse(readFileSync(openapiPath, 'utf8')) as { |
| 13 | + paths: Record<string, Record<string, Operation>>; |
| 14 | +}; |
| 15 | + |
| 16 | +type Row = { |
| 17 | + method: string; |
| 18 | + path: string; |
| 19 | + summary: string; |
| 20 | + operationId: string; |
| 21 | + tag: string; |
| 22 | + flag: string; |
| 23 | +}; |
| 24 | + |
| 25 | +const rows: Row[] = []; |
| 26 | + |
| 27 | +for (const [routePath, methods] of Object.entries(doc.paths)) { |
| 28 | + for (const [method, op] of Object.entries(methods)) { |
| 29 | + if (typeof op !== 'object' || !op) continue; |
| 30 | + const summary = op.summary ?? ''; |
| 31 | + const operationId = op.operationId ?? ''; |
| 32 | + const tag = op.tags?.[0] ?? '(no tag)'; |
| 33 | + |
| 34 | + let flag = ''; |
| 35 | + if (!summary) flag = 'MISSING'; |
| 36 | + else if ( |
| 37 | + /^(Get|Post|Put|Patch|Delete)\b.*v1/i.test(summary) || |
| 38 | + summary === operationId || |
| 39 | + /Controller_/.test(summary) |
| 40 | + ) { |
| 41 | + flag = 'AUTO_GEN'; |
| 42 | + } |
| 43 | + |
| 44 | + rows.push({ method: method.toUpperCase(), path: routePath, summary, operationId, tag, flag }); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +rows.sort((a, b) => (a.tag + a.path).localeCompare(b.tag + b.path)); |
| 49 | + |
| 50 | +const flagged = rows.filter((r) => r.flag); |
| 51 | +console.log(`Total operations: ${rows.length}`); |
| 52 | +console.log(`Flagged: ${flagged.length}`); |
| 53 | +console.log(); |
| 54 | + |
| 55 | +let currentTag = ''; |
| 56 | +for (const r of flagged) { |
| 57 | + if (r.tag !== currentTag) { |
| 58 | + currentTag = r.tag; |
| 59 | + console.log(`\n## ${currentTag}`); |
| 60 | + } |
| 61 | + console.log(` [${r.flag.padEnd(9)}] ${r.method.padEnd(6)} ${r.path} — "${r.summary}"`); |
| 62 | +} |
0 commit comments