@@ -1296,7 +1296,8 @@ static const char *annotation_route_method(const char *name) {
12961296 }
12971297 /* JAX-RS bare-verb annotations (@GET/@POST/...) — path comes from @Path. */
12981298 if (strcmp (name , "GET" ) == 0 || strcmp (name , "POST" ) == 0 || strcmp (name , "PUT" ) == 0 ||
1299- strcmp (name , "DELETE" ) == 0 || strcmp (name , "PATCH" ) == 0 ) {
1299+ strcmp (name , "DELETE" ) == 0 || strcmp (name , "PATCH" ) == 0 || strcmp (name , "HEAD" ) == 0 ||
1300+ strcmp (name , "OPTIONS" ) == 0 ) {
13001301 return name ;
13011302 }
13021303 return NULL ;
@@ -1605,35 +1606,85 @@ static bool try_route_from_annotation(CBMArena *a, TSNode annotation, const char
16051606 return true;
16061607}
16071608
1608- /* Scan the annotation nodes nested in a JVM/C# `modifiers`/`attribute_list`
1609- * wrapper (and direct children) for a route-mapping annotation. Java/Kotlin
1610- * Spring annotations (@GetMapping, @RequestMapping, ...) live here rather than
1611- * as prev-siblings, so the prev-sibling decorator walk never sees them. */
1612- static bool extract_route_from_annotations (CBMArena * a , TSNode func_node , const char * source ,
1613- const CBMLangSpec * spec , const char * * out_path ,
1614- const char * * out_method ) {
1615- TSNode modifiers = find_jvm_modifiers (func_node , spec -> language );
1609+ /* Scan ALL annotation nodes nested in a JVM/C# `modifiers`/`attribute_list`
1610+ * wrapper (and direct children), collecting route information from the whole
1611+ * set instead of stopping at the first mapping annotation. Java/Kotlin Spring
1612+ * annotations (@GetMapping, @RequestMapping, ...) live here rather than as
1613+ * prev-siblings, so the prev-sibling decorator walk never sees them.
1614+ *
1615+ * JAX-RS splits the route across two annotations: the verb comes from a bare
1616+ * @GET/@POST/... and the path from a sibling @Path("..."). Returning on the
1617+ * first mapping annotation therefore dropped every method-level @Path
1618+ * (the @GET matched first, defaulted the path to "/", and @Path was never
1619+ * read), and class-level @Path prefixes were never recognized at all. */
1620+ static void scan_route_annotations (CBMArena * a , TSNode owner , const char * source ,
1621+ const CBMLangSpec * spec , const char * * out_map_path ,
1622+ const char * * out_method , const char * * out_jax_path ) {
1623+ * out_map_path = NULL ;
1624+ * out_method = NULL ;
1625+ * out_jax_path = NULL ;
1626+
1627+ TSNode wrappers [2 ];
1628+ int wn = 0 ;
1629+ TSNode modifiers = find_jvm_modifiers (owner , spec -> language );
16161630 if (!ts_node_is_null (modifiers )) {
1617- uint32_t mc = ts_node_child_count (modifiers );
1618- for (uint32_t mi = 0 ; mi < mc ; mi ++ ) {
1619- TSNode mchild = ts_node_child (modifiers , mi );
1620- if (cbm_kind_in_set (mchild , spec -> decorator_node_types ) &&
1621- try_route_from_annotation (a , mchild , source , out_path , out_method )) {
1622- return true;
1623- }
1624- }
1631+ wrappers [wn ++ ] = modifiers ;
16251632 }
16261633 /* Direct-child annotations (some grammars attach the annotation as a child
16271634 * of the method node rather than under `modifiers`). */
1628- uint32_t cc = ts_node_child_count (func_node );
1629- for (uint32_t ci = 0 ; ci < cc ; ci ++ ) {
1630- TSNode child = ts_node_child (func_node , ci );
1631- if (cbm_kind_in_set (child , spec -> decorator_node_types ) &&
1632- try_route_from_annotation (a , child , source , out_path , out_method )) {
1633- return true;
1635+ wrappers [wn ++ ] = owner ;
1636+
1637+ for (int w = 0 ; w < wn ; w ++ ) {
1638+ uint32_t cc = ts_node_child_count (wrappers [w ]);
1639+ for (uint32_t ci = 0 ; ci < cc ; ci ++ ) {
1640+ TSNode child = ts_node_child (wrappers [w ], ci );
1641+ if (!cbm_kind_in_set (child , spec -> decorator_node_types )) {
1642+ continue ;
1643+ }
1644+ TSNode name_node = annotation_name_node (child );
1645+ if (ts_node_is_null (name_node )) {
1646+ continue ;
1647+ }
1648+ char * name = cbm_node_text (a , name_node , source );
1649+ if (!name ) {
1650+ continue ;
1651+ }
1652+ if (!* out_jax_path && strcmp (name , "Path" ) == 0 ) {
1653+ TSNode args = annotation_args_node (child );
1654+ if (!ts_node_is_null (args )) {
1655+ * out_jax_path = extract_route_path_from_args (a , args , source );
1656+ }
1657+ continue ;
1658+ }
1659+ if (!* out_method ) {
1660+ const char * method = annotation_route_method (name );
1661+ if (method ) {
1662+ * out_method = method ;
1663+ TSNode args = annotation_args_node (child );
1664+ if (!ts_node_is_null (args )) {
1665+ * out_map_path = extract_route_path_from_args (a , args , source );
1666+ }
1667+ }
1668+ }
16341669 }
16351670 }
1636- return false;
1671+ }
1672+
1673+ static bool extract_route_from_annotations (CBMArena * a , TSNode func_node , const char * source ,
1674+ const CBMLangSpec * spec , const char * * out_path ,
1675+ const char * * out_method ) {
1676+ const char * map_path = NULL ;
1677+ const char * method = NULL ;
1678+ const char * jax_path = NULL ;
1679+ scan_route_annotations (a , func_node , source , spec , & map_path , & method , & jax_path );
1680+ /* Method-level routes still require a verb/mapping annotation; a lone
1681+ * @Path (JAX-RS sub-resource locator) is not an endpoint by itself. */
1682+ if (!method ) {
1683+ return false;
1684+ }
1685+ * out_method = method ;
1686+ * out_path = map_path ? map_path : (jax_path ? jax_path : "/" );
1687+ return true;
16371688}
16381689
16391690static void extract_route_from_decorators (CBMArena * a , TSNode func_node , const char * source ,
@@ -1702,10 +1753,18 @@ static const char *join_route_paths(CBMArena *a, const char *prefix, const char
17021753
17031754static const char * spring_class_route_prefix (CBMArena * a , TSNode class_node , const char * source ,
17041755 const CBMLangSpec * spec ) {
1705- const char * prefix = NULL ;
1756+ const char * map_path = NULL ;
17061757 const char * method = NULL ;
1707- if (extract_route_from_annotations (a , class_node , source , spec , & prefix , & method )) {
1708- return prefix ;
1758+ const char * jax_path = NULL ;
1759+ scan_route_annotations (a , class_node , source , spec , & map_path , & method , & jax_path );
1760+ if (map_path ) {
1761+ return map_path ; /* @RequestMapping("/api") and friends */
1762+ }
1763+ if (jax_path ) {
1764+ return jax_path ; /* JAX-RS class-level @Path("/api") carries no verb */
1765+ }
1766+ if (method ) {
1767+ return "/" ; /* mapping annotation without a path argument */
17091768 }
17101769 return NULL ;
17111770}
0 commit comments