Skip to content
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
28 changes: 20 additions & 8 deletions src/bundle/ApiPlatform/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,27 @@
/**
* @throws \JsonException
*/
private function insertIbexaResponseExample(Operation $operation): Operation

Check failure on line 176 in src/bundle/ApiPlatform/OpenApiFactory.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=ibexa_rest&issues=AaDToKpDplL5awmsvI4K&open=AaDToKpDplL5awmsvI4K&pullRequest=245
{
$newOperation = $operation;

foreach (($operation->getResponses() ?? []) as $responseCode => $response) {
if (!is_array($response) || !array_key_exists('content', $response)) {
if ($response instanceof Response) {
$content = $response->getContent()?->getArrayCopy();
} elseif (is_array($response) && array_key_exists('content', $response)) {
$content = $response['content'];
} else {
continue;
}

$newContent = $response['content'];
if ($content === null) {
continue;
}

$newContent = $content;

foreach ($newContent as $mediaType => $responseContent) {
if (!array_key_exists('x-ibexa-example-file', $responseContent)) {
if (!is_array($responseContent) || !array_key_exists('x-ibexa-example-file', $responseContent)) {
continue;
}

Expand All @@ -195,12 +203,16 @@
unset($newContent[$mediaType]['x-ibexa-example-file']);
}

if ($newContent !== $response['content']) {
$newOperation = $newOperation->withResponse(
$responseCode,
new Response($response['description'] ?? (string)$responseCode, new ArrayObject($newContent)),
);
if ($newContent === $content) {
continue;
}

$newOperation = $newOperation->withResponse(
$responseCode,
$response instanceof Response
? $response->withContent(new ArrayObject($newContent))
: new Response($response['description'] ?? (string)$responseCode, new ArrayObject($newContent)),
);
}

return $newOperation;
Expand Down
19 changes: 6 additions & 13 deletions src/lib/Server/Controller/Bookmark/BookmarkCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\LocationService;
Expand Down Expand Up @@ -50,21 +51,13 @@
],
requestBody: new Model\RequestBody(
description: 'No payload required',
content: new \ArrayObject(),
content: new ArrayObject(),
),
responses: [
Response::HTTP_CREATED => [
'description' => 'Created.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location does not exist.',
],
Response::HTTP_CONFLICT => [
'description' => 'Error - Location is already bookmarked.',
],
Response::HTTP_CREATED => new Model\Response(description: 'Created.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to given Location.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the given Location does not exist.'),
Response::HTTP_CONFLICT => new Model\Response(description: 'Error - Location is already bookmarked.'),
],
),
)]
Expand Down
12 changes: 3 additions & 9 deletions src/lib/Server/Controller/Bookmark/BookmarkDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@
),
],
responses: [
Response::HTTP_NO_CONTENT => [
'description' => 'Deleted - no content.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized for the given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location does not exist / is not bookmarked.',
],
Response::HTTP_NO_CONTENT => new Model\Response(description: 'Deleted - no content.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized for the given Location.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the given Location does not exist / is not bookmarked.'),
],
),
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@
),
],
responses: [
Response::HTTP_OK => [
'description' => 'OK - the given Location is bookmarked.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized for the given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location is not bookmarked or does not exist.',
],
Response::HTTP_OK => new Model\Response(description: 'OK - the given Location is bookmarked.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized for the given Location.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the given Location is not bookmarked or does not exist.'),
],
),
)]
Expand All @@ -70,15 +64,9 @@
),
],
responses: [
Response::HTTP_OK => [
'description' => 'OK - the given Location is bookmarked.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized for the given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location is not bookmarked or does not exist.',
],
Response::HTTP_OK => new Model\Response(description: 'OK - the given Location is bookmarked.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized for the given Location.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the given Location is not bookmarked or does not exist.'),
],
),
)]
Expand Down
15 changes: 7 additions & 8 deletions src/lib/Server/Controller/Bookmark/BookmarkListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Rest\Server\Controller as RestController;
Expand All @@ -30,9 +31,9 @@
'Bookmark',
],
responses: [
Response::HTTP_OK => [
'description' => 'If set, the list is returned in XML or JSON format.',
'content' => [
Response::HTTP_OK => new Model\Response(
description: 'If set, the list is returned in XML or JSON format.',
content: new ArrayObject([
'application/vnd.ibexa.api.BookmarkList+json' => [
'schema' => [
'$ref' => '#/components/schemas/BookmarkListWrapper',
Expand All @@ -45,11 +46,9 @@
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/bookmark/GET/BookmarkList.xml.example',
],
],
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to list bookmarks.',
],
]),
),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to list bookmarks.'),
],
),
)]
Expand Down
25 changes: 10 additions & 15 deletions src/lib/Server/Controller/Content/ContentCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException;
use Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException;
Expand Down Expand Up @@ -46,7 +47,7 @@
],
requestBody: new Model\RequestBody(
description: 'The ContentCreate schema encoded in XML or JSON format.',
content: new \ArrayObject([
content: new ArrayObject([
'application/vnd.ibexa.api.ContentCreate+json' => [
'schema' => [
'$ref' => '#/components/schemas/ContentCreateWrapper',
Expand All @@ -62,9 +63,9 @@
]),
),
responses: [
Response::HTTP_CREATED => [
'description' => 'Content - If set, all information for the content item including the embedded current version is returned in XML or JSON format. ContentInfo - If set, all information for the content item (excluding the current version) is returned in XML or JSON format.',
'content' => [
Response::HTTP_CREATED => new Model\Response(
description: 'Content - If set, all information for the content item including the embedded current version is returned in XML or JSON format. ContentInfo - If set, all information for the content item (excluding the current version) is returned in XML or JSON format.',
content: new ArrayObject([
'application/vnd.ibexa.api.Content+json' => [
'schema' => [
'$ref' => '#/components/schemas/ContentWrapper',
Expand All @@ -89,17 +90,11 @@
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/POST/ContentInfo.xml.example',
],
],
],
Response::HTTP_BAD_REQUEST => [
'description' => 'Error - the input does not match the input schema definition or the validation on a field fails.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to create this Object in this Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the parent Location specified in the request body does not exist.',
],
]),
),
Response::HTTP_BAD_REQUEST => new Model\Response(description: 'Error - the input does not match the input schema definition or the validation on a field fails.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to create this Object in this Location.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the parent Location specified in the request body does not exist.'),
],
),
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values\TemporaryRedirect;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -33,9 +34,9 @@
),
],
responses: [
Response::HTTP_OK => [
'description' => 'OK - returns the Version in XML or JSON format.',
'content' => [
Response::HTTP_OK => new Model\Response(
description: 'OK - returns the Version in XML or JSON format.',
content: new ArrayObject([
'application/vnd.ibexa.api.Version+json' => [
'schema' => [
'$ref' => '#/components/schemas/VersionWrapper',
Expand All @@ -48,14 +49,10 @@
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/currentversion/GET/Version.xml.example',
],
],
],
Response::HTTP_TEMPORARY_REDIRECT => [
'description' => 'Temporary redirect.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the resource does not exist.',
],
]),
),
Response::HTTP_TEMPORARY_REDIRECT => new Model\Response(description: 'Temporary redirect.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the resource does not exist.'),
],
),
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@
),
],
responses: [
Response::HTTP_TEMPORARY_REDIRECT => [
'description' => 'Temporary redirect.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to read this content item.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the content item was not found.',
],
Response::HTTP_TEMPORARY_REDIRECT => new Model\Response(description: 'Temporary redirect.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to read this content item.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the content item was not found.'),
],
),
)]
Expand Down
12 changes: 3 additions & 9 deletions src/lib/Server/Controller/Content/ContentDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@
),
],
responses: [
Response::HTTP_NO_CONTENT => [
'description' => 'The content item is deleted.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - content item was not found.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to delete this content item.',
],
Response::HTTP_NO_CONTENT => new Model\Response(description: 'The content item is deleted.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - content item was not found.'),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to delete this content item.'),
],
),
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
Expand Down Expand Up @@ -48,12 +49,12 @@
],
requestBody: new Model\RequestBody(
description: 'No payload required',
content: new \ArrayObject(),
content: new ArrayObject(),
),
responses: [
Response::HTTP_CREATED => [
'description' => 'Created',
'content' => [
Response::HTTP_CREATED => new Model\Response(
description: 'Created',
content: new ArrayObject([
'application/vnd.ibexa.api.Version+json' => [
'schema' => [
'$ref' => '#/components/schemas/VersionWrapper',
Expand All @@ -66,17 +67,11 @@
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/versions/version_no/GET/Version.xml.example',
],
],
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to update this content item.',
],
Response::HTTP_FORBIDDEN => [
'description' => 'Error - the current version is already a draft.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the content item was not found.',
],
]),
),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to update this content item.'),
Response::HTTP_FORBIDDEN => new Model\Response(description: 'Error - the current version is already a draft.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the content item was not found.'),
],
),
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use ArrayObject;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
Expand Down Expand Up @@ -54,12 +55,12 @@
],
requestBody: new Model\RequestBody(
description: 'No payload required',
content: new \ArrayObject(),
content: new ArrayObject(),
),
responses: [
Response::HTTP_CREATED => [
'description' => 'Created.',
'content' => [
Response::HTTP_CREATED => new Model\Response(
description: 'Created.',
content: new ArrayObject([
'application/vnd.ibexa.api.Version+json' => [
'schema' => [
'$ref' => '#/components/schemas/VersionWrapper',
Expand All @@ -72,14 +73,10 @@
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/versions/version_no/GET/Version.xml.example',
],
],
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to update this content item.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the content item was not found.',
],
]),
),
Response::HTTP_UNAUTHORIZED => new Model\Response(description: 'Error - the user is not authorized to update this content item.'),
Response::HTTP_NOT_FOUND => new Model\Response(description: 'Error - the content item was not found.'),
],
),
)]
Expand Down
Loading
Loading