module

Analyzer::CSharp::MinimalApiSupport

Constants

CONST_REFERENCE_RE = /(?:Request|request)\.(?:Query|Headers|Cookies|Form)\[\s*[A-Za-z_]|\[From\w+\s*\(\s*Name\s*=\s*[A-Za-z_]/

request.Headers[TokenHeader] / [FromHeader(Name = TokenHeader)]: a key held in a string constant.

CONST_STRING_RE = /\bconst\s+string\s+([A-Za-z_]\w*)\s*=\s*@?"([^"]*)"\s*;/
MAP_ANY_METHOD_RE = /\.\s*Map(?:HealthChecks|Forwarder)?\s*\(/

Map(pattern, …) and the extensions that wrap it with no method filter: MapHealthChecks("/health"), YARP's MapForwarder("/x/{id}", …).

MAP_ANY_PREFIX_RE = /\.?\s*Map(?:Get|Post|Put|Delete|Patch|Head|Options|Methods|HealthChecks|Forwarder)?\s*(?:<[^<>()]*>\s*)?\(/
MAP_ANY_ROUTE_RE = /(?:\b([A-Za-z_][A-Za-z0-9_]*)\s*\.\s*)?Map(?:HealthChecks|Forwarder)?\s*\(\s*(?:[A-Za-z_][A-Za-z0-9_]*\s*:\s*)?@?"([^"]*)"/m
MAP_CALL_RE = /\bMap(?:Get|Post|Put|Delete|Patch|Head|Options|Methods|HealthChecks|Forwarder)?\s*(?:<[^<>()]*>\s*)?\(/
MAP_METHODS = ["Get", "Post", "Put", "Delete", "Patch", "Head", "Options"] of ::String
MAP_METHODS_RE = /(?:\b([A-Za-z_][A-Za-z0-9_]*)\s*\.\s*)?MapMethods\s*(?:<[^<>()]*>\s*)?\(\s*(?:[A-Za-z_][A-Za-z0-9_]*\s*:\s*)?@?"([^"]*)"\s*,\s*([\s\S]+?)(?:=>|\);)/m
MAP_VERB_ROUTE_RE = /(?:\b([A-Za-z_][A-Za-z0-9_]*)\s*\.\s*)?Map(Get|Post|Put|Delete|Patch|Head|Options)\s*(?:<[^<>()]*>\s*)?\(\s*(?:[A-Za-z_][A-Za-z0-9_]*\s*:\s*)?@?"([^"]*)"/m

Map<Verb> may carry an explicit generic argument — Carter's app.MapPut<Person>("/", …) and the typed MapGet<T> helpers some libraries ship. Without the optional <…> the route literal was never reached and the registration produced no endpoint at all.

MINIMAL_API_MARKER_RE = /\.\s*Map(?:Get|Post|Put|Delete|Patch|Head|Options|Methods)\s*(?:<[^<>()]*>\s*)?\(/
ROUTE_BUILDER_EXTENSION_RE = /\bstatic\s[^;{}()=]*?\b([A-Za-z_][A-Za-z0-9_]*)\s*(?:<[^<>()]*>\s*)?\(\s*this\s+(?:RouteGroupBuilder|IEndpointRouteBuilder|WebApplication)\b/

A static … MapTodosApi(this RouteGroupBuilder group) extension method: the routes it registers on group take the prefix of whichever MapGroup(...) it is called on, possibly from another file —

app.MapGroup("/public/todos").MapTodosApi(); app.MapGroup("/private/todos").MapTodosApi();

SERVICE_BINDING_TYPES = Set {"CancellationToken", "HttpContext", "HttpRequest", "HttpResponse", "ClaimsPrincipal", "IServiceProvider", "ILogger", "ILoggerFactory", "LinkGenerator"}
SIMPLE_BINDING_TYPES = Set {"bool", "byte", "sbyte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "decimal", "char", "string", "Guid", "DateTime", "DateTimeOffset", "TimeSpan"}

Nested types