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

Fix broken taskprocessing api /tasktypes endpoint #50094

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 60 additions & 20 deletions core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCP\TaskProcessing\ShapeEnumValue;
use OCP\TaskProcessing\Task;
use RuntimeException;
use stdClass;

/**
* @psalm-import-type CoreTaskProcessingTask from ResponseDefinitions
Expand Down Expand Up @@ -67,31 +68,70 @@ public function __construct(
#[PublicPage]
#[ApiRoute(verb: 'GET', url: '/tasktypes', root: '/taskprocessing')]
public function taskTypes(): DataResponse {
/** @var array<string, CoreTaskProcessingTaskType> $taskTypes */
$taskTypes = array_map(function (array $tt) {
$tt['inputShape'] = array_values(array_map(function ($descriptor) {
$tt['inputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['inputShape']));
$tt['outputShape'] = array_values(array_map(function ($descriptor) {
}, $tt['inputShape']);
if (empty($tt['inputShape'])) {
$tt['inputShape'] = new stdClass;
}

$tt['outputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['outputShape']));
$tt['optionalInputShape'] = array_values(array_map(function ($descriptor) {
}, $tt['outputShape']);
if (empty($tt['outputShape'])) {
$tt['outputShape'] = new stdClass;
}

$tt['optionalInputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalInputShape']));
$tt['optionalOutputShape'] = array_values(array_map(function ($descriptor) {
}, $tt['optionalInputShape']);
if (empty($tt['optionalInputShape'])) {
$tt['optionalInputShape'] = new stdClass;
}

$tt['optionalOutputShape'] = array_map(function ($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalOutputShape']));
$tt['inputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
}, $tt['inputShapeEnumValues']));
$tt['optionalInputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
}, $tt['optionalInputShapeEnumValues']));
$tt['outputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
}, $tt['outputShapeEnumValues']));
$tt['optionalOutputShapeEnumValues'] = array_values(array_map(function (array $enumValues) {
return array_values(array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues));
}, $tt['optionalOutputShapeEnumValues']));
}, $tt['optionalOutputShape']);
if (empty($tt['optionalOutputShape'])) {
$tt['optionalOutputShape'] = new stdClass;
}

$tt['inputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['inputShapeEnumValues']);
if (empty($tt['inputShapeEnumValues'])) {
$tt['inputShapeEnumValues'] = new stdClass;
}

$tt['optionalInputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalInputShapeEnumValues']);
if (empty($tt['optionalInputShapeEnumValues'])) {
$tt['optionalInputShapeEnumValues'] = new stdClass;
}

$tt['outputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['outputShapeEnumValues']);
if (empty($tt['outputShapeEnumValues'])) {
$tt['outputShapeEnumValues'] = new stdClass;
}

$tt['optionalOutputShapeEnumValues'] = array_map(function (array $enumValues) {
return array_map(fn (ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalOutputShapeEnumValues']);
if (empty($tt['optionalOutputShapeEnumValues'])) {
$tt['optionalOutputShapeEnumValues'] = new stdClass;
}

if (empty($tt['inputShapeDefaults'])) {
$tt['inputShapeDefaults'] = new stdClass;
}
if (empty($tt['optionalInputShapeDefaults'])) {
$tt['optionalInputShapeDefaults'] = new stdClass;
}
return $tt;
}, $this->taskProcessingManager->getAvailableTaskTypes());
return new DataResponse([
Expand Down
16 changes: 8 additions & 8 deletions core/ResponseDefinitions.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdClass class missing

Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@
* @psalm-type CoreTaskProcessingTaskType = array{
* name: string,
* description: string,
* inputShape: list<CoreTaskProcessingShape>,
* inputShapeEnumValues: list<list<array{name: string, value: string}>>,
* inputShape: array<string, CoreTaskProcessingShape>,
* inputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
* inputShapeDefaults: array<string, numeric|string>,
* optionalInputShape: list<CoreTaskProcessingShape>,
* optionalInputShapeEnumValues: list<list<array{name: string, value: string}>>,
* optionalInputShape: array<string, CoreTaskProcessingShape>,
* optionalInputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
* optionalInputShapeDefaults: array<string, numeric|string>,
* outputShape: list<CoreTaskProcessingShape>,
* outputShapeEnumValues: list<list<array{name: string, value: string}>>,
* optionalOutputShape: list<CoreTaskProcessingShape>,
* optionalOutputShapeEnumValues: list<list<array{name: string, value: string}>>,
* outputShape: array<string, CoreTaskProcessingShape>,
* outputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
* optionalOutputShape: array<string, CoreTaskProcessingShape>,
* optionalOutputShapeEnumValues: array<string, list<array{name: string, value: string}>>,
* }
*
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>
Expand Down
32 changes: 16 additions & 16 deletions core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,14 @@
"type": "string"
},
"inputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"inputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -675,14 +675,14 @@
}
},
"optionalInputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalInputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -715,14 +715,14 @@
}
},
"outputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"outputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand All @@ -742,14 +742,14 @@
}
},
"optionalOutputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalOutputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down
32 changes: 16 additions & 16 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,14 @@
"type": "string"
},
"inputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"inputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -675,14 +675,14 @@
}
},
"optionalInputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalInputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -715,14 +715,14 @@
}
},
"outputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"outputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand All @@ -742,14 +742,14 @@
}
},
"optionalOutputShape": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/TaskProcessingShape"
}
},
"optionalOutputShapeEnumValues": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
Expand Down
Loading