Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TaskProcessing): Implement enums and default values #46722

Merged
merged 11 commits into from
Jul 25, 2024
49 changes: 29 additions & 20 deletions core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use OCP\TaskProcessing\Exception\UnauthorizedException;
use OCP\TaskProcessing\Exception\ValidationException;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\ShapeDescriptor;
use OCP\TaskProcessing\ShapeEnumValue;
use OCP\TaskProcessing\Task;
use RuntimeException;

Expand Down Expand Up @@ -67,26 +67,35 @@ public function __construct(
#[PublicPage]
#[ApiRoute(verb: 'GET', url: '/tasktypes', root: '/taskprocessing')]
public function taskTypes(): DataResponse {
$taskTypes = $this->taskProcessingManager->getAvailableTaskTypes();

$serializedTaskTypes = [];
foreach ($taskTypes as $key => $taskType) {
$serializedTaskTypes[$key] = [
'name' => $taskType['name'],
'description' => $taskType['description'],
'inputShape' => array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => true], $taskType['inputShape'])
+ array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => false], $taskType['optionalInputShape']),
'outputShape' => array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => true], $taskType['outputShape'])
+ array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => false], $taskType['optionalOutputShape']),
];
}

$taskTypes = array_map(function (array $tt) {
$tt['inputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['inputShape']);
$tt['outputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['outputShape']);
$tt['optionalInputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalInputShape']);
$tt['optionalOutputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalOutputShape']);
$tt['inputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['inputShapeEnumValues']);
$tt['optionalInputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalInputShapeEnumValues']);
$tt['outputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['outputShapeEnumValues']);
$tt['optionalOutputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalOutputShapeEnumValues']);
return $tt;
}, $this->taskProcessingManager->getAvailableTaskTypes());
return new DataResponse([
'types' => $serializedTaskTypes,
'types' => $taskTypes,
]);
}

Expand Down
11 changes: 9 additions & 2 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,22 @@
* @psalm-type CoreTaskProcessingShape = array{
* name: string,
* description: string,
* type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles",
* mandatory: bool,
* type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"Enum"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles",
* }
*
* @psalm-type CoreTaskProcessingTaskType = array{
* name: string,
* description: string,
* inputShape: CoreTaskProcessingShape[],
* inputShapeEnumValues: array{name: string, value: string}[][],
* inputShapeDefaults: array<string, numeric|string>,
* optionalInputShape: CoreTaskProcessingShape[],
* optionalInputShapeEnumValues: array{name: string, value: string}[][],
* optionalInputShapeDefaults: array<string, numeric|string>,
* outputShape: CoreTaskProcessingShape[],
* outputShapeEnumValues: array{name: string, value: string}[][],
* optionalOutputShape: CoreTaskProcessingShape[],
* optionalOutputShapeEnumValues: array{name: string, value: string}[][]}
* }
*
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>
Expand Down
139 changes: 133 additions & 6 deletions core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@
"required": [
"name",
"description",
"type",
"mandatory"
"type"
],
"properties": {
"name": {
Expand All @@ -515,16 +514,14 @@
"Image",
"Video",
"File",
"Enum",
"ListOfNumbers",
"ListOfTexts",
"ListOfImages",
"ListOfAudios",
"ListOfVideos",
"ListOfFiles"
]
},
"mandatory": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -602,7 +599,15 @@
"name",
"description",
"inputShape",
"outputShape"
"inputShapeEnumValues",
"inputShapeDefaults",
"optionalInputShape",
"optionalInputShapeEnumValues",
"optionalInputShapeDefaults",
"outputShape",
"outputShapeEnumValues",
"optionalOutputShape",
"optionalOutputShapeEnumValues"
],
"properties": {
"name": {
Expand All @@ -617,11 +622,133 @@
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"inputShapeEnumValues": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
},
"inputShapeDefaults": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
}
},
"optionalInputShape": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalInputShapeEnumValues": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
},
"optionalInputShapeDefaults": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
}
},
"outputShape": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"outputShapeEnumValues": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
},
"optionalOutputShape": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalOutputShapeEnumValues": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
},
Expand Down
Loading
Loading