Skip to content

Commit 2552950

Browse files
committed
fix(core): Fix TeamsApiController typing
Signed-off-by: provokateurin <[email protected]>
1 parent 2ea30f9 commit 2552950

File tree

7 files changed

+201
-51
lines changed

7 files changed

+201
-51
lines changed

core/Controller/TeamsApiController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
use OCP\IRequest;
1818
use OCP\Teams\ITeamManager;
1919
use OCP\Teams\Team;
20+
use OCP\Teams\TeamResource;
2021

2122
/**
2223
* @psalm-import-type CoreTeamResource from ResponseDefinitions
2324
* @psalm-import-type CoreTeam from ResponseDefinitions
25+
* @psalm-import-type CoreTeamWithResources from ResponseDefinitions
2426
* @property $userId string
2527
*/
2628
class TeamsApiController extends OCSController {
@@ -44,21 +46,18 @@ public function __construct(
4446
#[NoAdminRequired]
4547
#[ApiRoute(verb: 'GET', url: '/{teamId}/resources', root: '/teams')]
4648
public function resolveOne(string $teamId): DataResponse {
47-
/**
48-
* @var list<CoreTeamResource> $resolvedResources
49-
* @psalm-suppress PossiblyNullArgument The route is limited to logged-in users
50-
*/
49+
/** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */
5150
$resolvedResources = $this->teamManager->getSharedWith($teamId, $this->userId);
5251

53-
return new DataResponse(['resources' => $resolvedResources]);
52+
return new DataResponse(['resources' => array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $resolvedResources)]);
5453
}
5554

5655
/**
5756
* Get all teams of a resource
5857
*
5958
* @param string $providerId Identifier of the provider (e.g. deck, talk, collectives)
6059
* @param string $resourceId Unique id of the resource to list teams for (e.g. deck board id)
61-
* @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeam>}, array{}>
60+
* @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeamWithResources>}, array{}>
6261
*
6362
* 200: Teams returned
6463
*/
@@ -67,11 +66,10 @@ public function resolveOne(string $teamId): DataResponse {
6766
public function listTeams(string $providerId, string $resourceId): DataResponse {
6867
/** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */
6968
$teams = $this->teamManager->getTeamsForResource($providerId, $resourceId, $this->userId);
70-
/** @var list<CoreTeam> $teams */
7169
$teams = array_values(array_map(function (Team $team) {
7270
$response = $team->jsonSerialize();
7371
/** @psalm-suppress PossiblyNullArgument The route is limited to logged in users */
74-
$response['resources'] = $this->teamManager->getSharedWith($team->getId(), $this->userId);
72+
$response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $this->teamManager->getSharedWith($team->getId(), $this->userId));
7573
return $response;
7674
}, $teams));
7775

core/ResponseDefinitions.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,28 @@
149149
* }
150150
*
151151
* @psalm-type CoreTeam = array{
152-
* id: string,
153-
* name: string,
154-
* icon: string,
152+
* teamId: string,
153+
* displayName: string,
154+
* link: ?string,
155155
* }
156156
*
157157
* @psalm-type CoreTeamResource = array{
158-
* id: int,
159-
* label: string,
160-
* url: string,
161-
* iconSvg: ?string,
162-
* iconURL: ?string,
163-
* iconEmoji: ?string,
164-
* }
158+
* id: string,
159+
* label: string,
160+
* url: string,
161+
* iconSvg: ?string,
162+
* iconURL: ?string,
163+
* iconEmoji: ?string,
164+
* provider: array{
165+
* id: string,
166+
* name: string,
167+
* icon: string,
168+
* },
169+
* }
170+
*
171+
* @psalm-type CoreTeamWithResources = CoreTeam&array{
172+
* resources: list<CoreTeamResource>,
173+
* }
165174
*
166175
* @psalm-type CoreTaskProcessingShape = array{
167176
* name: string,

core/openapi-full.json

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,20 @@
898898
"Team": {
899899
"type": "object",
900900
"required": [
901-
"id",
902-
"name",
903-
"icon"
901+
"teamId",
902+
"displayName",
903+
"link"
904904
],
905905
"properties": {
906-
"id": {
906+
"teamId": {
907907
"type": "string"
908908
},
909-
"name": {
909+
"displayName": {
910910
"type": "string"
911911
},
912-
"icon": {
913-
"type": "string"
912+
"link": {
913+
"type": "string",
914+
"nullable": true
914915
}
915916
}
916917
},
@@ -922,12 +923,12 @@
922923
"url",
923924
"iconSvg",
924925
"iconURL",
925-
"iconEmoji"
926+
"iconEmoji",
927+
"provider"
926928
],
927929
"properties": {
928930
"id": {
929-
"type": "integer",
930-
"format": "int64"
931+
"type": "string"
931932
},
932933
"label": {
933934
"type": "string"
@@ -946,9 +947,49 @@
946947
"iconEmoji": {
947948
"type": "string",
948949
"nullable": true
950+
},
951+
"provider": {
952+
"type": "object",
953+
"required": [
954+
"id",
955+
"name",
956+
"icon"
957+
],
958+
"properties": {
959+
"id": {
960+
"type": "string"
961+
},
962+
"name": {
963+
"type": "string"
964+
},
965+
"icon": {
966+
"type": "string"
967+
}
968+
}
949969
}
950970
}
951971
},
972+
"TeamWithResources": {
973+
"allOf": [
974+
{
975+
"$ref": "#/components/schemas/Team"
976+
},
977+
{
978+
"type": "object",
979+
"required": [
980+
"resources"
981+
],
982+
"properties": {
983+
"resources": {
984+
"type": "array",
985+
"items": {
986+
"$ref": "#/components/schemas/TeamResource"
987+
}
988+
}
989+
}
990+
}
991+
]
992+
},
952993
"TextProcessingTask": {
953994
"type": "object",
954995
"required": [
@@ -6306,7 +6347,7 @@
63066347
"teams": {
63076348
"type": "array",
63086349
"items": {
6309-
"$ref": "#/components/schemas/Team"
6350+
"$ref": "#/components/schemas/TeamWithResources"
63106351
}
63116352
}
63126353
}

core/openapi.json

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,20 @@
898898
"Team": {
899899
"type": "object",
900900
"required": [
901-
"id",
902-
"name",
903-
"icon"
901+
"teamId",
902+
"displayName",
903+
"link"
904904
],
905905
"properties": {
906-
"id": {
906+
"teamId": {
907907
"type": "string"
908908
},
909-
"name": {
909+
"displayName": {
910910
"type": "string"
911911
},
912-
"icon": {
913-
"type": "string"
912+
"link": {
913+
"type": "string",
914+
"nullable": true
914915
}
915916
}
916917
},
@@ -922,12 +923,12 @@
922923
"url",
923924
"iconSvg",
924925
"iconURL",
925-
"iconEmoji"
926+
"iconEmoji",
927+
"provider"
926928
],
927929
"properties": {
928930
"id": {
929-
"type": "integer",
930-
"format": "int64"
931+
"type": "string"
931932
},
932933
"label": {
933934
"type": "string"
@@ -946,9 +947,49 @@
946947
"iconEmoji": {
947948
"type": "string",
948949
"nullable": true
950+
},
951+
"provider": {
952+
"type": "object",
953+
"required": [
954+
"id",
955+
"name",
956+
"icon"
957+
],
958+
"properties": {
959+
"id": {
960+
"type": "string"
961+
},
962+
"name": {
963+
"type": "string"
964+
},
965+
"icon": {
966+
"type": "string"
967+
}
968+
}
949969
}
950970
}
951971
},
972+
"TeamWithResources": {
973+
"allOf": [
974+
{
975+
"$ref": "#/components/schemas/Team"
976+
},
977+
{
978+
"type": "object",
979+
"required": [
980+
"resources"
981+
],
982+
"properties": {
983+
"resources": {
984+
"type": "array",
985+
"items": {
986+
"$ref": "#/components/schemas/TeamResource"
987+
}
988+
}
989+
}
990+
}
991+
]
992+
},
952993
"TextProcessingTask": {
953994
"type": "object",
954995
"required": [
@@ -6306,7 +6347,7 @@
63066347
"teams": {
63076348
"type": "array",
63086349
"items": {
6309-
"$ref": "#/components/schemas/Team"
6350+
"$ref": "#/components/schemas/TeamWithResources"
63106351
}
63116352
}
63126353
}

lib/public/Teams/Team.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public function getLink(): ?string {
5050
}
5151

5252
/**
53+
* @return array{
54+
* teamId: string,
55+
* displayName: string,
56+
* link: ?string,
57+
* }
58+
*
5359
* @since 29.0.0
5460
*/
5561
public function jsonSerialize(): array {

lib/public/Teams/TeamResource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ public function getIconEmoji(): ?string {
9494
}
9595

9696
/**
97+
* @return array{
98+
* id: string,
99+
* label: string,
100+
* url: string,
101+
* iconSvg: ?string,
102+
* iconURL: ?string,
103+
* iconEmoji: ?string,
104+
* provider: array{
105+
* id: string,
106+
* name: string,
107+
* icon: string,
108+
* },
109+
* }
110+
*
97111
* @since 29.0.0
98112
*/
99113
public function jsonSerialize(): array {

0 commit comments

Comments
 (0)