From 840d34d99b69934230b2fbe0004a5af8084e939e Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 27 Sep 2024 09:08:57 +0200 Subject: [PATCH] fix(OpenAPI): Fix some typings Signed-off-by: provokateurin --- lib/Api/V1Api.php | 2 +- lib/Capabilities.php | 10 +- lib/Controller/Api1Controller.php | 24 ++--- lib/Controller/ApiColumnsController.php | 12 +-- lib/Controller/ApiTablesController.php | 6 +- lib/Controller/ContextController.php | 2 +- lib/Db/Column.php | 89 +++++++++-------- lib/Db/Row2.php | 14 +-- lib/Db/RowSleeve.php | 10 +- lib/Db/Share.php | 52 +++++----- lib/Db/Table.php | 47 ++++----- lib/Db/View.php | 25 +++-- lib/ResponseDefinitions.php | 74 ++++++++------ lib/Service/ColumnService.php | 4 +- lib/Service/RowService.php | 4 +- lib/Service/ShareService.php | 4 +- lib/Service/TableService.php | 7 +- lib/Service/ViewService.php | 8 +- openapi.json | 127 +++++++++++++++++++----- psalm.xml | 4 + src/types/openapi/openapi.ts | 55 ++++++---- 21 files changed, 351 insertions(+), 229 deletions(-) diff --git a/lib/Api/V1Api.php b/lib/Api/V1Api.php index 69590e2f4..5d3c40b2a 100644 --- a/lib/Api/V1Api.php +++ b/lib/Api/V1Api.php @@ -30,7 +30,7 @@ public function __construct(ColumnService $columnService, RowService $rowService * @param int|null $offset * @param string|null $userId * @param string|null $nodeType - * @return array + * @return list> * @throws DoesNotExistException * @throws InternalError * @throws MultipleObjectsReturnedException diff --git a/lib/Capabilities.php b/lib/Capabilities.php index dea9ddd49..5224e71eb 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -29,7 +29,15 @@ public function __construct(IAppManager $appManager, LoggerInterface $logger, IC /** * - * @return array{tables: array{enabled: bool, version: string, apiVersions: string[], features: string[], column_types: string[]}} + * @return array{ + * tables: array{ + * enabled: bool, + * version: string, + * apiVersions: list, + * features: list, + * column_types: list, + * } + * } * * @inheritDoc */ diff --git a/lib/Controller/Api1Controller.php b/lib/Controller/Api1Controller.php index 9e1276d06..128c7ab6a 100644 --- a/lib/Controller/Api1Controller.php +++ b/lib/Controller/Api1Controller.php @@ -100,7 +100,7 @@ public function __construct( * @CORS * @NoCSRFRequired * - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Tables returned */ @@ -281,7 +281,7 @@ public function deleteTable(int $tableId): DataResponse { * @NoCSRFRequired * * @param int $tableId Table ID - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Views returned * 403: No permissions @@ -376,7 +376,7 @@ public function getView(int $viewId): DataResponse { * @NoCSRFRequired * * @param int $viewId View ID - * @param array{key: 'title'|'emoji'|'description', value: string}|array{key: 'columns', value: int[]}|array{key: 'sort', value: array{columnId: int, mode: 'ASC'|'DESC'}}|array{key: 'filter', value: array{columnId: int, operator: 'begins-with'|'ends-with'|'contains'|'is-equal'|'is-greater-than'|'is-greater-than-or-equal'|'is-lower-than'|'is-lower-than-or-equal'|'is-empty', value: string|int|float}} $data key-value pairs + * @param array{key: 'title'|'emoji'|'description', value: string}|array{key: 'columns', value: list}|array{key: 'sort', value: array{columnId: int, mode: 'ASC'|'DESC'}}|array{key: 'filter', value: array{columnId: int, operator: 'begins-with'|'ends-with'|'contains'|'is-equal'|'is-greater-than'|'is-greater-than-or-equal'|'is-lower-than'|'is-lower-than-or-equal'|'is-empty', value: string|int|float}} $data key-value pairs * @return DataResponse|DataResponse * * 200: View updated @@ -477,7 +477,7 @@ public function getShare(int $shareId): DataResponse { * @NoCSRFRequired * * @param int $viewId View ID - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Shares returned */ @@ -500,7 +500,7 @@ public function indexViewShares(int $viewId): DataResponse { * @NoCSRFRequired * * @param int $tableId Table ID - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Shares returned */ @@ -694,7 +694,7 @@ public function updateShareDisplayMode(int $shareId, int $displayMode, string $t * * @param int $tableId Table ID * @param int|null $viewId View ID - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: View deleted * 403: No permissions @@ -723,7 +723,7 @@ public function indexTableColumns(int $tableId, ?int $viewId): DataResponse { * @NoCSRFRequired * * @param int $viewId View ID - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: View deleted * 403: No permissions @@ -778,7 +778,7 @@ public function indexViewColumns(int $viewId): DataResponse { * @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup * @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup * @param bool|null $usergroupShowUserStatus Whether to show the user's status, if column type is usergroup - * @param int[]|null $selectedViewIds View IDs where this column should be added to be presented + * @param list|null $selectedViewIds View IDs where this column should be added to be presented * * @return DataResponse|DataResponse * @@ -1039,7 +1039,7 @@ public function deleteColumn(int $columnId): DataResponse { * @param int $tableId Table ID * @param int|null $limit Limit * @param int|null $offset Offset - * @return DataResponse|DataResponse + * @return DataResponse>, array{}>|DataResponse * * 200: Row values returned * 403: No permissions @@ -1069,7 +1069,7 @@ public function indexTableRowsSimple(int $tableId, ?int $limit, ?int $offset): D * @param int $tableId Table ID * @param int|null $limit Limit * @param int|null $offset Offset - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Rows returned * 403: No permissions @@ -1099,7 +1099,7 @@ public function indexTableRows(int $tableId, ?int $limit, ?int $offset): DataRes * @param int $viewId View ID * @param int|null $limit Limit * @param int|null $offset Offset - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Rows returned * 403: No permissions @@ -1495,7 +1495,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive * @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup * @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup * @param bool|null $usergroupShowUserStatus Whether to show the user's status, if column type is usergroup - * @param int[]|null $selectedViewIds View IDs where this column should be added to be presented + * @param list|null $selectedViewIds View IDs where this column should be added to be presented * * @return DataResponse|DataResponse * diff --git a/lib/Controller/ApiColumnsController.php b/lib/Controller/ApiColumnsController.php index d126b833a..d2d19a227 100644 --- a/lib/Controller/ApiColumnsController.php +++ b/lib/Controller/ApiColumnsController.php @@ -43,7 +43,7 @@ public function __construct( * * @param int $nodeId Node ID * @param 'table'|'view' $nodeType Node type - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: View deleted * 403: No permissions @@ -111,7 +111,7 @@ public function show(int $id): DataResponse { * @param float|null $numberMax Max * @param 'progress'|'stars'|null $subtype Subtype for the new column * @param string|null $description Description - * @param int[]|null $selectedViewIds View IDs where this columns should be added + * @param list|null $selectedViewIds View IDs where this columns should be added * @return DataResponse|DataResponse * * 200: Column created @@ -160,7 +160,7 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe * @param int|null $textMaxLength Max raw text length * @param 'progress'|'stars'|null $subtype Subtype for the new column * @param string|null $description Description - * @param int[]|null $selectedViewIds View IDs where this columns should be added + * @param list|null $selectedViewIds View IDs where this columns should be added * @param boolean $mandatory Is mandatory * @param 'table'|'view' $baseNodeType Context type of the column creation * @return DataResponse|DataResponse @@ -207,7 +207,7 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe * @param string|null $selectionDefault Json int|int[] for default selected option(s), eg 5 or ["1", "8"] * @param 'progress'|'stars'|null $subtype Subtype for the new column * @param string|null $description Description - * @param int[]|null $selectedViewIds View IDs where this columns should be added + * @param list|null $selectedViewIds View IDs where this columns should be added * @param boolean $mandatory Is mandatory * @param 'table'|'view' $baseNodeType Context type of the column creation * @return DataResponse|DataResponse @@ -252,7 +252,7 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se * @param 'today'|'now'|null $datetimeDefault For a subtype 'date' you can set 'today'. For a main type or subtype 'time' you can set to 'now'. * @param 'progress'|'stars'|null $subtype Subtype for the new column * @param string|null $description Description - * @param int[]|null $selectedViewIds View IDs where this columns should be added + * @param list|null $selectedViewIds View IDs where this columns should be added * @param boolean $mandatory Is mandatory * @param 'table'|'view' $baseNodeType Context type of the column creation * @return DataResponse|DataResponse @@ -297,7 +297,7 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da * @param boolean $usergroupSelectGroups Whether you can select groups * @param boolean $showUserStatus Whether to show the user's status * @param string|null $description Description - * @param int[]|null $selectedViewIds View IDs where this columns should be added + * @param list|null $selectedViewIds View IDs where this columns should be added * @param boolean $mandatory Is mandatory * @param 'table'|'view' $baseNodeType Context type of the column creation * @return DataResponse|DataResponse diff --git a/lib/Controller/ApiTablesController.php b/lib/Controller/ApiTablesController.php index 6b8b359be..6f3b4ccaa 100644 --- a/lib/Controller/ApiTablesController.php +++ b/lib/Controller/ApiTablesController.php @@ -59,7 +59,7 @@ public function __construct( * * @NoAdminRequired * - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: Tables returned */ @@ -127,8 +127,8 @@ public function showScheme(int $id): DataResponse { * @param string $title title of new table * @param string $emoji emoji * @param string $description description - * @param array $columns columns - * @param array $views views + * @param list $columns columns + * @param list $views views * @return DataResponse|DataResponse * * 200: Tables returned diff --git a/lib/Controller/ContextController.php b/lib/Controller/ContextController.php index ec7742d9a..3dc259eb3 100644 --- a/lib/Controller/ContextController.php +++ b/lib/Controller/ContextController.php @@ -48,7 +48,7 @@ public function __construct( * * Return an empty array if no contexts were found * - * @return DataResponse|DataResponse + * @return DataResponse, array{}>|DataResponse * * 200: reporting in available contexts * diff --git a/lib/Db/Column.php b/lib/Db/Column.php index 04d1f65a6..3bb279ad8 100644 --- a/lib/Db/Column.php +++ b/lib/Db/Column.php @@ -18,63 +18,63 @@ * * @psalm-import-type TablesColumn from ResponseDefinitions * - * @method getTitle(): string + * @method string getTitle() * @method setTitle(string $title) - * @method getTableId(): int + * @method int getTableId() * @method setTableId(int $tableId) - * @method getCreatedBy(): string + * @method string getCreatedBy() * @method setCreatedBy(string $createdBy) - * @method getCreatedByDisplayName(): string + * @method string getCreatedByDisplayName() * @method setCreatedByDisplayName(string $displayName) - * @method getCreatedAt(): string + * @method string getCreatedAt() * @method setCreatedAt(string $createdAt) - * @method getLastEditBy(): string + * @method string getLastEditBy() * @method setLastEditBy(string $lastEditBy) - * @method getLastEditByDisplayName(): string + * @method string getLastEditByDisplayName() * @method setLastEditByDisplayName(string $displayName) - * @method getLastEditAt(): string + * @method string getLastEditAt() * @method setLastEditAt(string $lastEditAt) - * @method getType(): string + * @method string getType() * @method setType(string $type) - * @method getSubtype(): string + * @method string getSubtype() * @method setSubtype(string $subtype) - * @method getMandatory(): bool + * @method bool getMandatory() * @method setMandatory(?bool $mandatory) - * @method getDescription(): string + * @method string getDescription() * @method setDescription(?string $description) - * @method getNumberDefault(): float + * @method float getNumberDefault() * @method setNumberDefault(?float $numberDefault) - * @method getNumberMin(): float + * @method float getNumberMin() * @method setNumberMin(?float $numberMin) - * @method getNumberMax(): float + * @method float getNumberMax() * @method setNumberMax(?float $numberMax) - * @method getNumberDecimals(): int + * @method int getNumberDecimals() * @method setNumberDecimals(?int $numberDecimals) - * @method getNumberPrefix(): string + * @method string getNumberPrefix() * @method setNumberPrefix(?string $numberPrefix) - * @method getNumberSuffix(): string + * @method string getNumberSuffix() * @method setNumberSuffix(?string $numberSuffix) - * @method getTextDefault(): string + * @method string getTextDefault() * @method setTextDefault(?string $textDefault) - * @method getTextAllowedPattern(): string + * @method string getTextAllowedPattern() * @method setTextAllowedPattern(?string $textAllowedPattern) - * @method getTextMaxLength(): int + * @method int getTextMaxLength() * @method setTextMaxLength(?int $textMaxLength) - * @method getSelectionOptions(): string - * @method getSelectionDefault(): string + * @method string getSelectionOptions() * @method setSelectionOptions(?string $selectionOptionsArray) + * @method string getSelectionDefault() * @method setSelectionDefault(?string $selectionDefault) - * @method getDatetimeDefault(): string + * @method string getDatetimeDefault() * @method setDatetimeDefault(?string $datetimeDefault) - * @method getUsergroupDefault(): string + * @method string getUsergroupDefault() * @method setUsergroupDefault(?string $usergroupDefaultArray) - * @method getUsergroupMultipleItems(): bool + * @method bool getUsergroupMultipleItems() * @method setUsergroupMultipleItems(?bool $usergroupMultipleItems) - * @method getUsergroupSelectUsers(): bool + * @method bool getUsergroupSelectUsers() * @method setUsergroupSelectUsers(?bool $usergroupSelectUsers) - * @method getUsergroupSelectGroups(): bool + * @method bool getUsergroupSelectGroups() * @method setUsergroupSelectGroups(?bool $usergroupSelectGroups) - * @method getShowUserStatus(): bool + * @method bool getShowUserStatus() * @method setShowUserStatus(?bool $showUserStatus) */ class Column extends Entity implements JsonSerializable { @@ -91,19 +91,18 @@ class Column extends Entity implements JsonSerializable { public const TYPE_DATETIME = 'datetime'; public const TYPE_USERGROUP = 'usergroup'; - protected ?string $title = null; - protected ?int $tableId = null; - protected ?string $createdBy = null; - protected ?string $createdByDisplayName = null; - protected ?string $createdAt = null; - protected ?string $lastEditBy = null; - protected ?string $lastEditByDisplayName = null; - protected ?string $lastEditAt = null; - protected ?string $type = null; - protected ?string $subtype = null; - protected ?bool $mandatory = null; - protected ?string $description = null; - protected ?int $orderWeight = null; // Deprecated + protected string $title = ''; + protected int $tableId = 0; + protected string $createdBy = ''; + protected string $createdByDisplayName = ''; + protected string $createdAt = ''; + protected string $lastEditBy = ''; + protected string $lastEditByDisplayName = ''; + protected string $lastEditAt = ''; + protected string $type = ''; + protected string $subtype = ''; + protected bool $mandatory = false; + protected string $description = ''; // type number protected ?float $numberDefault = null; @@ -180,6 +179,9 @@ public static function fromDto(ColumnDto $data): self { return $column; } + /** + * @return array{id: int, label: string}|list + */ public function getUsergroupDefaultArray():array { $default = $this->getUsergroupDefault(); if ($default !== "" && $default !== null) { @@ -194,6 +196,9 @@ public function setUsergroupDefaultArray(array $array):void { $this->setUsergroup($json); } + /** + * @return list + */ public function getSelectionOptionsArray():array { $options = $this->getSelectionOptions(); if ($options !== "" && $options !== null && $options !== 'null') { diff --git a/lib/Db/Row2.php b/lib/Db/Row2.php index b64a6abb0..71b220347 100644 --- a/lib/Db/Row2.php +++ b/lib/Db/Row2.php @@ -15,13 +15,13 @@ * @psalm-import-type TablesRow from ResponseDefinitions */ class Row2 implements JsonSerializable { - private ?int $id = null; - private ?int $tableId = null; - private ?string $createdBy = null; - private ?string $createdAt = null; - private ?string $lastEditBy = null; - private ?string $lastEditAt = null; - private ?array $data = []; + private int $id = 0; + private int $tableId = 0; + private string $createdBy = ''; + private string $createdAt = ''; + private string $lastEditBy = ''; + private string $lastEditAt = ''; + private array $data = []; private array $changedColumnIds = []; // collect column ids that have changed after $loaded = true private bool $loaded = false; // set to true if model is loaded, after that changed column ids will be collected diff --git a/lib/Db/RowSleeve.php b/lib/Db/RowSleeve.php index 3c765e817..333580b04 100644 --- a/lib/Db/RowSleeve.php +++ b/lib/Db/RowSleeve.php @@ -13,15 +13,15 @@ /** * @psalm-suppress PropertyNotSetInConstructor - * @method getTableId(): ?int + * @method int|null getTableId() * @method setTableId(int $columnId) - * @method getCreatedBy(): string + * @method string getCreatedBy() * @method setCreatedBy(string $createdBy) - * @method getCreatedAt(): string + * @method string getCreatedAt() * @method setCreatedAt(string $createdAt) - * @method getLastEditBy(): string + * @method string getLastEditBy() * @method setLastEditBy(string $lastEditBy) - * @method getLastEditAt(): string + * @method string getLastEditAt() * @method setLastEditAt(string $lastEditAt) */ class RowSleeve extends Entity implements JsonSerializable { diff --git a/lib/Db/Share.php b/lib/Db/Share.php index 36e85eea6..c3f6d305f 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -17,48 +17,48 @@ * * @psalm-suppress PropertyNotSetInConstructor * - * @method getSender(): string + * @method string getSender() * @method setSender(string $sender) - * @method getReceiver(): string + * @method string getReceiver() * @method setReceiver(string $receiver) - * @method getReceiverDisplayName(): string + * @method string getReceiverDisplayName() * @method setReceiverDisplayName(string $receiverDisplayName) - * @method getReceiverType(): string + * @method string getReceiverType() * @method setReceiverType(string $receiverType) - * @method getNodeId(): int + * @method int getNodeId() * @method setNodeId(int $nodeId) - * @method getNodeType(): string + * @method string getNodeType() * @method setNodeType(string $nodeType) - * @method getPermissionRead(): bool + * @method bool getPermissionRead() * @method setPermissionRead(bool $permissionRead) - * @method getPermissionCreate(): bool + * @method bool getPermissionCreate() * @method setPermissionCreate(bool $permissionCreate) - * @method getPermissionUpdate(): bool + * @method bool getPermissionUpdate() * @method setPermissionUpdate(bool $permissionUpdate) - * @method getPermissionDelete(): bool + * @method bool getPermissionDelete() * @method setPermissionDelete(bool $permissionDelete) - * @method getPermissionManage(): bool + * @method bool getPermissionManage() * @method setPermissionManage(bool $permissionManage) - * @method getCreatedAt(): string + * @method string getCreatedAt() * @method setCreatedAt(string $createdAt) - * @method getLastEditAt(): string + * @method string getLastEditAt() * @method setLastEditAt(string $lastEditAt) */ class Share extends Entity implements JsonSerializable { - protected ?string $sender = null; // is also owner + protected string $sender = ''; // is also owner - protected ?string $receiver = null; - protected ?string $receiverDisplayName = null; - protected ?string $receiverType = null; // user, group - protected ?int $nodeId = null; - protected ?string $nodeType = null; - protected ?bool $permissionRead = null; - protected ?bool $permissionCreate = null; - protected ?bool $permissionUpdate = null; - protected ?bool $permissionDelete = null; - protected ?bool $permissionManage = null; - protected ?string $createdAt = null; - protected ?string $lastEditAt = null; + protected string $receiver = ''; + protected string $receiverDisplayName = ''; + protected string $receiverType = ''; // user, group + protected int $nodeId = 0; + protected string $nodeType = ''; + protected bool $permissionRead = false; + protected bool $permissionCreate = false; + protected bool $permissionUpdate = false; + protected bool $permissionDelete = false; + protected bool $permissionManage = false; + protected string $createdAt = ''; + protected string $lastEditAt = ''; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/Table.php b/lib/Db/Table.php index 17f0699bb..bf120b950 100644 --- a/lib/Db/Table.php +++ b/lib/Db/Table.php @@ -18,42 +18,42 @@ * @psalm-import-type TablesTable from ResponseDefinitions * @psalm-import-type TablesView from ResponseDefinitions * - * @method getTitle(): string - * @method getId(): int + * @method string getTitle() + * @method int getId() * @method setTitle(string $title) - * @method getEmoji(): string + * @method string getEmoji() * @method setEmoji(string $emoji) - * @method getArchived(): bool + * @method bool getArchived() * @method setArchived(bool $archived) - * @method getDescription(): string + * @method string getDescription() * @method setDescription(string $description) - * @method getOwnership(): string + * @method string getOwnership() * @method setOwnership(string $ownership) - * @method getOwnerDisplayName(): string + * @method string getOwnerDisplayName() * @method setOwnerDisplayName(string $ownerDisplayName) - * @method getIsShared(): bool + * @method bool getIsShared() * @method setIsShared(bool $isShared) - * @method getOnSharePermissions(): ?Permissions + * @method Permissions|null getOnSharePermissions() * @method setOnSharePermissions(Permissions $onSharePermissions) - * @method getHasShares(): bool + * @method bool getHasShares() * @method setHasShares(bool $hasShares) - * @method getFavorite(): bool + * @method bool getFavorite() * @method setFavorite(bool $favorite) - * @method getRowsCount(): int + * @method int getRowsCount() * @method setRowsCount(int $rowsCount) - * @method getColumnsCount(): int + * @method int getColumnsCount() * @method setColumnsCount(int $columnsCount) - * @method getViews(): array + * @method array getViews() * @method setViews(array $views) - * @method getColumns(): array + * @method array getColumns() * @method setColumns(array $columns) - * @method getCreatedBy(): string + * @method string getCreatedBy() * @method setCreatedBy(string $createdBy) - * @method getCreatedAt(): string + * @method string getCreatedAt() * @method setCreatedAt(string $createdAt) - * @method getLastEditBy(): string + * @method string getLastEditBy() * @method setLastEditBy(string $lastEditBy) - * @method getLastEditAt(): string + * @method string getLastEditAt() * @method setLastEditAt(string $lastEditAt) */ class Table extends Entity implements JsonSerializable { @@ -70,7 +70,7 @@ class Table extends Entity implements JsonSerializable { protected ?Permissions $onSharePermissions = null; protected ?bool $hasShares = false; - protected ?bool $favorite = false; + protected bool $favorite = false; protected ?int $rowsCount = 0; protected ?int $columnsCount = 0; protected ?array $views = null; @@ -113,10 +113,11 @@ private function getSharePermissions(): ?Permissions { } /** - * @psalm-suppress MismatchingDocblockReturnType - * @return TablesView[] + * @return list */ private function getViewsArray(): array { - return $this->getViews() ?: []; + /** @var list $views */ + $views = $this->getViews() ?: []; + return $views; } } diff --git a/lib/Db/View.php b/lib/Db/View.php index 744ba9441..50555f5a2 100644 --- a/lib/Db/View.php +++ b/lib/Db/View.php @@ -80,37 +80,40 @@ public function __construct() { } /** - * @psalm-suppress MismatchingDocblockReturnType - * @return int[] + * @return list */ public function getColumnsArray(): array { - return $this->getArray($this->getColumns()); + /** @var list $data */ + $data = $this->getArray($this->getColumns()); + return $data; } /** - * @psalm-suppress MismatchingDocblockReturnType * @return list */ public function getSortArray(): array { - return $this->getArray($this->getSort()); + /** @var list $data */ + $data = $this->getArray($this->getSort()); + return $data; } /** - * @psalm-suppress MismatchingDocblockReturnType * @return list> */ public function getFilterArray():array { + /** @var list> $filters */ $filters = $this->getArray($this->getFilter()); // a filter(group) was stored with a not-selected column - it may break impressively. // filter them out now until we have a permanent fix foreach ($filters as &$filterGroups) { - $filterGroups = array_filter($filterGroups, function (array $item) { + $filterGroups = array_values(array_filter($filterGroups, function (array $item) { return $item['columnId'] !== null; - }); + })); } - return array_filter($filters, function (array $item) { + /** @var list> $filters */ + return array_values(array_filter($filters, function (array $item) { return !empty($item); - }); + })); } private function getArray(?string $json): array { @@ -146,7 +149,7 @@ public function setOwnership(string $ownership): void { } /** - * @psalm-return TablesView + * @return TablesView */ public function jsonSerialize(): array { $serialisedJson = [ diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 5e3826d02..a3f00beaa 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -15,18 +15,25 @@ * @psalm-type TablesView = array{ * id: int, * title: string, - * emoji: string|null, + * emoji: ?string, * tableId: int, * ownership: string, - * ownerDisplayName: string|null, + * ownerDisplayName: ?string, * createdBy: string, * createdAt: string, * lastEditBy: string, * lastEditAt: string, - * description: string|null, - * columns: int[], - * sort: list, - * filter: list>, + * description: ?string, + * columns: list, + * sort: list, + * filter: list>, * isShared: bool, * favorite: bool, * onSharePermissions: ?array{ @@ -43,7 +50,8 @@ * @psalm-type TablesTable = array{ * id: int, * title: string, - * emoji: string|null, + * description: string, + * emoji: ?string, * ownership: string, * ownerDisplayName: string, * createdBy: string, @@ -62,13 +70,13 @@ * }, * hasShares: bool, * rowsCount: int, - * views: TablesView[], + * views: list, * columnsCount: int, * } * * @psalm-type TablesIndex = array{ - * tables: TablesTable[], - * views: TablesView[], + * tables: list, + * views: list, * } * * @psalm-type TablesRow = array{ @@ -78,7 +86,10 @@ * createdAt: string, * lastEditBy: string, * lastEditAt: string, - * data: ?array{columnId: int, value: mixed}, + * data: ?array{ + * columnId: int, + * value: mixed, + * }, * } * * @psalm-type TablesShare = array{ @@ -95,7 +106,7 @@ * permissionDelete: bool, * permissionManage: bool, * createdAt: string, - * createdBy: string, + * lastEditAt: string, * } * * @psalm-type TablesColumn = array{ @@ -103,31 +114,32 @@ * title: string, * tableId: int, * createdBy: string, + * createdByDisplayName: string, * createdAt: string, * lastEditBy: string, + * lastEditByDisplayName: string, * lastEditAt: string, * type: string, * subtype: string, * mandatory: bool, * description: string, - * orderWeight: int, - * numberDefault: float, - * numberMin: float, - * numberMax: float, - * numberDecimals: int, - * numberPrefix: string, - * numberSuffix: string, - * textDefault: string, - * textAllowedPattern: string, - * textMaxLength: int, - * selectionOptions: string, - * selectionDefault: string, - * datetimeDefault: string, - * usergroupDefault: string, - * usergroupMultipleItems: bool, - * usergroupSelectUsers: bool, - * usergroupSelectGroups: bool, - * showUserStatus: bool, + * numberDefault: ?float, + * numberMin: ?float, + * numberMax: ?float, + * numberDecimals: ?int, + * numberPrefix: ?string, + * numberSuffix: ?string, + * textDefault: ?string, + * textAllowedPattern: ?string, + * textMaxLength: ?int, + * selectionOptions: list, + * selectionDefault: ?string, + * datetimeDefault: ?string, + * usergroupDefault: array{id: int, label: string}|list, + * usergroupMultipleItems: ?bool, + * usergroupSelectUsers: ?bool, + * usergroupSelectGroups: ?bool, + * showUserStatus: ?bool, * } * * @psalm-type TablesImportState = array{ @@ -154,8 +166,6 @@ * displayMode: int, * userId: string, * } - * - * @psalm-type TablesColumn */ class ResponseDefinitions { } diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index 31908b413..a811d5467 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -106,10 +106,10 @@ public function findAllByView(int $viewId, ?string $userId = null): array { /** * @param Column[] $columns - * @return TablesColumn[] + * @return list */ public function formatColumns(array $columns): array { - return array_map(fn (Column $item) => $item->jsonSerialize(), $columns); + return array_values(array_map(fn (Column $item) => $item->jsonSerialize(), $columns)); } /** diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index 18eeafeef..b2003b6ce 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -64,10 +64,10 @@ public function __construct( /** * @param Row2[] $rows - * @psalm-return TablesRow[] + * @return list */ public function formatRows(array $rows): array { - return array_map(fn (Row2 $row) => $row->jsonSerialize(), $rows); + return array_values(array_map(fn (Row2 $row) => $row->jsonSerialize(), $rows)); } /** diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 53f39ae83..31cfba2a8 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -95,10 +95,10 @@ public function findAll(string $nodeType, int $nodeId, ?string $userId = null, b /** * @param Share[] $items - * @return TablesShare[] + * @return list */ public function formatShares(array $items): array { - return array_map(fn (Share $item) => $item->jsonSerialize(), $items); + return array_values(array_map(fn (Share $item) => $item->jsonSerialize(), $items)); } /** diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index 77d80ed79..7a69b7b14 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -13,6 +13,7 @@ use OCA\Tables\AppInfo\Application; use OCA\Tables\Db\Table; use OCA\Tables\Db\TableMapper; +use OCA\Tables\Db\View; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -173,10 +174,10 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal /** * @param Table[] $tables - * @return TablesTable[] + * @return list */ public function formatTables(array $tables): array { - return array_map(fn (Table $table) => $table->jsonSerialize(), $tables); + return array_values(array_map(fn (Table $table) => $table->jsonSerialize(), $tables)); } /** @@ -234,7 +235,7 @@ private function enhanceTable(Table $table, string $userId): void { } if (!$table->getIsShared() || $table->getOnSharePermissions()->manage) { // add the corresponding views if it is an own table, or you have table manage rights - $table->setViews($this->viewService->findAll($table)); + $table->setViews(array_map(static fn (View $view) => $view->jsonSerialize(), $this->viewService->findAll($table))); } if ($this->favoritesService->isFavorite(Application::NODE_TYPE_TABLE, $table->getId())) { diff --git a/lib/Service/ViewService.php b/lib/Service/ViewService.php index bd7e98bc0..eadf2ec82 100644 --- a/lib/Service/ViewService.php +++ b/lib/Service/ViewService.php @@ -76,7 +76,7 @@ public function __construct( /** * @param Table $table * @param string|null $userId - * @return array + * @return list * @throws InternalError * @throws PermissionError */ @@ -93,7 +93,7 @@ public function findAll(Table $table, ?string $userId = null): array { foreach ($allViews as $view) { $this->enhanceView($view, $userId); } - return $allViews; + return array_values($allViews); } catch (\OCP\DB\Exception|InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InternalError($e->getMessage()); @@ -105,10 +105,10 @@ public function findAll(Table $table, ?string $userId = null): array { /** * @param View[] $items - * @return TablesView[] + * @return list */ public function formatViews(array $items): array { - return array_map(fn (View $item) => $item->jsonSerialize(), $items); + return array_values(array_map(fn (View $item) => $item->jsonSerialize(), $items)); } /** diff --git a/openapi.json b/openapi.json index fddafc065..3e04324d7 100644 --- a/openapi.json +++ b/openapi.json @@ -71,14 +71,15 @@ "title", "tableId", "createdBy", + "createdByDisplayName", "createdAt", "lastEditBy", + "lastEditByDisplayName", "lastEditAt", "type", "subtype", "mandatory", "description", - "orderWeight", "numberDefault", "numberMin", "numberMax", @@ -112,12 +113,18 @@ "createdBy": { "type": "string" }, + "createdByDisplayName": { + "type": "string" + }, "createdAt": { "type": "string" }, "lastEditBy": { "type": "string" }, + "lastEditByDisplayName": { + "type": "string" + }, "lastEditAt": { "type": "string" }, @@ -133,65 +140,128 @@ "description": { "type": "string" }, - "orderWeight": { - "type": "integer", - "format": "int64" - }, "numberDefault": { "type": "number", - "format": "double" + "format": "double", + "nullable": true }, "numberMin": { "type": "number", - "format": "double" + "format": "double", + "nullable": true }, "numberMax": { "type": "number", - "format": "double" + "format": "double", + "nullable": true }, "numberDecimals": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true }, "numberPrefix": { - "type": "string" + "type": "string", + "nullable": true }, "numberSuffix": { - "type": "string" + "type": "string", + "nullable": true }, "textDefault": { - "type": "string" + "type": "string", + "nullable": true }, "textAllowedPattern": { - "type": "string" + "type": "string", + "nullable": true }, "textMaxLength": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true }, "selectionOptions": { - "type": "string" + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "label" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "label": { + "type": "string" + } + } + } }, "selectionDefault": { - "type": "string" + "type": "string", + "nullable": true }, "datetimeDefault": { - "type": "string" + "type": "string", + "nullable": true }, "usergroupDefault": { - "type": "string" + "oneOf": [ + { + "type": "object", + "required": [ + "id", + "label" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "label": { + "type": "string" + } + } + }, + { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "label" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "label": { + "type": "string" + } + } + } + } + ] }, "usergroupMultipleItems": { - "type": "boolean" + "type": "boolean", + "nullable": true }, "usergroupSelectUsers": { - "type": "boolean" + "type": "boolean", + "nullable": true }, "usergroupSelectGroups": { - "type": "boolean" + "type": "boolean", + "nullable": true }, "showUserStatus": { - "type": "boolean" + "type": "boolean", + "nullable": true } } }, @@ -403,7 +473,7 @@ "permissionDelete", "permissionManage", "createdAt", - "createdBy" + "lastEditAt" ], "properties": { "id": { @@ -447,7 +517,7 @@ "createdAt": { "type": "string" }, - "createdBy": { + "lastEditAt": { "type": "string" } } @@ -457,6 +527,7 @@ "required": [ "id", "title", + "description", "emoji", "ownership", "ownerDisplayName", @@ -481,6 +552,9 @@ "title": { "type": "string" }, + "description": { + "type": "string" + }, "emoji": { "type": "string", "nullable": true @@ -3845,7 +3919,10 @@ "schema": { "type": "array", "items": { - "type": "string" + "type": "array", + "items": { + "type": "object" + } } } } diff --git a/psalm.xml b/psalm.xml index 54cf837e1..09748dda9 100644 --- a/psalm.xml +++ b/psalm.xml @@ -26,6 +26,10 @@ + + + + diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 5e1f859bf..2d464ce3a 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -751,37 +751,49 @@ export type components = { /** Format: int64 */ readonly tableId: number; readonly createdBy: string; + readonly createdByDisplayName: string; readonly createdAt: string; readonly lastEditBy: string; + readonly lastEditByDisplayName: string; readonly lastEditAt: string; readonly type: string; readonly subtype: string; readonly mandatory: boolean; readonly description: string; - /** Format: int64 */ - readonly orderWeight: number; /** Format: double */ - readonly numberDefault: number; + readonly numberDefault: number | null; /** Format: double */ - readonly numberMin: number; + readonly numberMin: number | null; /** Format: double */ - readonly numberMax: number; + readonly numberMax: number | null; /** Format: int64 */ - readonly numberDecimals: number; - readonly numberPrefix: string; - readonly numberSuffix: string; - readonly textDefault: string; - readonly textAllowedPattern: string; + readonly numberDecimals: number | null; + readonly numberPrefix: string | null; + readonly numberSuffix: string | null; + readonly textDefault: string | null; + readonly textAllowedPattern: string | null; /** Format: int64 */ - readonly textMaxLength: number; - readonly selectionOptions: string; - readonly selectionDefault: string; - readonly datetimeDefault: string; - readonly usergroupDefault: string; - readonly usergroupMultipleItems: boolean; - readonly usergroupSelectUsers: boolean; - readonly usergroupSelectGroups: boolean; - readonly showUserStatus: boolean; + readonly textMaxLength: number | null; + readonly selectionOptions: readonly { + /** Format: int64 */ + readonly id: number; + readonly label: string; + }[]; + readonly selectionDefault: string | null; + readonly datetimeDefault: string | null; + readonly usergroupDefault: { + /** Format: int64 */ + readonly id: number; + readonly label: string; + } | readonly { + /** Format: int64 */ + readonly id: number; + readonly label: string; + }[]; + readonly usergroupMultipleItems: boolean | null; + readonly usergroupSelectUsers: boolean | null; + readonly usergroupSelectGroups: boolean | null; + readonly showUserStatus: boolean | null; }; readonly Context: { /** Format: int64 */ @@ -858,12 +870,13 @@ export type components = { readonly permissionDelete: boolean; readonly permissionManage: boolean; readonly createdAt: string; - readonly createdBy: string; + readonly lastEditAt: string; }; readonly Table: { /** Format: int64 */ readonly id: number; readonly title: string; + readonly description: string; readonly emoji: string | null; readonly ownership: string; readonly ownerDisplayName: string; @@ -2695,7 +2708,7 @@ export interface operations { readonly [name: string]: unknown; }; content: { - readonly "application/json": readonly string[]; + readonly "application/json": readonly (readonly Record[])[]; }; }; /** @description No permissions */