Skip to content

Commit d3ec3de

Browse files
authored
Merge pull request #50094 from nextcloud/fix/noid/broken-taskprocessing-api
Fix broken taskprocessing api /tasktypes endpoint
2 parents 4a3fcea + 7bf74f9 commit d3ec3de

File tree

4 files changed

+100
-60
lines changed

4 files changed

+100
-60
lines changed

core/Controller/TaskProcessingApiController.php

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCP\TaskProcessing\ShapeEnumValue;
4040
use OCP\TaskProcessing\Task;
4141
use RuntimeException;
42+
use stdClass;
4243

4344
/**
4445
* @psalm-import-type CoreTaskProcessingTask from ResponseDefinitions
@@ -67,31 +68,70 @@ public function __construct(
6768
#[PublicPage]
6869
#[ApiRoute(verb: 'GET', url: '/tasktypes', root: '/taskprocessing')]
6970
public function taskTypes(): DataResponse {
71+
/** @var array<string, CoreTaskProcessingTaskType> $taskTypes */
7072
$taskTypes = array_map(function (array $tt) {
71-
$tt['inputShape'] = array_values(array_map(function ($descriptor) {
73+
$tt['inputShape'] = array_map(function ($descriptor) {
7274
return $descriptor->jsonSerialize();
73-
}, $tt['inputShape']));
74-
$tt['outputShape'] = array_values(array_map(function ($descriptor) {
75+
}, $tt['inputShape']);
76+
if (empty($tt['inputShape'])) {
77+
$tt['inputShape'] = new stdClass;
78+
}
79+
80+
$tt['outputShape'] = array_map(function ($descriptor) {
7581
return $descriptor->jsonSerialize();
76-
}, $tt['outputShape']));
77-
$tt['optionalInputShape'] = array_values(array_map(function ($descriptor) {
82+
}, $tt['outputShape']);
83+
if (empty($tt['outputShape'])) {
84+
$tt['outputShape'] = new stdClass;
85+
}
86+
87+
$tt['optionalInputShape'] = array_map(function ($descriptor) {
7888
return $descriptor->jsonSerialize();
79-
}, $tt['optionalInputShape']));
80-
$tt['optionalOutputShape'] = array_values(array_map(function ($descriptor) {
89+
}, $tt['optionalInputShape']);
90+
if (empty($tt['optionalInputShape'])) {
91+
$tt['optionalInputShape'] = new stdClass;
92+
}
93+
94+
$tt['optionalOutputShape'] = array_map(function ($descriptor) {
8195
return $descriptor->jsonSerialize();
82-
}, $tt['optionalOutputShape']));
83-
$tt['inputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
84-
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
85-
}, $tt['inputShapeEnumValues']));
86-
$tt['optionalInputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
87-
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
88-
}, $tt['optionalInputShapeEnumValues']));
89-
$tt['outputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
90-
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
91-
}, $tt['outputShapeEnumValues']));
92-
$tt['optionalOutputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
93-
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
94-
}, $tt['optionalOutputShapeEnumValues']));
96+
}, $tt['optionalOutputShape']);
97+
if (empty($tt['optionalOutputShape'])) {
98+
$tt['optionalOutputShape'] = new stdClass;
99+
}
100+
101+
$tt['inputShapeEnumValues'] = array_map(function (array $enumValues) {
102+
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
103+
}, $tt['inputShapeEnumValues']);
104+
if (empty($tt['inputShapeEnumValues'])) {
105+
$tt['inputShapeEnumValues'] = new stdClass;
106+
}
107+
108+
$tt['optionalInputShapeEnumValues'] = array_map(function (array $enumValues) {
109+
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
110+
}, $tt['optionalInputShapeEnumValues']);
111+
if (empty($tt['optionalInputShapeEnumValues'])) {
112+
$tt['optionalInputShapeEnumValues'] = new stdClass;
113+
}
114+
115+
$tt['outputShapeEnumValues'] = array_map(function (array $enumValues) {
116+
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
117+
}, $tt['outputShapeEnumValues']);
118+
if (empty($tt['outputShapeEnumValues'])) {
119+
$tt['outputShapeEnumValues'] = new stdClass;
120+
}
121+
122+
$tt['optionalOutputShapeEnumValues'] = array_map(function (array $enumValues) {
123+
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
124+
}, $tt['optionalOutputShapeEnumValues']);
125+
if (empty($tt['optionalOutputShapeEnumValues'])) {
126+
$tt['optionalOutputShapeEnumValues'] = new stdClass;
127+
}
128+
129+
if (empty($tt['inputShapeDefaults'])) {
130+
$tt['inputShapeDefaults'] = new stdClass;
131+
}
132+
if (empty($tt['optionalInputShapeDefaults'])) {
133+
$tt['optionalInputShapeDefaults'] = new stdClass;
134+
}
95135
return $tt;
96136
}, $this->taskProcessingManager->getAvailableTaskTypes());
97137
return new DataResponse([

core/ResponseDefinitions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@
171171
* @psalm-type CoreTaskProcessingTaskType = array{
172172
* name: string,
173173
* description: string,
174-
* inputShape: list<CoreTaskProcessingShape>,
175-
* inputShapeEnumValues: list<list<array{name: string, value: string}>>,
174+
* inputShape: array<string, CoreTaskProcessingShape>,
175+
* inputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
176176
* inputShapeDefaults: array<string, numeric|string>,
177-
* optionalInputShape: list<CoreTaskProcessingShape>,
178-
* optionalInputShapeEnumValues: list<list<array{name: string, value: string}>>,
177+
* optionalInputShape: array<string, CoreTaskProcessingShape>,
178+
* optionalInputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
179179
* optionalInputShapeDefaults: array<string, numeric|string>,
180-
* outputShape: list<CoreTaskProcessingShape>,
181-
* outputShapeEnumValues: list<list<array{name: string, value: string}>>,
182-
* optionalOutputShape: list<CoreTaskProcessingShape>,
183-
* optionalOutputShapeEnumValues: list<list<array{name: string, value: string}>>,
180+
* outputShape: array<string, CoreTaskProcessingShape>,
181+
* outputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
182+
* optionalOutputShape: array<string, CoreTaskProcessingShape>,
183+
* optionalOutputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
184184
* }
185185
*
186186
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>

core/openapi-full.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,14 @@
635635
"type": "string"
636636
},
637637
"inputShape": {
638-
"type": "array",
639-
"items": {
638+
"type": "object",
639+
"additionalProperties": {
640640
"$ref": "#/components/schemas/TaskProcessingShape"
641641
}
642642
},
643643
"inputShapeEnumValues": {
644-
"type": "array",
645-
"items": {
644+
"type": "object",
645+
"additionalProperties": {
646646
"type": "array",
647647
"items": {
648648
"type": "object",
@@ -675,14 +675,14 @@
675675
}
676676
},
677677
"optionalInputShape": {
678-
"type": "array",
679-
"items": {
678+
"type": "object",
679+
"additionalProperties": {
680680
"$ref": "#/components/schemas/TaskProcessingShape"
681681
}
682682
},
683683
"optionalInputShapeEnumValues": {
684-
"type": "array",
685-
"items": {
684+
"type": "object",
685+
"additionalProperties": {
686686
"type": "array",
687687
"items": {
688688
"type": "object",
@@ -715,14 +715,14 @@
715715
}
716716
},
717717
"outputShape": {
718-
"type": "array",
719-
"items": {
718+
"type": "object",
719+
"additionalProperties": {
720720
"$ref": "#/components/schemas/TaskProcessingShape"
721721
}
722722
},
723723
"outputShapeEnumValues": {
724-
"type": "array",
725-
"items": {
724+
"type": "object",
725+
"additionalProperties": {
726726
"type": "array",
727727
"items": {
728728
"type": "object",
@@ -742,14 +742,14 @@
742742
}
743743
},
744744
"optionalOutputShape": {
745-
"type": "array",
746-
"items": {
745+
"type": "object",
746+
"additionalProperties": {
747747
"$ref": "#/components/schemas/TaskProcessingShape"
748748
}
749749
},
750750
"optionalOutputShapeEnumValues": {
751-
"type": "array",
752-
"items": {
751+
"type": "object",
752+
"additionalProperties": {
753753
"type": "array",
754754
"items": {
755755
"type": "object",

core/openapi.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,14 @@
635635
"type": "string"
636636
},
637637
"inputShape": {
638-
"type": "array",
639-
"items": {
638+
"type": "object",
639+
"additionalProperties": {
640640
"$ref": "#/components/schemas/TaskProcessingShape"
641641
}
642642
},
643643
"inputShapeEnumValues": {
644-
"type": "array",
645-
"items": {
644+
"type": "object",
645+
"additionalProperties": {
646646
"type": "array",
647647
"items": {
648648
"type": "object",
@@ -675,14 +675,14 @@
675675
}
676676
},
677677
"optionalInputShape": {
678-
"type": "array",
679-
"items": {
678+
"type": "object",
679+
"additionalProperties": {
680680
"$ref": "#/components/schemas/TaskProcessingShape"
681681
}
682682
},
683683
"optionalInputShapeEnumValues": {
684-
"type": "array",
685-
"items": {
684+
"type": "object",
685+
"additionalProperties": {
686686
"type": "array",
687687
"items": {
688688
"type": "object",
@@ -715,14 +715,14 @@
715715
}
716716
},
717717
"outputShape": {
718-
"type": "array",
719-
"items": {
718+
"type": "object",
719+
"additionalProperties": {
720720
"$ref": "#/components/schemas/TaskProcessingShape"
721721
}
722722
},
723723
"outputShapeEnumValues": {
724-
"type": "array",
725-
"items": {
724+
"type": "object",
725+
"additionalProperties": {
726726
"type": "array",
727727
"items": {
728728
"type": "object",
@@ -742,14 +742,14 @@
742742
}
743743
},
744744
"optionalOutputShape": {
745-
"type": "array",
746-
"items": {
745+
"type": "object",
746+
"additionalProperties": {
747747
"$ref": "#/components/schemas/TaskProcessingShape"
748748
}
749749
},
750750
"optionalOutputShapeEnumValues": {
751-
"type": "array",
752-
"items": {
751+
"type": "object",
752+
"additionalProperties": {
753753
"type": "array",
754754
"items": {
755755
"type": "object",

0 commit comments

Comments
 (0)