From 68bf3940bc348edf2c817c23d9eafc0dcc8af038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imants=20Liepi=C5=86=C5=A1?= Date: Fri, 15 Nov 2024 17:07:02 +0200 Subject: [PATCH 1/2] improve storage item resource openapi doc generation --- src/Api/Resource/StorageItemResource.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Api/Resource/StorageItemResource.php b/src/Api/Resource/StorageItemResource.php index f462fa8..89d1045 100644 --- a/src/Api/Resource/StorageItemResource.php +++ b/src/Api/Resource/StorageItemResource.php @@ -79,11 +79,15 @@ class StorageItemResource extends BaseResource public const PREFIX = 'storage_item:'; - #[ApiProperty(identifier: true)] + #[ApiProperty( + required: true, + identifier: true, + openapiContext: ['type' => 'integer'], + )] #[Groups([self::ITEM, self::READ, ])] public mixed $id = null; - #[ApiProperty(types: ['https://schema.org/contentUrl', ])] + #[ApiProperty(required: true, types: ['https://schema.org/contentUrl', ])] #[Groups([self::ITEM, self::READ, ])] public ?string $contentUrl = null; @@ -100,6 +104,7 @@ class StorageItemResource extends BaseResource public ?File $file = null; #[Groups([self::ITEM, self::READ, ])] + #[ApiProperty(required: true, schema: ['type' => 'string'])] public ?string $filePath = null; #[Groups([self::ITEM, self::READ, ])] @@ -118,14 +123,19 @@ class StorageItemResource extends BaseResource public ?string $title = null; #[Groups([self::ITEM, self::READ, ])] + #[Assert\NotBlank(groups: [self::READ, ])] + #[ApiProperty(required: true, schema: ['type' => 'string'])] public ?DateTimeImmutable $createdAt = null; #[Groups([self::ITEM, self::READ, ])] + #[Assert\NotBlank(groups: [self::READ, ])] + #[ApiProperty(required: true, schema: ['type' => 'string'])] public ?DateTimeImmutable $updatedAt = null; #[Groups([self::ITEM, self::READ, ])] public ?bool $isImage = null; #[Groups([self::ITEM, self::WRITE, self::PATCH, self::READ, ])] + #[ApiProperty(openapiContext: ['type' => 'object', 'additionalProperties' => true])] public ?array $data = null; } From 42426ac9f20c7830874ef2b5688e30413dfaf839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imants=20Liepi=C5=86=C5=A1?= Date: Fri, 15 Nov 2024 17:27:43 +0200 Subject: [PATCH 2/2] remove unnecessary asserts --- src/Api/Resource/StorageItemResource.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Api/Resource/StorageItemResource.php b/src/Api/Resource/StorageItemResource.php index 89d1045..00c642b 100644 --- a/src/Api/Resource/StorageItemResource.php +++ b/src/Api/Resource/StorageItemResource.php @@ -87,7 +87,11 @@ class StorageItemResource extends BaseResource #[Groups([self::ITEM, self::READ, ])] public mixed $id = null; - #[ApiProperty(required: true, types: ['https://schema.org/contentUrl', ])] + #[ApiProperty( + required: true, + types: ['https://schema.org/contentUrl', ], + schema: ['type' => 'string'], + )] #[Groups([self::ITEM, self::READ, ])] public ?string $contentUrl = null; @@ -123,12 +127,10 @@ class StorageItemResource extends BaseResource public ?string $title = null; #[Groups([self::ITEM, self::READ, ])] - #[Assert\NotBlank(groups: [self::READ, ])] #[ApiProperty(required: true, schema: ['type' => 'string'])] public ?DateTimeImmutable $createdAt = null; #[Groups([self::ITEM, self::READ, ])] - #[Assert\NotBlank(groups: [self::READ, ])] #[ApiProperty(required: true, schema: ['type' => 'string'])] public ?DateTimeImmutable $updatedAt = null;