in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/dotnet/AspNetCoreApiScanner.java [887:932]
private void extractRazorPageHandlers(DotNetAst.CSharpClass csharpClass, Path file, List<ApiEndpoint> apiEndpoints) {
// Derive route from file path
String filePath = file.toString();
String route = deriveRazorPageRoute(filePath);
for (DotNetAst.Method method : csharpClass.methods()) {
String methodName = method.name();
// Match OnGet, OnPost, OnGetAsync, OnPostAsync, etc.
if (methodName.startsWith("On") && (methodName.contains("Get") || methodName.contains("Post") ||
methodName.contains("Put") || methodName.contains("Delete") || methodName.contains("Patch"))) {
// Extract HTTP method from handler name
String httpMethod = extractHttpMethodFromHandler(methodName);
if (httpMethod == null) {
continue;
}
// Extract parameters
String requestSchema = buildRequestSchemaFromAst(method.parameters(), route);
// Check for handler-specific route (e.g., OnGetDetails with [RouteAttribute])
String handlerRoute = route;
for (DotNetAst.Attribute attribute : method.attributes()) {
if (attribute.name().equals("Route") && !attribute.arguments().isEmpty()) {
String customRoute = attribute.arguments().get(0).replace("\"", "");
handlerRoute = customRoute.startsWith(PATH_SEPARATOR) ? customRoute : PATH_SEPARATOR + customRoute;
}
}
ApiEndpoint endpoint = new ApiEndpoint(
csharpClass.name(),
ApiType.REST,
handlerRoute,
httpMethod,
csharpClass.name() + "." + methodName,
requestSchema,
method.returnType(),
null
);
apiEndpoints.add(endpoint);
log.debug("Found Razor Page handler: {} {} -> {}", httpMethod, handlerRoute, methodName);
}
}
}