From 08e9766c2a50995c7c074085b7f08fbb1b1008a2 Mon Sep 17 00:00:00 2001 From: w3houde Date: Thu, 25 Jun 2026 21:32:02 +0200 Subject: [PATCH] Fix #37282 dispatch API classes whose name ends with the 'Api' suffix (#38819) The API discovery loop in htdocs/api/index.php (around line 308) accepts both Foo and FooApi class names when scanning module directories. The dispatch loop on the request-handling side (line 422) only checked class_exists($classname), so a module exposing class MyModuleApi from api_mymodule.class.php would appear in the API Explorer yet 501 with 'API not found' when the endpoint was actually called. Probe class_exists($classname.'Api') first to mirror the discovery behavior. Falls back to the plain class name so existing modules keep working. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/api/index.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 3be224d492e..f517acdfd76 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -419,7 +419,13 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && exit(0); } - if (class_exists($classname)) { + // Match the discovery loop above which accepts both "Foo" and "FooApi" class + // names (see line ~308). Without the Api suffix branch, a module file named + // api_mymodule.class.php exposing class MyModuleApi cannot be dispatched + // even though the api explorer lists it (#37282). + if (class_exists($classname.'Api')) { + $api->r->addAPIClass($classname.'Api'); + } elseif (class_exists($classname)) { $api->r->addAPIClass($classname); } }