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 <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-25 21:32:02 +02:00 committed by GitHub
parent eed3218153
commit 08e9766c2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}
}