<?php
declare(strict_types=1);
namespace App\Attributes;
use AllowDynamicProperties;
use App\Responses\Dto;
use App\Services\ResponseService;
use Attribute;
use Illuminate\Support\Str;
use Knuckles\Scribe\Attributes\Response as ResponseAttribute;
#[AllowDynamicProperties]
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class OpenApiResponse extends ResponseAttribute
{
public function __construct(
/** @var Dto $dto */
public ?string $dto,
public ?string $event = 'ok',
public int $status = 200,
) {
/*_*/
}
public function toArray(): array
{
return [
'status' => $this->status,
'content' => ResponseService::array($this->dto::example($this->event, $this->dto)),
'description' => Str::headline($this->event),
];
}
}