Skip to content

Commit

Permalink
Add AssetSchemasJson to describe response of get asset by id endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Apr 18, 2024
1 parent 05c5668 commit fd39629
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/Attributes/Response/Content/AssetSchemasJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Attributes\Response\Content;

use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Schema;
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;

/**
* @internal
*/
final class AssetSchemasJson extends JsonContent
{
public function __construct()
{
parent::__construct(
type: 'object',
oneOf: [
new Schema(ref: Image::class),
new Schema(ref: Document::class),
new Schema(ref: Audio::class),
new Schema(ref: Video::class),
new Schema(ref: Archive::class),
new Schema(ref: Text::class),
new Schema(ref: Folder::class),
new Schema(ref: Unknown::class),
],
);
}
}
1 change: 1 addition & 0 deletions src/Attributes/Response/Property/AssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioApiBundle\Provider\SchemaProvider;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Archive;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Audio;
use Pimcore\Bundle\StudioApiBundle\Response\Asset\Document;
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Api/Assets/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OpenApi\Attributes\Get;
use OpenApi\Attributes\JsonContent;
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\Content\AssetSchemasJson;
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\UnauthorizedResponse;
use Pimcore\Bundle\StudioApiBundle\Config\Tags;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(
#[IdParameter(type: 'asset')]
#[SuccessResponse(
description: 'Paginated assets with total count as header param',
content: new JsonContent(ref: Asset::class)
content: new AssetSchemasJson()
)]
#[UnauthorizedResponse]
public function getAssetById(int $id): JsonResponse
Expand Down

0 comments on commit fd39629

Please sign in to comment.