Skip to content

Commit cac812d

Browse files
committed
fix: address review comments
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent f5a8bda commit cac812d

File tree

5 files changed

+58
-61
lines changed

5 files changed

+58
-61
lines changed

core/ResponseDefinitions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
* @psalm-type CoreTaskProcessingShape = array{
181181
* name: string,
182182
* description: string,
183-
* type: int,
183+
* type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles",
184184
* mandatory: bool,
185185
* }
186186
*
@@ -191,14 +191,16 @@
191191
* outputShape: CoreTaskProcessingShape[],
192192
* }
193193
*
194+
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>
195+
*
194196
* @psalm-type CoreTaskProcessingTask = array{
195197
* id: int,
196198
* type: string,
197199
* status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN',
198200
* userId: ?string,
199201
* appId: string,
200-
* input: array<string, numeric|list<numeric>|string|list<string>>,
201-
* output: null|array<string, numeric|list<numeric>|string|list<string>>,
202+
* input: CoreTaskProcessingIO,
203+
* output: null|CoreTaskProcessingIO,
202204
* customId: ?string,
203205
* completionExpectedAt: ?int,
204206
* progress: ?float

core/openapi.json

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,31 @@
466466
}
467467
}
468468
},
469+
"TaskProcessingIO": {
470+
"type": "object",
471+
"additionalProperties": {
472+
"anyOf": [
473+
{
474+
"type": "number"
475+
},
476+
{
477+
"type": "array",
478+
"items": {
479+
"type": "number"
480+
}
481+
},
482+
{
483+
"type": "string"
484+
},
485+
{
486+
"type": "array",
487+
"items": {
488+
"type": "string"
489+
}
490+
}
491+
]
492+
}
493+
},
469494
"TaskProcessingShape": {
470495
"type": "object",
471496
"required": [
@@ -482,8 +507,21 @@
482507
"type": "string"
483508
},
484509
"type": {
485-
"type": "integer",
486-
"format": "int64"
510+
"type": "string",
511+
"enum": [
512+
"Number",
513+
"Text",
514+
"Audio",
515+
"Image",
516+
"Video",
517+
"File",
518+
"ListOfNumbers",
519+
"ListOfTexts",
520+
"ListOfImages",
521+
"ListOfAudios",
522+
"ListOfVideos",
523+
"ListOfFiles"
524+
]
487525
},
488526
"mandatory": {
489527
"type": "boolean"
@@ -531,55 +569,11 @@
531569
"type": "string"
532570
},
533571
"input": {
534-
"type": "object",
535-
"additionalProperties": {
536-
"anyOf": [
537-
{
538-
"type": "number"
539-
},
540-
{
541-
"type": "array",
542-
"items": {
543-
"type": "number"
544-
}
545-
},
546-
{
547-
"type": "string"
548-
},
549-
{
550-
"type": "array",
551-
"items": {
552-
"type": "string"
553-
}
554-
}
555-
]
556-
}
572+
"$ref": "#/components/schemas/TaskProcessingIO"
557573
},
558574
"output": {
559-
"type": "object",
560-
"nullable": true,
561-
"additionalProperties": {
562-
"anyOf": [
563-
{
564-
"type": "number"
565-
},
566-
{
567-
"type": "array",
568-
"items": {
569-
"type": "number"
570-
}
571-
},
572-
{
573-
"type": "string"
574-
},
575-
{
576-
"type": "array",
577-
"items": {
578-
"type": "string"
579-
}
580-
}
581-
]
582-
}
575+
"$ref": "#/components/schemas/TaskProcessingIO",
576+
"nullable": true
583577
},
584578
"customId": {
585579
"type": "string",

lib/private/TaskProcessing/Manager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use OCP\Lock\LockedException;
4646
use OCP\SpeechToText\ISpeechToTextProvider;
4747
use OCP\SpeechToText\ISpeechToTextProviderWithId;
48-
use OCP\SpeechToText\ISpeechToTextProviderWithUserId;
4948
use OCP\TaskProcessing\EShapeType;
5049
use OCP\TaskProcessing\Events\TaskFailedEvent;
5150
use OCP\TaskProcessing\Events\TaskSuccessfulEvent;

lib/public/TaskProcessing/EShapeType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ enum EShapeType: int {
4242
case ListOfNumbers = 10;
4343
case ListOfTexts = 11;
4444
case ListOfImages = 12;
45-
case ListOfAudio = 13;
46-
case ListOfVideo = 14;
45+
case ListOfAudios = 13;
46+
case ListOfVideos = 14;
4747
case ListOfFiles = 15;
4848

4949
/**
@@ -84,13 +84,13 @@ public function validateInput(mixed $value): void {
8484
if ($this === EShapeType::Audio && !is_numeric($value)) {
8585
throw new ValidationException('Non-audio item provided for Audio slot');
8686
}
87-
if ($this === EShapeType::ListOfAudio && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) {
87+
if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) {
8888
throw new ValidationException('Non-audio list item provided for ListOfAudio slot');
8989
}
9090
if ($this === EShapeType::Video && !is_numeric($value)) {
9191
throw new ValidationException('Non-video item provided for Video slot');
9292
}
93-
if ($this === EShapeType::ListOfVideo && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) {
93+
if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) {
9494
throw new ValidationException('Non-video list item provided for ListOfTexts slot');
9595
}
9696
if ($this === EShapeType::File && !is_numeric($value)) {
@@ -116,13 +116,13 @@ public function validateOutput(mixed $value) {
116116
if ($this === EShapeType::Audio && !is_string($value)) {
117117
throw new ValidationException('Non-audio item provided for Audio slot');
118118
}
119-
if ($this === EShapeType::ListOfAudio && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) {
119+
if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) {
120120
throw new ValidationException('Non-audio list item provided for ListOfAudio slot');
121121
}
122122
if ($this === EShapeType::Video && !is_string($value)) {
123123
throw new ValidationException('Non-video item provided for Video slot');
124124
}
125-
if ($this === EShapeType::ListOfVideo && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) {
125+
if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) {
126126
throw new ValidationException('Non-video list item provided for ListOfTexts slot');
127127
}
128128
if ($this === EShapeType::File && !is_string($value)) {

lib/public/TaskProcessing/ShapeDescriptor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public function getShapeType(): EShapeType {
4545
}
4646

4747
/**
48-
* @return array{name: string, description: string, type: int}
48+
* @return array{name: string, description: string, type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles"}
4949
* @since 30.0.0
5050
*/
5151
public function jsonSerialize(): array {
52+
/** @var "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles" $type */
53+
$type = $this->getShapeType()->name;
5254
return [
5355
'name' => $this->getName(),
5456
'description' => $this->getDescription(),
55-
'type' => $this->getShapeType()->value,
57+
'type' => $type,
5658
];
5759
}
5860
}

0 commit comments

Comments
 (0)