The 'items' field for Array property's isn't populated by the DocBlock
The following constructor:
/**
* @param DateTimeImmutable[] $times
* @param string[] $alerts
*/
public function __construct(
#[OA\Property]
public readonly array $times,
#[OA\Property]
public readonly array $alerts,
)
Will throw the error: @OA\Items() is required when @OA\Property() has type "array"
The fix is to manually populate the info, this works:
/**
* @param DateTimeImmutable[] $times
* @param string[] $alerts
*/
public function __construct(
#[OA\Property(items: new OA\Items(ref: "#/components/schemas/DateTimeImmutable", type: "object"))]
public readonly array $times,
#[OA\Property(items: new OA\Items(type: "string"))]
public readonly array $alerts,
)
Is this a bug? Should the generator automatically populate the items info from the DocBlock generics?
Not sure if it's a bug, but it could be better, agreed. I'll make sure to add their to the ongoing type detection revamp.
Yeah I also think that will be more cleaner way to do it, if we can do like below,
#[Property()]
public array SchemaLineChartsResource $market;
Currently below is the working example
#[Property(items: new Items(ref: SchemaLineChartsResource::class))]
public array $market;
public array SchemaLineChartsResource $market;
That doesn't look like a valid PHP typehint to me, though?
Yeah, you are right, but was looking for more cleaner way, wondering if we can do it.
Could be done, but the type system overhaul is going very slow (sorry). The only way to add those typehints would be phpdoc, I suppose:
/** @var array<SchemaLineChartsResource> $market */
public array $market;
Just to keep things linked, I have a really similar issue generating documentation for api-platform/core:3.2.*:
- https://github.com/api-platform/core/issues/6194
As this issue didn't appear when searching the error on Google, I'm going to add the full detailed error here:
User Warning: @OA\Items() parent type must be "array" in