diff --git a/lib/Controller/ApiColumnsController.php b/lib/Controller/ApiColumnsController.php index f87949b7d..8792af687 100644 --- a/lib/Controller/ApiColumnsController.php +++ b/lib/Controller/ApiColumnsController.php @@ -209,8 +209,8 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe * * @param int $baseNodeId Context of the column creation * @param string $title Title - * @param string $selectionOptions Options that can be selected - * @param string|null $selectionDefault Default selected option(s) + * @param string $selectionOptions Json array{id: int, label: string} with options that can be selected, eg [{"id": 1, "label": "first"},{"id": 2, "label": "second"}] + * @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 @@ -225,14 +225,14 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe * @throws NotFoundError * @throws PermissionError */ - public function createSelectionColumn(int $baseNodeId, string $title, string $selectionOptions, ?string $selectionDefault, string $subtype = null, string $description = null, ?array $selectedViewIds = null, bool $mandatory = false, string $baseNodeType = 'table'): DataResponse { + public function createSelectionColumn(int $baseNodeId, string $title, string $selectionOptions, ?string $selectionDefault, string $subtype = null, string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse { $tableId = $baseNodeType === 'table' ? $baseNodeId : null; $viewId = $baseNodeType === 'view' ? $baseNodeId : null; $column = $this->service->create( $this->userId, $tableId, $viewId, - 'text', + 'selection', $subtype, $title, $mandatory, diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index 8dd3f2f1a..6eb7b8393 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -193,7 +193,7 @@ public function create( ?string $selectionDefault, ?string $datetimeDefault, - ?array $selectedViewIds + ?array $selectedViewIds = [] ):Column { // security if ($viewId) { diff --git a/openapi.json b/openapi.json index 2b8c33584..d0eaa9f4c 100644 --- a/openapi.json +++ b/openapi.json @@ -6416,7 +6416,7 @@ { "name": "selectionOptions", "in": "query", - "description": "Options that can be selected", + "description": "Json array{id: int, label: string} with options that can be selected, eg [{\"id\": 1, \"label\": \"first\"},{\"id\": 2, \"label\": \"second\"}]", "required": true, "schema": { "type": "string" @@ -6425,7 +6425,7 @@ { "name": "selectionDefault", "in": "query", - "description": "Default selected option(s)", + "description": "Json int|int[] for default selected option(s), eg 5 or [\"1\", \"8\"]", "schema": { "type": "string", "nullable": true @@ -6456,6 +6456,7 @@ "schema": { "type": "array", "nullable": true, + "default": [], "items": { "type": "integer", "format": "int64" diff --git a/tests/integration/features/APIv2.feature b/tests/integration/features/APIv2.feature index 17908b7ff..843f4d685 100644 --- a/tests/integration/features/APIv2.feature +++ b/tests/integration/features/APIv2.feature @@ -48,3 +48,19 @@ Feature: APIv2 Then node with node type "table" and node name "t2" has the following columns via v2 | Beautiful text column | Rich is cool | Counter | Progress | Checking | A single date | Then print register + + @api2selection + Scenario: Create selection columns + Given table "Table 3" with emoji "👋" exists for user "participant1-v2" as "t3" via v2 + Then column from main type "selection" for node type "table" and node name "t3" exists with name "sel-c1" and following properties via v2 + | title | sel single | + | selectionOptions | [{"id": 1, "label": "first"},{"id": 2, "label": "second"}] | + | selectionDefault | 2 | + Then column from main type "selection" for node type "table" and node name "t3" exists with name "sel-c2" and following properties via v2 + | title | sel multi | + | subtype | multi | + | selectionOptions | [{"id": 1, "label": "first"},{"id": 2, "label": "second"}] | + | selectionDefault | ["1","2"] | + Then node with node type "table" and node name "t3" has the following columns via v2 + | sel single | sel multi | + Then print register