v0.12.12
This is a relatively small release, but brings support for long awaited array's in request root and some inference improvements.
Support for arrays in request body root
Now it it possible to provide validation rules for arrays as request body root:
$request->validate([
'*.foo' => ['required', 'string'],
'*.bar' => ['required', 'string'],
]);Scramble will correctly recognize that request body is an array of objects with foo and bar properties.
Type inference improvements
Now Scramble will be able to infer types originating from typed property calls. This allows you to have a correct documentation for method calls on services you inject into your controller.
// CompanyController.php
<?php
namespace App\Http\Controllers\Api;
use App\CompanyDataFactory;
use App\Http\Controllers\Controller;
use App\Models\Company;
class CompanyController extends Controller
{
public function __construct(
private readonly CompanyDataFactory $companyDataFactory,
) {}
/**
* Get company.
*/
public function show(Company $company)
{
return $this->companyDataFactory->createTerseCompanyData($company);
}
}
// CompanyDataFactory.php
<?php
namespace App;
use App\Data\CompanyData;
class CompanyDataFactory
{
public function createTerseCompanyData($model): CompanyData
{
return CompanyData::from($model)->only('id');
}
}Scramble will correctly document the response from show controller's method 🔥
What's Changed
- Fixed documenting validation rules when it is a root array of objects by @romalytvynenko in #766
- Type inference improvements: preserving keyed arrays attributes, inference on typed class properties by @romalytvynenko in #769
Full Changelog: v0.12.11...v0.12.12