refactor(tagging): deduplicate tag-dispatch logic across tag controllers (#3594) (#3619)

* refactor(tagging): deduplicate tag-dispatch logic across tag controllers (#3594)

* fix(docs): support superclass REST method extraction in regen_action_docs

- Read inherited JAX-RS methods from superclass when a REST controller extends a base class
- Add test_extract_rest_inherits_methods_from_superclass test
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-14 12:52:37 -04:00
1 parent e82836348b
commit 7981e23dcd
6 files changed
+231 -110

No files matched your search

+24 -7
View File
@@ -90,13 +90,10 @@ def extract_switch_actions(java_source: str) -> list[str]:
return out
def extract_rest_actions(java_source: str) -> list[str]:
"""ucfirst(method name) of @GET/@POST/@PUT/@DELETE/@PATCH methods, source order.
CLASS_EXTENDS_RE = re.compile(r"public\s+(?:abstract\s+)?class\s+\w+\s+extends\s+([A-Za-z0-9_]+)")
Only applies to classes containing a class-level @Path. Returns [] otherwise.
"""
if not CLASS_PATH_RE.search(java_source):
return []
def _extract_raw_rest_methods(java_source: str) -> list[str]:
actions: list[str] = []
pending = False
for line in java_source.splitlines():
@@ -119,6 +116,26 @@ def extract_rest_actions(java_source: str) -> list[str]:
return actions
def extract_rest_actions(java_source: str, source_path: Path | None = None) -> list[str]:
"""ucfirst(method name) of @GET/@POST/@PUT/@DELETE/@PATCH methods, source order.
Only applies to classes containing a class-level @Path. Returns [] otherwise.
Inherited methods from a superclass in the same directory are included first.
"""
if not CLASS_PATH_RE.search(java_source):
return []
actions: list[str] = []
if source_path is not None:
extends_match = CLASS_EXTENDS_RE.search(java_source)
if extends_match:
super_name = extends_match.group(1)
super_path = source_path.parent / f"{super_name}.java"
if super_path.exists():
actions.extend(_extract_raw_rest_methods(super_path.read_text(encoding="utf-8")))
actions.extend(_extract_raw_rest_methods(java_source))
return actions
def extract_actions(entry: ServiceEntry) -> list[str]:
"""Merged, deduped, override-corrected action list for a service.
@@ -133,7 +150,7 @@ def extract_actions(entry: ServiceEntry) -> list[str]:
if source.mode == "switch":
raw = extract_switch_actions(text)
elif source.mode == "rest":
raw = extract_rest_actions(text)
raw = extract_rest_actions(text, source.path)
else:
raise ValueError(f"unknown mode: {source.mode!r}")
for name in raw:
+26
View File
@@ -130,6 +130,32 @@ public class C {
assert r.extract_rest_actions(src) == ["CreateThing", "ListThings"]
def test_extract_rest_inherits_methods_from_superclass(tmp_path: Path):
base_src = """
public abstract class BaseController {
@GET
public Response getBaseItem() { return ok(); }
@DELETE
public Response deleteBaseItem() { return ok(); }
}
"""
sub_src = """
@Path("/items")
public class ChildController extends BaseController {
@POST
public Response createChildItem() { return ok(); }
}
"""
base_file = tmp_path / "BaseController.java"
sub_file = tmp_path / "ChildController.java"
base_file.write_text(base_src, encoding="utf-8")
sub_file.write_text(sub_src, encoding="utf-8")
actions = r.extract_rest_actions(sub_src, sub_file)
assert actions == ["GetBaseItem", "DeleteBaseItem", "CreateChildItem"]
def test_extract_actions_applies_rename_and_exclude(tmp_path: Path):
src = tmp_path / "ThingController.java"
src.write_text(REST_CONTROLLER)