Skip to content

Commit d493124

Browse files
committed
fix(routes): compose class-level @path for Scala JAX-RS resources
Scala JAX-RS resources declare @path on the class exactly like Java and Kotlin, but the class-level prefix was only joined with the method path for those two languages. Include Scala so a method route is emitted as `<class path>/<method path>` instead of the bare method template. Adds a Scala probe test covering both an empty and a non-empty method template. Signed-off-by: Hubert Tarnacki <hubert.tarnacki@gmail.com>
1 parent 452485f commit d493124

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎internal/cbm/extract_defs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5005,7 +5005,8 @@ static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node,
50055005

50065006
def.decorators = extract_decorators(a, child, ctx->source, ctx->language, spec);
50075007
extract_route_from_decorators(a, child, ctx->source, spec, &def.route_path, &def.route_method);
5008-
if (def.route_path && (ctx->language == CBM_LANG_JAVA || ctx->language == CBM_LANG_KOTLIN)) {
5008+
if (def.route_path && (ctx->language == CBM_LANG_JAVA || ctx->language == CBM_LANG_KOTLIN ||
5009+
ctx->language == CBM_LANG_SCALA)) {
50095010
const char *prefix = spring_class_route_prefix(a, class_node, ctx->source, spec);
50105011
def.route_path = join_route_paths(a, prefix, def.route_path);
50115012
}

‎tests/test_edge_types_probe.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,29 @@ TEST(handles_spring_java_relative_string_not_route) {
528528
PASS();
529529
}
530530

531+
/* JAX-RS (Scala): class-level @Path must be composed with both an empty
532+
* method path and a non-empty one. Without the Scala branch in
533+
* push_method_def, unrelated resources collapse onto the global verb/root
534+
* Route node. */
535+
TEST(handles_jaxrs_scala) {
536+
static const char *routes[] = {"/billingAccount", "/billingAccount/{id}",
537+
"/billingAccount/{id}/attachment/{attachmentId}/content", NULL};
538+
static const EtFile f[] = {
539+
{"BillingAccountApiController.scala",
540+
"package com.example\n\n"
541+
"import jakarta.ws.rs.{GET, POST, Path}\n\n"
542+
"@Path(\"/billingAccount\")\nclass BillingAccountApiController {\n"
543+
" @POST\n @Path(\"\")\n"
544+
" def createBillingAccount(): String = \"created\"\n\n"
545+
" @GET\n @Path(\"{id}\")\n"
546+
" def retrieveBillingAccount(): String = \"account\"\n\n"
547+
" @GET\n @Path(\"{id}/attachment/{attachmentId}/content\")\n"
548+
" def retrieveAttachment(): String = \"attachment\"\n}\n"}};
549+
ASSERT_TRUE(et_edge_present(f, 1, "HANDLES", 3));
550+
ASSERT_TRUE(et_routes_exact(f, 1, routes));
551+
PASS();
552+
}
553+
531554
/* ASP.NET Minimal API (C#) — route registration via static MapGet/MapPost calls
532555
* with identifier handlers, under a Microsoft/AspNetCore path so the resolved
533556
* callee QN carries the "MapGet"/"Microsoft.AspNetCore" route-reg substrings.
@@ -1680,6 +1703,7 @@ SUITE(edge_types_probe) {
16801703
RUN_TEST(handles_jaxrs_java);
16811704
RUN_TEST(handles_jaxrs_java_relative_path);
16821705
RUN_TEST(handles_spring_java_relative_string_not_route);
1706+
RUN_TEST(handles_jaxrs_scala);
16831707
RUN_TEST(handles_aspnet_csharp);
16841708
RUN_TEST(handles_laravel_php);
16851709
RUN_TEST(handles_laravel_facade_routes_issue952);

0 commit comments

Comments
 (0)