Skip to content

Commit

Permalink
Merge pull request #294 from provokateurin/fix/openapi/duplicate-stat…
Browse files Browse the repository at this point in the history
…us-codes

fix(OpenAPI): Fix duplicate status code definitions
  • Loading branch information
julien-nc authored Aug 18, 2024
2 parents b900cb6 + 31bd6c7 commit 45daae0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 123 deletions.
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

0 comments on commit 45daae0

Please sign in to comment.