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(OpenAPI): Fix duplicate status code definitions #294

Merged
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
10 changes: 4 additions & 6 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function deleteMember(string $projectId, int $memberId): DataResponse {
* @param null $activated
* @param string|null $color
* @param string|null $userId
* @return DataResponse<Http::STATUS_OK, null, array{}>|DataResponse<Http::STATUS_OK, CospendMember, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array<string, string>, array{}>
* @return DataResponse<Http::STATUS_OK, ?CospendMember, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array<string, string>, array{}>
*
* 200: Member was successfully edited (and deleted if it was disabled and wasn't ower of any bill)
* 400: Failed to edit the member
Expand All @@ -398,13 +398,11 @@ public function editMember(
$activated = false;
}
$result = $this->projectService->editMember($projectId, $memberId, $name, $userId, $weight, $activated, $color);
if (empty($result)) {
return new DataResponse(null);
} elseif (isset($result['activated'])) {
if ($result === null || isset($result['activated'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, Http::STATUS_BAD_REQUEST);
}

return new DataResponse($result, Http::STATUS_BAD_REQUEST);
}

/**
Expand Down
16 changes: 6 additions & 10 deletions lib/Controller/OldApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,11 @@ public function apiEditMember(string $token, int $memberid,
$result = $this->projectService->editMember(
$publicShareInfo['projectid'], $memberid, $name, $userid, $weight, $activated, $color
);
if (count($result) === 0) {
return new DataResponse(null);
} elseif (array_key_exists('activated', $result)) {
if ($result === null || isset($result['activated'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

#[NoAdminRequired]
Expand All @@ -744,13 +742,11 @@ public function apiPrivEditMember(string $projectId, int $memberid, ?string $nam
$activated = false;
}
$result = $this->projectService->editMember($projectId, $memberid, $name, $userid, $weight, $activated, $color);
if (count($result) === 0) {
return new DataResponse(null);
} elseif (array_key_exists('activated', $result)) {
if ($result === null || isset($result['activated'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

#[NoAdminRequired]
Expand Down
10 changes: 4 additions & 6 deletions lib/Controller/PublicApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public function publicDeleteMember(string $token, int $memberId): DataResponse {
* @param null $activated
* @param string|null $color
* @param string|null $userId
* @return DataResponse<Http::STATUS_OK, null, array{}>|DataResponse<Http::STATUS_OK, CospendMember, array{}>|DataResponse<Http::STATUS_FORBIDDEN, array<string, string>, array{}>
* @return DataResponse<Http::STATUS_OK, ?CospendMember, array{}>|DataResponse<Http::STATUS_FORBIDDEN, array<string, string>, array{}>
* @throws Exception
*/
#[NoAdminRequired]
Expand All @@ -727,13 +727,11 @@ public function publicEditMember(
$result = $this->projectService->editMember(
$publicShareInfo['projectid'], $memberId, $name, $userId, $weight, $activated, $color
);
if (count($result) === 0) {
return new DataResponse(null);
} elseif (isset($result['activated'])) {
if ($result === null || isset($result['activated'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

return new DataResponse($result, Http::STATUS_FORBIDDEN);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1269,12 +1269,12 @@ private function sortCreditersDebiters(array $arr, bool $reverse = false): array
* @param float|null $weight
* @param bool $activated
* @param string|null $color
* @return array
* @return array|null
*/
public function editMember(
string $projectId, int $memberId, ?string $name = null, ?string $userId = null,
?float $weight = null, ?bool $activated = null, ?string $color = null
): array {
): array|null {
$dbMember = $this->memberMapper->getMemberById($projectId, $memberId);
if ($dbMember === null) {
return ['name' => $this->l10n->t('This project have no such member')];
Expand All @@ -1286,7 +1286,7 @@ public function editMember(
&& count($this->memberMapper->getBillIdsOfMember($memberId)) === 0
) {
$this->memberMapper->delete($dbMember);
return [];
return null;
}

if ($name !== null) {
Expand Down
140 changes: 42 additions & 98 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7640,58 +7640,30 @@
"description": "Member was successfully edited (and deleted if it was disabled and wasn't ower of any bill)",
"content": {
"application/json": {
"schema": [
{
"oneOf": [
{
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"nullable": true
}
}
}
}
},
{
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Member"
}
}
}
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Member",
"nullable": true
}
}
]
}
}
]
}
}
}
},
Expand Down Expand Up @@ -8216,58 +8188,30 @@
"description": "",
"content": {
"application/json": {
"schema": [
{
"oneOf": [
{
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"nullable": true
}
}
}
}
},
{
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Member"
}
}
}
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Member",
"nullable": true
}
}
]
}
}
]
}
}
}
},
Expand Down
Loading