Spatie laravel data rules inferring not working
Closed this issue · 2 comments
slnw commented
Scramble version: 0.11.9
Scramble pro: 0.6.2
should get the DataObject::rules(DataObject::empty()) to infer the properties
<?php
namespace App\Http\Resources;
use App\AgentTools;
use App\Data\AgentToolMetaData;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class AgentToolsResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'team_id' => $this->team_id,
'name' => $this->name,
/**
* @var AgentToolMetaData $meta
*/
'meta' => $this->meta,
];
}
}
<?php
namespace App\Data;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Validation\ValidationContext;
class AgentToolMetaData extends Data
{
public function __construct(
public array $properties,
)
{
}
public static function rules(ValidationContext $context): array
{
return [
'properties' => ['required', 'array'],
'properties.*.name' => ['required', 'string'],
'properties.*.type' => ['required', 'in', ['text', 'number', 'date', 'boolean', 'select']],
'properties.*.description' => ['string'],
'properties.*.example' => ['string'],
];
}
}
romalytvynenko commented
Gotcha! Working on it
romalytvynenko commented
@slnw this should be fixed now in dedoc/scramble-pro
v0.6.3
!
Feel free to re-open if you have any other questions!