Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed May 14, 2024
1 parent 63deefe commit e1a7a49
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 61 deletions.
8 changes: 5 additions & 3 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
* }
*
Expand All @@ -191,14 +191,16 @@
* outputShape: CoreTaskProcessingShape[],
* }
*
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>
*
* @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, numeric|list<numeric>|string|list<string>>,
* output: null|array<string, numeric|list<numeric>|string|list<string>>,
* input: CoreTaskProcessingIO,
* output: null|CoreTaskProcessingIO,
* customId: ?string,
* completionExpectedAt: ?int,
* progress: ?float
Expand Down
92 changes: 43 additions & 49 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions lib/public/TaskProcessing/EShapeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/public/TaskProcessing/ShapeDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}

0 comments on commit e1a7a49

Please sign in to comment.