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

Update to enable and fix tests. #580

Merged
merged 7 commits into from
Jan 16, 2025
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/Asset/Attribute/Request/CsvExportAssetRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct()
new Property(property: StepConfig::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: StepConfig::SETTINGS_HEADER->value,
type: 'enum',
type: 'string',
enum: StepConfig::values(),
example: StepConfig::SETTINGS_HEADER_TITLE->value
),
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Attribute/Request/CsvExportFolderRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct()
new Property(property: StepConfig::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: StepConfig::SETTINGS_HEADER->value,
type: 'enum',
type: 'string',
enum: StepConfig::values(),
example: StepConfig::SETTINGS_HEADER_TITLE->value
),
Expand Down
6 changes: 3 additions & 3 deletions src/Asset/Controller/Image/CustomDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function __construct(
#[MimeTypeParameter]
#[ResizeModeParameter]
#[ImageConfigParameter('width', 140)]
#[ImageConfigParameter('height')]
#[ImageConfigParameter('quality')]
#[ImageConfigParameter('dpi')]
#[ImageConfigParameter('height', 140)]
#[ImageConfigParameter('quality', 80)]
#[ImageConfigParameter('dpi', 300)]
#[SuccessResponse(
description: 'asset_image_download_custom_success_response',
content: [new MediaType('image/jpeg'), new MediaType('image/png')],
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Controller/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
#[PageSizeParameter]
#[ParentIdParameter(
description: 'Filter assets by parent id.',
example: null,
example: 1,
)]
#[IdSearchTermParameter]
#[ExcludeFoldersParameter]
Expand Down
8 changes: 4 additions & 4 deletions src/Asset/Controller/Video/ImageThumbnailStreamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function __construct(
)]
#[IdParameter(type: 'video')]
#[WidthParameter('Width of the video image thumbnail', 265)]
#[HeightParameter('Height of the video image thumbnail')]
#[AspectRatioParameter]
#[FrameParameter]
#[AsyncGenerationParameter]
#[HeightParameter('Height of the video image thumbnail', 265)]
#[AspectRatioParameter('Aspect ratio of the video image thumbnail', false)]
#[FrameParameter('Frame of the video image thumbnail', true)]
#[AsyncGenerationParameter(false)]
#[SuccessResponse(
description: 'asset_video_image_thumbnail_stream_success_response',
content: [new MediaType('image/*')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class ImageConfigParameter extends QueryParameter
{
public function __construct(string $name, mixed $defaultValue = null)
public function __construct(string $name, mixed $example = null)
{
parent::__construct(
name: $name,
description: ucfirst($name) . ' of downloaded image',
in: 'query',
schema: new Schema(type: 'integer', example: $defaultValue),
schema: new Schema(type: 'integer', example: $example),
);
}
}
3 changes: 1 addition & 2 deletions src/Asset/Schema/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#[Schema(
title: 'Asset',
required: [
'iconName',
'hasChildren',
'type',
'filename',
Expand All @@ -50,7 +49,7 @@ class Asset extends Element implements AdditionalAttributesInterface
use WorkflowAvailableTrait;

public function __construct(
#[Property(description: 'Has children', type: 'bool', example: false)]
#[Property(description: 'Has children', required: ['hasChildren'], type: 'bool', example: false)]
private readonly bool $hasChildren,
#[Property(description: 'Type', type: 'string', example: 'image')]
private readonly string $type,
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Schema/CustomSetting/FixedCustomSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
#[Property(
description: 'embedded meta data of the asset - array of any key-value pairs',
type: 'array',
items: new Items(),
items: new Items(type: 'object'),
example: '{ FileSize: "265 KiB", MIMEType: "image/jpeg" }'
)]
private array $embeddedMetadata = [],
Expand Down
4 changes: 2 additions & 2 deletions src/Asset/Schema/CustomSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(
#[Property(
description: 'dynamic custom settings - can be any key-value pair',
type: 'array',
items: new Items(),
example: '{ imageWidth: 1280, imageHeight: 720 }')
items: new Items(type: 'object'),
example: '[{ imageWidth: 1280 }, { imageHeight: 720 }]')
]
private readonly array $dynamicCustomSettings = [],
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Schema/Type/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Pimcore\Bundle\StudioBackendBundle\Response\ElementIcon;

