From 77114fb3277742fc69ddcf2432311ecb263af97e Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 24 Sep 2024 15:53:13 +0200 Subject: fix(OpenAPI): Adjust array syntax to avoid ambiguities Signed-off-by: provokateurin --- apps/files/lib/Controller/TemplateController.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'apps/files/lib/Controller/TemplateController.php') diff --git a/apps/files/lib/Controller/TemplateController.php b/apps/files/lib/Controller/TemplateController.php index 551c9c54c4b..3321fb5f119 100644 --- a/apps/files/lib/Controller/TemplateController.php +++ b/apps/files/lib/Controller/TemplateController.php @@ -16,13 +16,16 @@ use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCSController; use OCP\Files\GenericFileException; use OCP\Files\Template\ITemplateManager; +use OCP\Files\Template\Template; use OCP\Files\Template\TemplateFileCreator; use OCP\IRequest; /** * @psalm-import-type FilesTemplateFile from ResponseDefinitions * @psalm-import-type FilesTemplateFileCreator from ResponseDefinitions + * @psalm-import-type FilesTemplateFileCreatorWithTemplates from ResponseDefinitions * @psalm-import-type FilesTemplateField from ResponseDefinitions + * @psalm-import-type FilesTemplate from ResponseDefinitions */ class TemplateController extends OCSController { public function __construct( @@ -36,13 +39,17 @@ class TemplateController extends OCSController { /** * List the available templates * - * @return DataResponse, array{}> + * @return DataResponse, array{}> * * 200: Available templates returned */ #[NoAdminRequired] public function list(): DataResponse { - return new DataResponse($this->templateManager->listTemplates()); + /* Convert embedded Template instances to arrays to match return type */ + return new DataResponse(array_map(static function (array $templateFileCreator) { + $templateFileCreator['templates'] = array_map(static fn (Template $template) => $template->jsonSerialize(), $templateFileCreator['templates']); + return $templateFileCreator; + }, $this->templateManager->listTemplates())); } /** @@ -51,7 +58,7 @@ class TemplateController extends OCSController { * @param string $filePath Path of the file * @param string $templatePath Name of the template * @param string $templateType Type of the template - * @param FilesTemplateField[] $templateFields Fields of the template + * @param list $templateFields Fields of the template * * @return DataResponse * @throws OCSForbiddenException Creating template is not allowed @@ -82,7 +89,7 @@ class TemplateController extends OCSController { * @param string $templatePath Path of the template directory * @param bool $copySystemTemplates Whether to copy the system templates to the template directory * - * @return DataResponse + * @return DataResponse}, array{}> * @throws OCSForbiddenException Initializing the template directory is not allowed * * 200: Template directory initialized successfully @@ -94,7 +101,7 @@ class TemplateController extends OCSController { $templatePath = $this->templateManager->initializeTemplateDirectory($templatePath, null, $copySystemTemplates); return new DataResponse([ 'template_path' => $templatePath, - 'templates' => array_map(fn (TemplateFileCreator $creator) => $creator->jsonSerialize(), $this->templateManager->listCreators()), + 'templates' => array_values(array_map(fn (TemplateFileCreator $creator) => $creator->jsonSerialize(), $this->templateManager->listCreators())), ]); } catch (\Exception $e) { throw new OCSForbiddenException($e->getMessage()); -- cgit v1.2.3