* The endpoint-group prefix convention, read once from the app: the * `MapGroup($"/api/{groupName}")` that registers every `IEndpointGroup` * (or `EndpointGroupBase`) under a head — `/api/` — before the class name. * A group route extracted as `POST /TodoItems` becomes `POST /api/TodoItems`; * a
(context: ResolutionContext)
| 411 | * `qualifiedName` keeps the group and the sub-path. |
| 412 | */ |
| 413 | function endpointGroupRoutes(context: ResolutionContext): Node[] { |
| 414 | let head: string | null = null; |
| 415 | let looked = 0; |
| 416 | for (const file of context.getAllFiles()) { |
| 417 | if (!file.endsWith('.cs')) continue; |
| 418 | const content = context.readFile(file); |
| 419 | if (!content || !content.includes('MapGroup')) continue; |
| 420 | if (++looked > 400) break; |
| 421 | const m = /\$"([^"{]*)\{\s*(?:groupName|type\.Name|name|prefix)\s*\}"/.exec(content) ?? /MapGroup\(\s*\$"([^"{]*)\{/.exec(content); |
| 422 | if (m) { |
| 423 | head = m[1]!; |
| 424 | break; |
| 425 | } |
| 426 | } |
| 427 | if (!head || head === '/' || head === '') return []; |
| 428 | const updates: Node[] = []; |
| 429 | for (const route of context.getNodesByKind('route')) { |
| 430 | if (route.language !== 'csharp') continue; |
| 431 | const q = /::group:([A-Za-z_]\w*):([A-Z]+):(.*)$/.exec(route.qualifiedName); |
| 432 | if (!q) continue; |
| 433 | const content = context.readFile(route.filePath); |
| 434 | if (content && /\bRoutePrefix\s*(?:=>|=)\s*"/.test(content)) continue; |
| 435 | const name = `${q[2]} ${joinCsPath(head.replace(/\/+$/, '') + '/' + q[1], q[3]!)}`; |
| 436 | if (name !== route.name) updates.push({ ...route, name }); |
| 437 | } |
| 438 | return updates; |
| 439 | } |
| 440 | |
| 441 | /** Join a class-level [Route] prefix and an action's path into one normalized `/path`. */ |
| 442 | function joinCsPath(prefix: string, sub: string): string { |
no test coverage detected