MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / endpointGroupRoutes

Function endpointGroupRoutes

src/resolution/frameworks/csharp.ts:413–439  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

411 * `qualifiedName` keeps the group and the sub-path.
412 */
413function 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`. */
442function joinCsPath(prefix: string, sub: string): string {

Callers 1

postExtractFunction · 0.85

Calls 6

joinCsPathFunction · 0.85
pushMethod · 0.80
getAllFilesMethod · 0.65
readFileMethod · 0.65
execMethod · 0.65
getNodesByKindMethod · 0.65

Tested by

no test coverage detected