From e113a0316c973c26fe1482c0cf9bcfd02551d019 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Fri, 26 Jan 2024 10:27:03 +0100 Subject: [PATCH 1/3] add npm ci before build in makefile Signed-off-by: Julien Veyssier --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f23d89c..0691598 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ composer: .PHONY: npm npm: + npm ci npm run build .PHONY: clean From 871ba5a5e561fed2e0d45abe5648cfdabc20f33d Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Fri, 26 Jan 2024 10:27:14 +0100 Subject: [PATCH 2/3] use simple quotes Signed-off-by: Julien Veyssier --- lib/Service/AppsService.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Service/AppsService.php b/lib/Service/AppsService.php index 323b811..130450b 100644 --- a/lib/Service/AppsService.php +++ b/lib/Service/AppsService.php @@ -45,7 +45,7 @@ public function findSupported(): array { private function getSpecPath(string $app): ?string { $scopeSuffix = ''; if ($app === 'core') { - $baseDir = OC::$SERVERROOT . DIRECTORY_SEPARATOR . "core"; + $baseDir = OC::$SERVERROOT . DIRECTORY_SEPARATOR . 'core'; } else { try { if (str_contains($app, '-')) { @@ -65,25 +65,25 @@ public function getSpec(string $app): string { $data = json_decode(file_get_contents($this->getSpecPath($app)), true); // Only give basic authentication as an option - $data["components"]["securitySchemes"] = [ - "basic_auth" => [ - "type" => "http", - "scheme" => "basic", + $data['components']['securitySchemes'] = [ + 'basic_auth' => [ + 'type' => 'http', + 'scheme' => 'basic', ], ]; - $data["security"] = [ + $data['security'] = [ [ - "basic_auth" => [], + 'basic_auth' => [], ], ]; // Delete individual security requirements - foreach (array_keys($data["paths"]) as $path) { - foreach (array_keys($data["paths"][$path]) as $method) { - if (!in_array($method, ["delete", "get", "post", "put", "patch", "options"])) { + foreach (array_keys($data['paths']) as $path) { + foreach (array_keys($data['paths'][$path]) as $method) { + if (!in_array($method, ['delete', 'get', 'post', 'put', 'patch', 'options'])) { continue; } - $operation = &$data["paths"][$path][$method]; - unset($operation["security"]); + $operation = &$data['paths'][$path][$method]; + unset($operation['security']); } } From 41a4ed2fc754855f8f6740e9275c99bf760a7f42 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Fri, 26 Jan 2024 10:28:12 +0100 Subject: [PATCH 3/3] fix openAPI paths when NC is not served at the webserver's root Signed-off-by: Julien Veyssier --- lib/Service/AppsService.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Service/AppsService.php b/lib/Service/AppsService.php index 130450b..e56760b 100644 --- a/lib/Service/AppsService.php +++ b/lib/Service/AppsService.php @@ -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, + ) { } /** @@ -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); }