Skip to content

Commit

Permalink
Merge pull request #11 from nextcloud/feat/noid/openapi-scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Nov 7, 2023
2 parents dbeba40 + a62a63a commit d5994dd
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/Service/AppsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,42 @@ public function __construct(private IAppManager $appManager) {
* @return string[]
*/
public function findSupported(): array {
return array_values(array_filter(array_merge(["core"], $this->appManager->getInstalledApps()), function (string $app) {
$path = $this->getSpecPath($app);
return $path != null && file_exists($path);
}));
$apis = ['core'];

foreach ($this->appManager->getInstalledApps() as $app) {
try {
$baseDir = $this->appManager->getAppPath($app);
$iterator = new \DirectoryIterator($baseDir);
foreach ($iterator as $file) {
if ($file->getFilename() == 'openapi.json') {
$apis[] = $app;
} else if (str_starts_with($file->getFilename(), 'openapi-') && str_ends_with($file->getFilename(), '.json')) {
$apis[] = $app . '-' . substr($file->getFilename(), 8, -5);
}
}
} catch (AppPathNotFoundException) {
}
}
return $apis;
}

private function getSpecPath(string $app): ?string {
if ($app == "core") {
$scopeSuffix = '';
if ($app === 'core') {
$baseDir = OC::$SERVERROOT . DIRECTORY_SEPARATOR . "core";
} else {
try {
if (str_contains($app, '-')) {
[$app, $scope] = explode('-', $app, 2);
$scopeSuffix = '-' . $scope;
}
$baseDir = $this->appManager->getAppPath($app);
} catch (AppPathNotFoundException $e) {
return null;
}
}

return $baseDir . DIRECTORY_SEPARATOR . "openapi.json";
return $baseDir . DIRECTORY_SEPARATOR . "openapi$scopeSuffix.json";
}

public function getSpec(string $app): string {
Expand Down

0 comments on commit d5994dd

Please sign in to comment.