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

Improve request and response schemas #30

Merged
merged 3 commits into from
Apr 18, 2024
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
2 changes: 1 addition & 1 deletion src/Attributes/Request/CredentialsRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioApiBundle\Dto\Credentials;
use Pimcore\Bundle\StudioApiBundle\Request\Credentials;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class CredentialsRequestBody extends RequestBody
Expand Down
28 changes: 26 additions & 2 deletions src/Controller/Api/Assets/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OpenApi\Attributes\Get;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\ExcludeFoldersParameter;
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\IdSearchTermParameter;
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\PageParameter;
Expand All @@ -32,9 +33,16 @@
use Pimcore\Bundle\StudioApiBundle\Config\Tags;
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController;
use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Archive;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Audio;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Document;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Folder;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Image;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Text;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Unknown;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Video;
use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\AssetQuery;
Expand Down Expand Up @@ -81,7 +89,23 @@ public function __construct(
#[PathIncludeDescendantsParameter]
#[SuccessResponse(
description: 'Paginated assets with total count as header param',
content: new JsonContent(type: 'array', items: new Items(ref: Asset::class))
content: new JsonContent(
type: 'array',
items: new Items(
description: 'Asset or Image object',
anyOf: [
// TODO maybe find an easier way of describing this
new Schema(ref: Archive::class),
new Schema(ref: Audio::class),
new Schema(ref: Document::class),
new Schema(ref: Folder::class),
new Schema(ref: Image::class),
new Schema(ref: Text::class),
new Schema(ref: Unknown::class),
new Schema(ref: Video::class),
]
)
)
)]
#[UnauthorizedResponse]
public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/Assets/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\UnauthorizedResponse;
use Pimcore\Bundle\StudioApiBundle\Config\Tags;
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Bundle\StudioApiBundle\Response\Asset;
use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Api/Authorization/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\UnauthorizedResponse;
use Pimcore\Bundle\StudioApiBundle\Config\Tags;
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController;
use Pimcore\Bundle\StudioApiBundle\Dto\Credentials;
use Pimcore\Bundle\StudioApiBundle\Request\Credentials;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Refresh;
use Pimcore\Bundle\StudioApiBundle\Response\Schema\Token;
use Pimcore\Bundle\StudioApiBundle\Response\Token;
use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\TokenServiceInterface;
use Pimcore\Security\User\User;
Expand Down Expand Up @@ -86,13 +86,13 @@ public function login(#[MapRequestPayload] Credentials $credentials): JsonRespon
#[UnauthorizedResponse]
public function refresh(#[MapRequestPayload] Refresh $refresh): JsonResponse
{
$token = $this->tokenService->refreshToken($refresh->getToken());
$tokenInfo = $this->tokenService->refreshToken($refresh->getToken());

return $this->jsonResponse(
new Token(
$token->getToken(),
$tokenInfo->getToken(),
$this->tokenService->getLifetime(),
$token->getUsername())
$tokenInfo->getUsername())
);
}
}
2 changes: 1 addition & 1 deletion src/Controller/Api/DataObjects/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
use Pimcore\Bundle\StudioApiBundle\Config\Tags;
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController;
use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait;
use Pimcore\Bundle\StudioApiBundle\Dto\DataObject;
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParameters;
use Pimcore\Bundle\StudioApiBundle\Response\DataObject;
use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
Expand Down
152 changes: 0 additions & 152 deletions src/Dto/Element.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Dto/Credentials.php → src/Request/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Dto;
namespace Pimcore\Bundle\StudioApiBundle\Request;

use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
Expand Down
38 changes: 6 additions & 32 deletions src/Dto/Asset.php → src/Response/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Dto;
namespace Pimcore\Bundle\StudioApiBundle\Response;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Permissions;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Permissions;

#[Schema(
title: 'Asset',
Expand All @@ -46,27 +46,18 @@ public function __construct(
)]
private readonly array $metaData,
#[Property(description: 'Workflow permissions', type: 'bool', example: false)]
private readonly bool $workflowWithPermissions,
private readonly bool $hasWorkflowWithPermissions,
#[Property(description: 'Full path', type: 'string', example: '/path/to/asset.jpg')]
private readonly string $fullPath,
int $id,
#[Property(description: 'Parent ID', type: 'integer', example: 1)]
int $parentId,
#[Property(description: 'path', type: 'string', example: 'path/to/asset.jpg')]
string $path,
#[Property(description: 'owner', type: 'integer', example: 1)]
int $userOwner,
#[Property(description: 'User modification', type: 'integer', example: 1)]
int $userModification,
#[Property(description: 'Locked', type: 'string', example: 'locked')]
?string $locked,
#[Property(description: 'Is locked', type: 'bool', example: false)]
bool $isLocked,
#[Property(description: 'Creation date', type: 'integer', example: 1634025600)]
?int $creationDate,
#[Property(description: 'Modification date', type: 'integer', example: 1634025800)]
?int $modificationDate,
#[Property(ref: Permissions::class)]
Permissions $permissions
) {
parent::__construct(
Expand All @@ -88,14 +79,14 @@ public function getIconName(): string
return $this->iconName;
}

public function hasChildren(): bool
public function getHasChildren(): bool
{
return $this->hasChildren;
}

public function hasWorkflowWithPermissions(): bool
public function getHasWorkflowWithPermissions(): bool
{
return $this->workflowWithPermissions;
return $this->hasWorkflowWithPermissions;
}

public function getFilename(): ?string
Expand All @@ -108,11 +99,6 @@ public function getType(): string
return $this->type;
}

// public function getCustomSettings(): array
// {
// return $this->asset->getCustomSettings();
// }

public function getMimeType(): ?string
{
return $this->mimeType;
Expand All @@ -132,16 +118,4 @@ public function getFullPath(): string
{
return $this->fullPath;
}

// /**
// * @param User|null $user
// *
// * @return array
// *
// * @throws Exception
// */
// public function getUserPermissions(?User $user = null): array
// {
// return $this->permis;
// }
}
9 changes: 7 additions & 2 deletions src/Dto/Asset/Archive.php → src/Response/Asset/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Dto\Asset;
namespace Pimcore\Bundle\StudioApiBundle\Response\Asset;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioApiBundle\Response\Asset;

#[Schema(
title: 'Archive',
type: 'object'
)]
class Archive extends Asset
{
}
9 changes: 7 additions & 2 deletions src/Dto/Asset/Audio.php → src/Response/Asset/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Dto\Asset;
namespace Pimcore\Bundle\StudioApiBundle\Response\Asset;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioApiBundle\Response\Asset;

#[Schema(
title: 'Audio',
type: 'object'
)]
class Audio extends Asset
{
}
Loading
Loading