@@ -1416,7 +1416,8 @@ static bool is_route_string_kind(const char *kind) {
14161416 strcmp (kind , "interpreted_string_literal" ) == 0 ;
14171417}
14181418
1419- static const char * route_path_from_string_node (CBMArena * a , TSNode node , const char * source ) {
1419+ static const char * route_path_from_string_node (CBMArena * a , TSNode node , const char * source ,
1420+ bool allow_relative ) {
14201421 if (!is_route_string_kind (ts_node_type (node ))) {
14211422 return NULL ;
14221423 }
@@ -1428,30 +1429,41 @@ static const char *route_path_from_string_node(CBMArena *a, TSNode node, const c
14281429 if (plen >= PAIR_CHARS && (path [0 ] == '"' || path [0 ] == '\'' )) {
14291430 path = cbm_arena_strndup (a , path + SKIP_CHAR , (size_t )(plen - PAIR_CHARS ));
14301431 }
1431- return (path && path [0 ] == '/' ) ? path : NULL ;
1432+ if (!path || path [0 ] == '/' || !allow_relative ) {
1433+ return (path && path [0 ] == '/' ) ? path : NULL ;
1434+ }
1435+ /* JAX-RS @Path values are relative URI templates; a leading slash is
1436+ * optional and ignored by the framework. Route nodes use absolute-looking
1437+ * paths consistently, so normalize a non-empty relative value here. An
1438+ * empty @Path("") means "the class path itself": leave it unset so the
1439+ * caller falls back exactly as it does for a method without @Path. */
1440+ return path [0 ] ? cbm_arena_sprintf (a , "/%s" , path ) : NULL ;
14321441}
14331442
14341443static const char * find_route_path_literal (CBMArena * a , TSNode node , const char * source ,
1435- int max_depth ) {
1444+ int max_depth , bool allow_relative ) {
14361445 if (ts_node_is_null (node ) || max_depth < 0 ) {
14371446 return NULL ;
14381447 }
1439- const char * path = route_path_from_string_node (a , node , source );
1448+ const char * path = route_path_from_string_node (a , node , source , allow_relative );
14401449 if (path || max_depth == 0 ) {
14411450 return path ;
14421451 }
14431452 uint32_t nc = ts_node_named_child_count (node );
14441453 for (uint32_t i = 0 ; i < nc && i < DECORATOR_SCAN_LIMIT ; i ++ ) {
1445- path = find_route_path_literal (a , ts_node_named_child (node , i ), source , max_depth - 1 );
1454+ path = find_route_path_literal (a , ts_node_named_child (node , i ), source , max_depth - 1 ,
1455+ allow_relative );
14461456 if (path ) {
14471457 return path ;
14481458 }
14491459 }
14501460 return NULL ;
14511461}
14521462
1453- // Extract route path from decorator arguments (first string that starts with /).
1454- static const char * extract_route_path_from_args (CBMArena * a , TSNode args , const char * source ) {
1463+ // Extract route path from decorator arguments. Generic mappings keep only
1464+ // slash-prefixed strings; JAX-RS @Path additionally accepts relative templates.
1465+ static const char * extract_route_path_from_args (CBMArena * a , TSNode args , const char * source ,
1466+ bool allow_relative ) {
14551467 /* Every argument is checked. Java and Kotlin put no order on annotation
14561468 * attributes, so `path` can sit anywhere in the list. Stopping early left
14571469 * a real route unread and formed no Route node. Each argument's own
@@ -1464,7 +1476,8 @@ static const char *extract_route_path_from_args(CBMArena *a, TSNode args, const
14641476 * @GetMapping(path = {"/orders"})
14651477 * Walk a bounded subtree and keep the first string literal that is
14661478 * path-shaped, while ignoring non-route literals such as media types. */
1467- const char * path = find_route_path_literal (a , arg , source , CBM_DESCENDANT_MAX_DEPTH );
1479+ const char * path =
1480+ find_route_path_literal (a , arg , source , CBM_DESCENDANT_MAX_DEPTH , allow_relative );
14681481 if (path ) {
14691482 return path ;
14701483 }
@@ -1610,7 +1623,7 @@ static bool try_route_from_decorator_call(CBMArena *a, TSNode dchild, const char
16101623
16111624 TSNode args = find_decorator_args (dchild );
16121625 if (!ts_node_is_null (args )) {
1613- const char * path = extract_route_path_from_args (a , args , source );
1626+ const char * path = extract_route_path_from_args (a , args , source , false );
16141627 if (path ) {
16151628 * out_path = path ;
16161629 * out_method = method ;
@@ -1690,7 +1703,7 @@ static bool try_route_from_annotation(CBMArena *a, TSNode annotation, const char
16901703 TSNode args = annotation_args_node (annotation );
16911704 const char * path = NULL ;
16921705 if (!ts_node_is_null (args )) {
1693- path = extract_route_path_from_args (a , args , source );
1706+ path = extract_route_path_from_args (a , args , source , false );
16941707 }
16951708 * out_path = path ? path : "/" ;
16961709 * out_method = method ;
@@ -1740,7 +1753,7 @@ static void scan_route_annotations(CBMArena *a, TSNode owner, const char *source
17401753 if (!* out_jax_path && strcmp (name , "Path" ) == 0 ) {
17411754 TSNode args = annotation_args_node (child );
17421755 if (!ts_node_is_null (args )) {
1743- * out_jax_path = extract_route_path_from_args (a , args , source );
1756+ * out_jax_path = extract_route_path_from_args (a , args , source , true );
17441757 }
17451758 continue ;
17461759 }
@@ -1750,7 +1763,7 @@ static void scan_route_annotations(CBMArena *a, TSNode owner, const char *source
17501763 * out_method = method ;
17511764 TSNode args = annotation_args_node (child );
17521765 if (!ts_node_is_null (args )) {
1753- * out_map_path = extract_route_path_from_args (a , args , source );
1766+ * out_map_path = extract_route_path_from_args (a , args , source , false );
17541767 }
17551768 }
17561769 }
@@ -5147,7 +5160,8 @@ static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node,
51475160
51485161 def .decorators = extract_decorators (a , child , ctx -> source , ctx -> language , spec );
51495162 extract_route_from_decorators (a , child , ctx -> source , spec , & def .route_path , & def .route_method );
5150- if (def .route_path && (ctx -> language == CBM_LANG_JAVA || ctx -> language == CBM_LANG_KOTLIN )) {
5163+ if (def .route_path && (ctx -> language == CBM_LANG_JAVA || ctx -> language == CBM_LANG_KOTLIN ||
5164+ ctx -> language == CBM_LANG_SCALA )) {
51515165 const char * prefix = spring_class_route_prefix (a , class_node , ctx -> source , spec );
51525166 def .route_path = join_route_paths (a , prefix , def .route_path );
51535167 }
0 commit comments