* A FastEndpoints route named by a constant (`Post(CreateContributorRequest.Route)`) * gets the constant's value: `public const string Route = "/Contributors";` in * that class, wherever it is declared. Idempotent — the qualified name keeps the * expression.
(context: ResolutionContext)
| 379 | * expression. |
| 380 | */ |
| 381 | function fastEndpointConstantRoutes(context: ResolutionContext): Node[] { |
| 382 | const updates: Node[] = []; |
| 383 | for (const route of context.getNodesByKind('route')) { |
| 384 | if (route.language !== 'csharp') continue; |
| 385 | const q = /::fastendpoint:([A-Z]+):const:([A-Za-z_]\w*)\.([A-Za-z_]\w*)$/.exec(route.qualifiedName); |
| 386 | if (!q) continue; |
| 387 | const [, method, owner, field] = q; |
| 388 | let value: string | null = null; |
| 389 | for (const decl of context.getNodesByName(owner!)) { |
| 390 | if (decl.language !== 'csharp' || (decl.kind !== 'class' && decl.kind !== 'struct')) continue; |
| 391 | const text = context.readFile(decl.filePath) ?? ''; |
| 392 | const m = new RegExp(`\\b(?:const\\s+string|static\\s+readonly\\s+string|static\\s+string)\\s+${field}\\s*=\\s*"([^"]+)"`).exec(text); |
| 393 | if (m) { |
| 394 | value = m[1]!; |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | if (!value) continue; |
| 399 | const name = `${method} ${joinCsPath('', value)}`; |
| 400 | if (name !== route.name) updates.push({ ...route, name }); |
| 401 | } |
| 402 | return updates; |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * The endpoint-group prefix convention, read once from the app: the |
no test coverage detected