What happened?
With config('data.wrap') set to 'data', we're seeing Laravel Data objects with nested arrays of Laravel Data objects that have data wrapping in schema, despite their responses not being wrapped. i.e.:
class ProductData extends Data
{
/**
* Initialize a new ProductData (plans) instance.
*
* @param array<int, PriceData> $prices The collection of prices associated with the product
*/
public function __construct(
public readonly array $prices,
) {
}
}
generates schema as:
"prices": {
"type": "object",
"properties": {
"data": {
"type": "array",
despite the response having prices not wrapped in 'data'.
The outer data wrapper (on ProductData as a whole) is expected.
How to reproduce the bug
Create a Laravel Data object that contains an array of Data Objects within it like my example above with ProductData and PriceData[].
Generate api.json with php artisan scramble:export
Observe schema that wraps PriceData[] in data, and observe responses that do not wrap PriceData[].
Package Version
Scramble PRO: 0.9.15, Scramble: 0.13.42
PHP Version
8.5.2
Laravel Version
13.26.1
Which operating systems does with happen with?
No response
Notes
We have attempted a few workarounds (using my example):
- Using
array<int, PriceData> and/or PriceData[] in the PHPDoc for the constructor of ProductData
- Using @var annotations:
/**
* @var PriceData[]
*/
public readonly array $prices,
- Using
#[DataCollectionOf(PriceData::class)]
- Combinations of the above attempts
What happened?
With
config('data.wrap')set to'data', we're seeing Laravel Data objects with nested arrays of Laravel Data objects that have data wrapping in schema, despite their responses not being wrapped. i.e.:generates schema as:
despite the response having
pricesnot wrapped in'data'.The outer data wrapper (on ProductData as a whole) is expected.
How to reproduce the bug
Create a Laravel Data object that contains an array of Data Objects within it like my example above with ProductData and PriceData[].
Generate api.json with
php artisan scramble:exportObserve schema that wraps PriceData[] in
data, and observe responses that do not wrap PriceData[].Package Version
Scramble PRO: 0.9.15, Scramble: 0.13.42
PHP Version
8.5.2
Laravel Version
13.26.1
Which operating systems does with happen with?
No response
Notes
We have attempted a few workarounds (using my example):
array<int, PriceData>and/orPriceData[]in the PHPDoc for the constructor of ProductData#[DataCollectionOf(PriceData::class)]