Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(routes): compose class-level @Path for Scala JAX-RS resources

Hubert Tarnackid4931241adae
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index b94c0b4c2..fa42b6c52 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -5005,7 +5005,8 @@ static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node,
def.decorators = extract_decorators(a, child, ctx->source, ctx->language, spec);
extract_route_from_decorators(a, child, ctx->source, spec, &def.route_path, &def.route_method);
- if (def.route_path && (ctx->language == CBM_LANG_JAVA || ctx->language == CBM_LANG_KOTLIN)) {
+ if (def.route_path && (ctx->language == CBM_LANG_JAVA || ctx->language == CBM_LANG_KOTLIN ||
+ ctx->language == CBM_LANG_SCALA)) {
const char *prefix = spring_class_route_prefix(a, class_node, ctx->source, spec);
def.route_path = join_route_paths(a, prefix, def.route_path);
}
diff --git a/tests/test_edge_types_probe.c b/tests/test_edge_types_probe.c
index 5469e19c8..b591c5bf2 100644
--- a/tests/test_edge_types_probe.c
+++ b/tests/test_edge_types_probe.c
@@ -528,6 +528,29 @@ TEST(handles_spring_java_relative_string_not_route) {
PASS();
}
+/* JAX-RS (Scala): class-level @Path must be composed with both an empty
+ * method path and a non-empty one. Without the Scala branch in
+ * push_method_def, unrelated resources collapse onto the global verb/root
+ * Route node. */
+TEST(handles_jaxrs_scala) {
+ static const char *routes[] = {"/billingAccount", "/billingAccount/{id}",
+ "/billingAccount/{id}/attachment/{attachmentId}/content", NULL};
+ static const EtFile f[] = {
+ {"BillingAccountApiController.scala",
+ "package com.example\n\n"
+ "import jakarta.ws.rs.{GET, POST, Path}\n\n"
+ "@Path(\"/billingAccount\")\nclass BillingAccountApiController {\n"
+ " @POST\n @Path(\"\")\n"
+ " def createBillingAccount(): String = \"created\"\n\n"
+ " @GET\n @Path(\"{id}\")\n"
+ " def retrieveBillingAccount(): String = \"account\"\n\n"
+ " @GET\n @Path(\"{id}/attachment/{attachmentId}/content\")\n"
+ " def retrieveAttachment(): String = \"attachment\"\n}\n"}};
+ ASSERT_TRUE(et_edge_present(f, 1, "HANDLES", 3));
+ ASSERT_TRUE(et_routes_exact(f, 1, routes));
+ PASS();
+}
+
/* ASP.NET Minimal API (C#) — route registration via static MapGet/MapPost calls
* with identifier handlers, under a Microsoft/AspNetCore path so the resolved
* callee QN carries the "MapGet"/"Microsoft.AspNetCore" route-reg substrings.
@@ -1680,6 +1703,7 @@ SUITE(edge_types_probe) {
RUN_TEST(handles_jaxrs_java);
RUN_TEST(handles_jaxrs_java_relative_path);
RUN_TEST(handles_spring_java_relative_string_not_route);
+ RUN_TEST(handles_jaxrs_scala);
RUN_TEST(handles_aspnet_csharp);
RUN_TEST(handles_laravel_php);
RUN_TEST(handles_laravel_facade_routes_issue952);