Skip to content

Commit

Permalink
fix openAPI paths when NC is not served at the webserver's root
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 26, 2024
1 parent 871ba5a commit 41a4ed2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Service/AppsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
use OC;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\IURLGenerator;

class AppsService {

public function __construct(private IAppManager $appManager) {
public function __construct(
private IAppManager $appManager,
private IURLGenerator $url,
) {
}

/**
Expand Down Expand Up @@ -86,6 +90,15 @@ public function getSpec(string $app): string {
unset($operation['security']);
}
}
// fix paths when NC is accessed at a sub path
$webRoot = $this->url->getWebroot();
if ($webRoot !== '' && $webRoot !== '/') {
foreach (array_keys($data['paths']) as $path) {
$prefixedPath = $webRoot . $path;
$data['paths'][$prefixedPath] = $data['paths'][$path];
unset($data['paths'][$path]);
}
}

return json_encode($data);
}
Expand Down

0 comments on commit 41a4ed2

Please sign in to comment.