You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document arguments of various clients via proper detailed type definitions #3309
changed the title [-]Document arguments of various clients via proper array shapes[/-][+]Document arguments of various clients via proper detailed type definitions[/+]on Jun 18, 2026
Thanks for raising this, @Ocramius, and sorry for the close call.
I understand the "jumping around web documentation" and find myself doing this often as a maintainer. The @method annotations were written when the SDK supported PHP 5.5, which is why they don't carry the kind of array shape info PHPStan or Psalm can use today. Luckily I think we're in a place now where we could do something about this.
On the "tags ignored" issue- this is one I'd love to address in V3, but changing this behavior would not be backward-compatible. Something to think about for the future though 🔮
If you, @MarcoStagno, and/or @albertomolinari can comment or add a reaction on #3017, that's where we're collecting feedback on future SDK direction/implementation and it'll help us prioritize.
I'll leave this open as the tracking item for the array shape annotation work. No timeline yet, but will update when I know more. The async-aws example is a useful reference point.
Luckily I think we're in a place now where we could do something about this.
Agreed 👍
On the "tags ignored" issue- this is one I'd love to address in V3, but changing this behavior would not be backward-compatible. Something to think about for the future though 🔮
I think we should stick to improving the generated docs: sealed array shapes suffice for this 👍
Thanks for the comment on #3017. We have wanted to make some major updates in those areas for years now, and there's been some momentum behind it lately. Stay tuned 🔮
For the docs improvement itself, I'm experimenting with a couple of approaches to get coverage in both IDEs and static analysis. Not sure we can have both because of magic@method limitations. I'll share more on this issue once I have something worth reviewing.
I've tried writing richer @method annotations and PHPStorm won't parse them- it doesn't seem the same format showed in your example above will work. What will work, however is keeping our existing @method annotations and adding an additional (psalm or) @phpstan-method annotation to document input. There doesn't appear to be autocomplete support in IDEs for this right now, but it's probably the best middle ground. Let me know what you think.
Very true, but it does seem like there are open feature requests to support autocomplete for these docblocks at least. Here is the current shape I'm working with:
I have to be mindful of artifact size here- The size increase of this shape (adding to each client method) on the current SDK is roughly 12mb. For now I think we should only document input shapes this way.
Since 3.395.0 (#3331) the clients carry exact argument shapes. Thanks, big improvement. One gap makes them unusable for DynamoDB.
The gap
DynamoDbClient::putItem() now expects Item?: array<string, array{S?: string, N?: string, ...}>, but the canonical way to produce that value is still annotated as a plain @return array:
// Aws\DynamoDb\Marshaler/** @return array Item formatted for DynamoDB. */publicfunction marshalItem($item)
PHPStan reads that as array<int|string, mixed>, which the new shape rejects:
$client->putItem([
'TableName' => $table,
'Item' => $marshaler->marshalItem(['pk' => 'a', 'n' => 1]),
]);
// 💡 Offset 'Item' does not accept type array<int|string, mixed>. [argument.type]
Hand-written shapes like ['Key' => ['pk' => ['S' => $id]]] pass fine. Only marshaled values fail, which is the path the DynamoDB docs point users to.
Suggested fix
Annotate the Marshaler with the shape the generator already emits:
Thanks for catching this, and sorry we missed the comment. You’re right- the new DynamoDB client annotations expose a gap in the existing Marshaler return types.
We should add an AttributeValue type alias and use it for the marshaling return types and unmarshaling inputs. I’ll follow up with a fix.
Activity
[-]Document arguments of various clients via proper array shapes[/-][+]Document arguments of various clients via proper detailed type definitions[/+]Ocramius commentedon Jun 18, 2026
An example of how
asyncawsgenerates such API doc:This is really good DX, and prevents the mistake that almost led to production system damage today...
stobrien89 commentedon Jun 20, 2026
Thanks for raising this, @Ocramius, and sorry for the close call.
I understand the "jumping around web documentation" and find myself doing this often as a maintainer. The
@methodannotations were written when the SDK supported PHP 5.5, which is why they don't carry the kind of array shape info PHPStan or Psalm can use today. Luckily I think we're in a place now where we could do something about this.On the "tags ignored" issue- this is one I'd love to address in V3, but changing this behavior would not be backward-compatible. Something to think about for the future though 🔮
If you, @MarcoStagno, and/or @albertomolinari can comment or add a reaction on #3017, that's where we're collecting feedback on future SDK direction/implementation and it'll help us prioritize.
I'll leave this open as the tracking item for the array shape annotation work. No timeline yet, but will update when I know more. The async-aws example is a useful reference point.
Ocramius commentedon Jun 20, 2026
Agreed 👍
I think we should stick to improving the generated docs: sealed array shapes suffice for this 👍
stobrien89 commentedon Jun 21, 2026
Thanks for the comment on #3017. We have wanted to make some major updates in those areas for years now, and there's been some momentum behind it lately. Stay tuned 🔮
For the docs improvement itself, I'm experimenting with a couple of approaches to get coverage in both IDEs and static analysis. Not sure we can have both because of magic
@methodlimitations. I'll share more on this issue once I have something worth reviewing.stobrien89 commentedon Jul 24, 2026
@Ocramius,
I've tried writing richer @method annotations and PHPStorm won't parse them- it doesn't seem the same format showed in your example above will work. What will work, however is keeping our existing @method annotations and adding an additional (psalm or) @phpstan-method annotation to document input. There doesn't appear to be autocomplete support in IDEs for this right now, but it's probably the best middle ground. Let me know what you think.
Ocramius commentedon Jul 24, 2026
Compared to what PHPStan/Psalm currently support, the IDE has always been lagging behind.
An attempt could be also done with:
stobrien89 commentedon Jul 25, 2026
Very true, but it does seem like there are open feature requests to support autocomplete for these docblocks at least. Here is the current shape I'm working with:
I have to be mindful of artifact size here- The size increase of this shape (adding to each client method) on the current SDK is roughly 12mb. For now I think we should only document input shapes this way.
Ocramius commentedon Jul 25, 2026
Having this is tremendous value for downstream: I wouldn't mind the size much
stobrien89 commentedon Jul 25, 2026
Opened #3331,
Would appreciate input from others who reacted @drupol, @johnnoel, @hskrasek, @andrew-demb
freddytqg commentedon Sep 17, 2026
Since 3.395.0 (#3331) the clients carry exact argument shapes. Thanks, big improvement. One gap makes them unusable for DynamoDB.
The gap
DynamoDbClient::putItem()now expectsItem?: array<string, array{S?: string, N?: string, ...}>, but the canonical way to produce that value is still annotated as a plain@return array:PHPStan reads that as
array<int|string, mixed>, which the new shape rejects:Hand-written shapes like
['Key' => ['pk' => ['S' => $id]]]pass fine. Only marshaled values fail, which is the path the DynamoDB docs point users to.Suggested fix
Annotate the
Marshalerwith the shape the generator already emits:unmarshalItem()/unmarshalValue()could take the same alias instead of barearray.SDK 3.395.3 · PHP 8.5 · PHPStan 2.2.14, level max
stobrien89 commentedon Oct 25, 2026
@freddytqg,
Thanks for catching this, and sorry we missed the comment. You’re right- the new DynamoDB client annotations expose a gap in the existing
Marshalerreturn types.We should add an
AttributeValuetype alias and use it for the marshaling return types and unmarshaling inputs. I’ll follow up with a fix.