#[Schema(
schema: 'Asset Document',
schema: 'AssetDocument',
title: 'Asset Document',
required: [
'pageCount',
Expand Down
2 changes: 1 addition & 1 deletion src/DataObject/Controller/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
#[PageSizeParameter]
#[ParentIdParameter(
description: 'Filter data objects by parent id.',
example: null
example: 1
)]
#[IdSearchTermParameter]
#[ExcludeFoldersParameter]
Expand Down
2 changes: 1 addition & 1 deletion src/DataObject/Schema/DataObjectAddParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
private string $classId,
#[Property(
description: 'Type',
type: 'enum',
type: 'string',
enum: [AbstractObject::OBJECT_TYPE_OBJECT, AbstractObject::OBJECT_TYPE_VARIANT],
example: AbstractObject::OBJECT_TYPE_OBJECT
)]
Expand Down
2 changes: 1 addition & 1 deletion src/DataObject/Schema/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
private readonly ?string $bodyStyle = null,
#[Property(description: 'Locked', type: 'bool', example: false)]
private readonly bool $locked = false,
#[Property(description: 'Children', type: 'array', items: new Items(), example: '[]')]
#[Property(description: 'Children', type: 'array', items: new Items(type: 'object'), example: '[{id: 1}]')]
private readonly array $children = [],
#[Property(description: 'Icon', type: ElementIcon::class)]
private readonly ?ElementIcon $icon = null,
Expand Down
22 changes: 22 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$this->addNoteTypes($rootNode);
$this->addDataObjectAdapterMapping($rootNode);
$this->addUserNode($rootNode);
$this->addServerNode($rootNode);

return $treeBuilder;
}
Expand Down Expand Up @@ -305,4 +306,25 @@ private function addUserNode(ArrayNodeDefinition $node): void
->end()
->end();
}

private function addServerNode(ArrayNodeDefinition $node): void
{
$node
->children()
->arrayNode('open_api_servers')
->arrayPrototype() // Allows multiple server entries
->children()
->scalarNode('url')
->isRequired() // Ensure each server has a URL
->info('The URL to the server.')
->end()
->scalarNode('description')
->isRequired() // Ensure each server has a description
->info('A description of the server.')
->end()
->end()
->end()
->end()
->end();
}
}
23 changes: 22 additions & 1 deletion src/DependencyInjection/PimcoreStudioBackendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Element\Service\ElementDeleteServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\EventSubscriber\CorsSubscriber;
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidHostException;
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidPathException;
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidUrlPrefixException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\ConfigurationServiceInterface;
Expand Down Expand Up @@ -70,13 +71,15 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load(basename($file));
}

$this->checkValidOpenApiScanPaths($config['open_api_scan_paths']);
$this->checkValidUrlPrefix($config['url_prefix']);
$this->checkValidOpenApiScanPaths($config['open_api_scan_paths']);
$this->checkValidServers($config['open_api_servers']);

$definition = $container->getDefinition(OpenApiServiceInterface::class);
$definition->setArguments([
'$routePrefix' => $config['url_prefix'],
'$openApiScanPaths' => $config['open_api_scan_paths'],
'$openApiServers' => $config['open_api_servers'],
]);

$definition = $container->getDefinition(CorsSubscriber::class);
Expand Down Expand Up @@ -158,6 +161,24 @@ private function checkValidOpenApiScanPaths(array $config): void
}
}

/**
* @throws InvalidHostException
*/
private function checkValidServers(array $servers): void
{
if (empty($servers)) {
return;
}

foreach ($servers as $serverUrl) {
if (!filter_var($serverUrl['url'], FILTER_VALIDATE_URL)) {
throw new InvalidHostException(
sprintf('The server URL "%s" is not a valid URL.', $serverUrl)
);
}
}
}

