From cac812dc580079f2772623641ba70985714ad7b2 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 14 May 2024 10:01:09 +0200 Subject: [PATCH] fix: address review comments Signed-off-by: Marcel Klehr --- core/ResponseDefinitions.php | 8 +- core/openapi.json | 92 +++++++++---------- lib/private/TaskProcessing/Manager.php | 1 - lib/public/TaskProcessing/EShapeType.php | 12 +-- lib/public/TaskProcessing/ShapeDescriptor.php | 6 +- 5 files changed, 58 insertions(+), 61 deletions(-) diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 23d89b25adfb0..6b537a3c461c9 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -180,7 +180,7 @@ * @psalm-type CoreTaskProcessingShape = array{ * name: string, * description: string, - * type: int, + * type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles", * mandatory: bool, * } * @@ -191,14 +191,16 @@ * outputShape: CoreTaskProcessingShape[], * } * + * @psalm-type CoreTaskProcessingIO = array|string|list> + * * @psalm-type CoreTaskProcessingTask = array{ * id: int, * type: string, * status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', * userId: ?string, * appId: string, - * input: array|string|list>, - * output: null|array|string|list>, + * input: CoreTaskProcessingIO, + * output: null|CoreTaskProcessingIO, * customId: ?string, * completionExpectedAt: ?int, * progress: ?float diff --git a/core/openapi.json b/core/openapi.json index c6802be54919b..d4067eac3cda8 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -466,6 +466,31 @@ } } }, + "TaskProcessingIO": { + "type": "object", + "additionalProperties": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "array", + "items": { + "type": "number" + } + }, + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, "TaskProcessingShape": { "type": "object", "required": [ @@ -482,8 +507,21 @@ "type": "string" }, "type": { - "type": "integer", - "format": "int64" + "type": "string", + "enum": [ + "Number", + "Text", + "Audio", + "Image", + "Video", + "File", + "ListOfNumbers", + "ListOfTexts", + "ListOfImages", + "ListOfAudios", + "ListOfVideos", + "ListOfFiles" + ] }, "mandatory": { "type": "boolean" @@ -531,55 +569,11 @@ "type": "string" }, "input": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "array", - "items": { - "type": "number" - } - }, - { - "type": "string" - }, - { - "type": "array", - "items": { - "type": "string" - } - } - ] - } + "$ref": "#/components/schemas/TaskProcessingIO" }, "output": { - "type": "object", - "nullable": true, - "additionalProperties": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "array", - "items": { - "type": "number" - } - }, - { - "type": "string" - }, - { - "type": "array", - "items": { - "type": "string" - } - } - ] - } + "$ref": "#/components/schemas/TaskProcessingIO", + "nullable": true }, "customId": { "type": "string", diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index f72d86bb97e97..c0336675e6927 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -45,7 +45,6 @@ use OCP\Lock\LockedException; use OCP\SpeechToText\ISpeechToTextProvider; use OCP\SpeechToText\ISpeechToTextProviderWithId; -use OCP\SpeechToText\ISpeechToTextProviderWithUserId; use OCP\TaskProcessing\EShapeType; use OCP\TaskProcessing\Events\TaskFailedEvent; use OCP\TaskProcessing\Events\TaskSuccessfulEvent; diff --git a/lib/public/TaskProcessing/EShapeType.php b/lib/public/TaskProcessing/EShapeType.php index 5555671976b67..1f612a11dd59e 100644 --- a/lib/public/TaskProcessing/EShapeType.php +++ b/lib/public/TaskProcessing/EShapeType.php @@ -42,8 +42,8 @@ enum EShapeType: int { case ListOfNumbers = 10; case ListOfTexts = 11; case ListOfImages = 12; - case ListOfAudio = 13; - case ListOfVideo = 14; + case ListOfAudios = 13; + case ListOfVideos = 14; case ListOfFiles = 15; /** @@ -84,13 +84,13 @@ public function validateInput(mixed $value): void { if ($this === EShapeType::Audio && !is_numeric($value)) { throw new ValidationException('Non-audio item provided for Audio slot'); } - if ($this === EShapeType::ListOfAudio && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); } if ($this === EShapeType::Video && !is_numeric($value)) { throw new ValidationException('Non-video item provided for Video slot'); } - if ($this === EShapeType::ListOfVideo && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { throw new ValidationException('Non-video list item provided for ListOfTexts slot'); } if ($this === EShapeType::File && !is_numeric($value)) { @@ -116,13 +116,13 @@ public function validateOutput(mixed $value) { if ($this === EShapeType::Audio && !is_string($value)) { throw new ValidationException('Non-audio item provided for Audio slot'); } - if ($this === EShapeType::ListOfAudio && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); } if ($this === EShapeType::Video && !is_string($value)) { throw new ValidationException('Non-video item provided for Video slot'); } - if ($this === EShapeType::ListOfVideo && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { throw new ValidationException('Non-video list item provided for ListOfTexts slot'); } if ($this === EShapeType::File && !is_string($value)) { diff --git a/lib/public/TaskProcessing/ShapeDescriptor.php b/lib/public/TaskProcessing/ShapeDescriptor.php index 6c14bab751e38..b389b0cebd21c 100644 --- a/lib/public/TaskProcessing/ShapeDescriptor.php +++ b/lib/public/TaskProcessing/ShapeDescriptor.php @@ -45,14 +45,16 @@ public function getShapeType(): EShapeType { } /** - * @return array{name: string, description: string, type: int} + * @return array{name: string, description: string, type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles"} * @since 30.0.0 */ public function jsonSerialize(): array { + /** @var "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles" $type */ + $type = $this->getShapeType()->name; return [ 'name' => $this->getName(), 'description' => $this->getDescription(), - 'type' => $this->getShapeType()->value, + 'type' => $type, ]; } }