/**
* @throws InvalidUrlPrefixException
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Document/Schema/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#[Schema(
schema: 'Document',
title: 'Document',
required: [
],
required: ['id'],
type: 'object'
)]
final class Document extends Element implements AdditionalAttributesInterface
Expand Down
3 changes: 2 additions & 1 deletion src/Email/Controller/Blocklist/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function __construct(
#[TextFieldParameter(
name: 'email',
description: 'Email address to be filtered by',
required: false
required: false,
example: '[email protected]'
)]
#[SuccessResponse(
description: 'email_blocklist_get_collection_success_response',
Expand Down
3 changes: 2 additions & 1 deletion src/Email/Controller/Blocklist/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function __construct(
#[TextFieldParameter(
name: 'email',
description: ' Email address to be deleted from blocklist',
required: false
required: false,
example: '[email protected]'
)]
#[SuccessResponse(
description: 'email_blocklist_delete_success_response',
Expand Down
7 changes: 6 additions & 1 deletion src/Email/Schema/EmailDocumentParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
public function __construct(
#[Property(description: 'parameter key', type: 'string', example: 'some_parameter_key')]
private string $key,
#[Property(description: 'parameter value', type: 'value', example: 'some_parameter_value')]
#[Property(description: 'parameter value', example: 'some_parameter_value', anyOf: [
new Schema(type: 'string'),
new Schema(type: 'number'),
new Schema(type: 'boolean'),
new Schema(type: 'object'),
])]
private mixed $value,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Email/Schema/SendEmailParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
private string $subject,
#[Property(
description: 'email content type',
type: 'enum',
type: 'string',
enum: [
EmailContentType::DOCUMENT->value,
EmailContentType::HTML->value,
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionEngine/Controller/AbortController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
#[Route('/execution-engine/abort/{jobRunId}', name: 'pimcore_studio_api_execution_engine_abort', methods: ['POST'])]
#[IsGranted(UserPermissions::ASSETS->value)]
#[Post(
path: self::PREFIX . '/execution-engine/abort/{JobRunId}',
path: self::PREFIX . '/execution-engine/abort/{jobRunId}',
operationId: 'execution_engine_abort_job_run_by_id',
description: 'execution_engine_abort_job_run_by_id_description',
summary: 'execution_engine_abort_job_run_by_id_summary',
Expand Down
8 changes: 7 additions & 1 deletion src/Mercure/Schema/ExecutionEngine/Finished.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Mercure\Schema\ExecutionEngine;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\GenericExecutionEngineBundle\Model\JobRunStates;
Expand Down Expand Up @@ -46,7 +47,12 @@ public function __construct(
private int $ownerId,
#[Property(description: 'status', type: 'string', example: JobRunStates::FINISHED->value)]
private string $status,
#[Property(description: 'messages', type: 'list', example: ['Something went wrong'])]
#[Property(
description: 'messages',
type: 'array',
items: new Items(type: 'string'),
example: ['Something went wrong']
)]
private array $messages = [],
#[Property(description: 'notifyAll', type: 'boolean', example: false)]
private bool $notifyAll = false,
Expand Down
2 changes: 1 addition & 1 deletion src/Note/Attribute/Parameter/Query/NoteSortByParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum: [
'description',
'locked',
],
example: null,
example: 'id',
),
);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Note/Schema/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ public function __construct(
#[Property(
description: 'Data of note',
type: 'array',
items: new Items(),
items: new Items(
anyOf: [
new Schema(type: 'string'),
new Schema(type: 'number'),
new Schema(type: 'boolean'),
new Schema(type: 'object'),
]
),
example: 'Can be pretty much anything',
)]
private readonly array $data,
Expand Down
2 changes: 1 addition & 1 deletion src/Notification/Schema/SendNotificationParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
private string $message,
#[Property(
description: 'type of the attachment',
type: 'enum',
type: 'string',
enum: [
ElementTypes::TYPE_ASSET,
ElementTypes::TYPE_DOCUMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
description: 'Filter folders from result.',
in: 'query',
required: false,
schema: new Schema(type: 'boolean', example: null),
schema: new Schema(type: 'boolean', example: false),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Attribute;
use OpenApi\Attributes\QueryParameter as OpenApiQueryParameter;
use OpenApi\Attributes\Schema;

#[Attribute(Attribute::TARGET_METHOD)]
final class FieldFilterParameter extends OpenApiQueryParameter
Expand All @@ -30,7 +31,7 @@ public function __construct()
[{"operator":"like","value":"John","field":"name","type":"string"}]',
in: 'query',
required: false,
example: ''
schema: new Schema(type: 'string', example: '[{"operator":"like","value":"John","field":"name"}]'),
);
}
}
2 changes: 1 addition & 1 deletion src/OpenApi/Attribute/Parameter/Query/FilterParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(string $filterFor = 'properties')
description: 'Filter for ' . $filterFor,
in: 'query',
required: false,
schema: new Schema(type: 'string', example: null),
schema: new Schema(type: 'string', example: $filterFor),
);
}
}
2 changes: 1 addition & 1 deletion src/OpenApi/Attribute/Parameter/Query/IdParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
description: $description,
in: 'query',
required: $required,
schema: new Schema(type: 'integer', example: null),
schema: new Schema(type: 'integer', example: 83),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
description: 'Filter assets/data-objects by matching ids. As a wildcard * can be used',
in: 'query',
required: false,
schema: new Schema(type: 'string', example: null),
schema: new Schema(type: 'string', example: 83),
);
}
}
Loading
Loading