Skip to content

Commit 57495b8

Browse files
authored
Differentiate empty list to not set list (#668)
1 parent 24bc787 commit 57495b8

30 files changed

+467
-333
lines changed

src/Input/BatchGetItemInput.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class BatchGetItemInput extends Input
1717
*
1818
* @required
1919
*
20-
* @var array<string, KeysAndAttributes>
20+
* @var array<string, KeysAndAttributes>|null
2121
*/
2222
private $RequestItems;
2323

@@ -53,7 +53,7 @@ public static function create($input): self
5353
*/
5454
public function getRequestItems(): array
5555
{
56-
return $this->RequestItems;
56+
return $this->RequestItems ?? [];
5757
}
5858

5959
/**
@@ -112,8 +112,11 @@ public function setReturnConsumedCapacity(?string $value): self
112112
private function requestBody(): array
113113
{
114114
$payload = [];
115+
if (null === $v = $this->RequestItems) {
116+
throw new InvalidArgument(sprintf('Missing parameter "RequestItems" for "%s". The value cannot be null.', __CLASS__));
117+
}
115118

116-
foreach ($this->RequestItems as $name => $v) {
119+
foreach ($v as $name => $v) {
117120
$payload['RequestItems'][$name] = $v->requestBody();
118121
}
119122
if (null !== $v = $this->ReturnConsumedCapacity) {

src/Input/BatchWriteItemInput.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class BatchWriteItemInput extends Input
1818
*
1919
* @required
2020
*
21-
* @var array<string, array>
21+
* @var array<string, array>|null
2222
*/
2323
private $RequestItems;
2424

@@ -65,7 +65,7 @@ public static function create($input): self
6565
*/
6666
public function getRequestItems(): array
6767
{
68-
return $this->RequestItems;
68+
return $this->RequestItems ?? [];
6969
}
7070

7171
/**
@@ -142,9 +142,13 @@ public function setReturnItemCollectionMetrics(?string $value): self
142142
private function requestBody(): array
143143
{
144144
$payload = [];
145+
if (null === $v = $this->RequestItems) {
146+
throw new InvalidArgument(sprintf('Missing parameter "RequestItems" for "%s". The value cannot be null.', __CLASS__));
147+
}
145148

146-
foreach ($this->RequestItems as $name => $v) {
149+
foreach ($v as $name => $v) {
147150
$index = -1;
151+
$payload['RequestItems'][$name] = [];
148152
foreach ($v as $listValue) {
149153
++$index;
150154
$payload['RequestItems'][$name][$index] = $listValue->requestBody();

src/Input/CreateTableInput.php

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class CreateTableInput extends Input
2323
*
2424
* @required
2525
*
26-
* @var AttributeDefinition[]
26+
* @var AttributeDefinition[]|null
2727
*/
2828
private $AttributeDefinitions;
2929

@@ -44,7 +44,7 @@ final class CreateTableInput extends Input
4444
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html
4545
* @required
4646
*
47-
* @var KeySchemaElement[]
47+
* @var KeySchemaElement[]|null
4848
*/
4949
private $KeySchema;
5050

@@ -53,15 +53,15 @@ final class CreateTableInput extends Input
5353
* partition key value. There is a 10 GB size limit per partition key value; otherwise, the size of a local secondary
5454
* index is unconstrained.
5555
*
56-
* @var LocalSecondaryIndex[]
56+
* @var LocalSecondaryIndex[]|null
5757
*/
5858
private $LocalSecondaryIndexes;
5959

6060
/**
6161
* One or more global secondary indexes (the maximum is 20) to be created on the table. Each global secondary index in
6262
* the array includes the following:.
6363
*
64-
* @var GlobalSecondaryIndex[]
64+
* @var GlobalSecondaryIndex[]|null
6565
*/
6666
private $GlobalSecondaryIndexes;
6767

@@ -100,7 +100,7 @@ final class CreateTableInput extends Input
100100
*
101101
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tagging.html
102102
*
103-
* @var Tag[]
103+
* @var Tag[]|null
104104
*/
105105
private $Tags;
106106

@@ -121,16 +121,16 @@ final class CreateTableInput extends Input
121121
*/
122122
public function __construct(array $input = [])
123123
{
124-
$this->AttributeDefinitions = array_map([AttributeDefinition::class, 'create'], $input['AttributeDefinitions'] ?? []);
124+
$this->AttributeDefinitions = isset($input['AttributeDefinitions']) ? array_map([AttributeDefinition::class, 'create'], $input['AttributeDefinitions']) : null;
125125
$this->TableName = $input['TableName'] ?? null;
126-
$this->KeySchema = array_map([KeySchemaElement::class, 'create'], $input['KeySchema'] ?? []);
127-
$this->LocalSecondaryIndexes = array_map([LocalSecondaryIndex::class, 'create'], $input['LocalSecondaryIndexes'] ?? []);
128-
$this->GlobalSecondaryIndexes = array_map([GlobalSecondaryIndex::class, 'create'], $input['GlobalSecondaryIndexes'] ?? []);
126+
$this->KeySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : null;
127+
$this->LocalSecondaryIndexes = isset($input['LocalSecondaryIndexes']) ? array_map([LocalSecondaryIndex::class, 'create'], $input['LocalSecondaryIndexes']) : null;
128+
$this->GlobalSecondaryIndexes = isset($input['GlobalSecondaryIndexes']) ? array_map([GlobalSecondaryIndex::class, 'create'], $input['GlobalSecondaryIndexes']) : null;
129129
$this->BillingMode = $input['BillingMode'] ?? null;
130130
$this->ProvisionedThroughput = isset($input['ProvisionedThroughput']) ? ProvisionedThroughput::create($input['ProvisionedThroughput']) : null;
131131
$this->StreamSpecification = isset($input['StreamSpecification']) ? StreamSpecification::create($input['StreamSpecification']) : null;
132132
$this->SSESpecification = isset($input['SSESpecification']) ? SSESpecification::create($input['SSESpecification']) : null;
133-
$this->Tags = array_map([Tag::class, 'create'], $input['Tags'] ?? []);
133+
$this->Tags = isset($input['Tags']) ? array_map([Tag::class, 'create'], $input['Tags']) : null;
134134
parent::__construct($input);
135135
}
136136

@@ -144,7 +144,7 @@ public static function create($input): self
144144
*/
145145
public function getAttributeDefinitions(): array
146146
{
147-
return $this->AttributeDefinitions;
147+
return $this->AttributeDefinitions ?? [];
148148
}
149149

150150
/**
@@ -160,23 +160,23 @@ public function getBillingMode(): ?string
160160
*/
161161
public function getGlobalSecondaryIndexes(): array
162162
{
163-
return $this->GlobalSecondaryIndexes;
163+
return $this->GlobalSecondaryIndexes ?? [];
164164
}
165165

166166
/**
167167
* @return KeySchemaElement[]
168168
*/
169169
public function getKeySchema(): array
170170
{
171-
return $this->KeySchema;
171+
return $this->KeySchema ?? [];
172172
}
173173

174174
/**
175175
* @return LocalSecondaryIndex[]
176176
*/
177177
public function getLocalSecondaryIndexes(): array
178178
{
179-
return $this->LocalSecondaryIndexes;
179+
return $this->LocalSecondaryIndexes ?? [];
180180
}
181181

182182
public function getProvisionedThroughput(): ?ProvisionedThroughput
@@ -204,7 +204,7 @@ public function getTableName(): ?string
204204
*/
205205
public function getTags(): array
206206
{
207-
return $this->Tags;
207+
return $this->Tags ?? [];
208208
}
209209

210210
/**
@@ -323,9 +323,13 @@ public function setTags(array $value): self
323323
private function requestBody(): array
324324
{
325325
$payload = [];
326+
if (null === $v = $this->AttributeDefinitions) {
327+
throw new InvalidArgument(sprintf('Missing parameter "AttributeDefinitions" for "%s". The value cannot be null.', __CLASS__));
328+
}
326329

327330
$index = -1;
328-
foreach ($this->AttributeDefinitions as $listValue) {
331+
$payload['AttributeDefinitions'] = [];
332+
foreach ($v as $listValue) {
329333
++$index;
330334
$payload['AttributeDefinitions'][$index] = $listValue->requestBody();
331335
}
@@ -334,25 +338,33 @@ private function requestBody(): array
334338
throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__));
335339
}
336340
$payload['TableName'] = $v;
341+
if (null === $v = $this->KeySchema) {
342+
throw new InvalidArgument(sprintf('Missing parameter "KeySchema" for "%s". The value cannot be null.', __CLASS__));
343+
}
337344

338345
$index = -1;
339-
foreach ($this->KeySchema as $listValue) {
346+
$payload['KeySchema'] = [];
347+
foreach ($v as $listValue) {
340348
++$index;
341349
$payload['KeySchema'][$index] = $listValue->requestBody();
342350
}
343351

344-
$index = -1;
345-
foreach ($this->LocalSecondaryIndexes as $listValue) {
346-
++$index;
347-
$payload['LocalSecondaryIndexes'][$index] = $listValue->requestBody();
352+
if (null !== $v = $this->LocalSecondaryIndexes) {
353+
$index = -1;
354+
$payload['LocalSecondaryIndexes'] = [];
355+
foreach ($v as $listValue) {
356+
++$index;
357+
$payload['LocalSecondaryIndexes'][$index] = $listValue->requestBody();
358+
}
348359
}
349-
350-
$index = -1;
351-
foreach ($this->GlobalSecondaryIndexes as $listValue) {
352-
++$index;
353-
$payload['GlobalSecondaryIndexes'][$index] = $listValue->requestBody();
360+
if (null !== $v = $this->GlobalSecondaryIndexes) {
361+
$index = -1;
362+
$payload['GlobalSecondaryIndexes'] = [];
363+
foreach ($v as $listValue) {
364+
++$index;
365+
$payload['GlobalSecondaryIndexes'][$index] = $listValue->requestBody();
366+
}
354367
}
355-
356368
if (null !== $v = $this->BillingMode) {
357369
if (!BillingMode::exists($v)) {
358370
throw new InvalidArgument(sprintf('Invalid parameter "BillingMode" for "%s". The value "%s" is not a valid "BillingMode".', __CLASS__, $v));
@@ -368,11 +380,13 @@ private function requestBody(): array
368380
if (null !== $v = $this->SSESpecification) {
369381
$payload['SSESpecification'] = $v->requestBody();
370382
}
371-
372-
$index = -1;
373-
foreach ($this->Tags as $listValue) {
374-
++$index;
375-
$payload['Tags'][$index] = $listValue->requestBody();
383+
if (null !== $v = $this->Tags) {
384+
$index = -1;
385+
$payload['Tags'] = [];
386+
foreach ($v as $listValue) {
387+
++$index;
388+
$payload['Tags'][$index] = $listValue->requestBody();
389+
}
376390
}
377391

378392
return $payload;

src/Input/DeleteItemInput.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class DeleteItemInput extends Input
2929
*
3030
* @required
3131
*
32-
* @var array<string, AttributeValue>
32+
* @var array<string, AttributeValue>|null
3333
*/
3434
private $Key;
3535

@@ -39,7 +39,7 @@ final class DeleteItemInput extends Input
3939
*
4040
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html
4141
*
42-
* @var array<string, ExpectedAttributeValue>
42+
* @var array<string, ExpectedAttributeValue>|null
4343
*/
4444
private $Expected;
4545

@@ -86,14 +86,14 @@ final class DeleteItemInput extends Input
8686
* One or more substitution tokens for attribute names in an expression. The following are some use cases for using
8787
* `ExpressionAttributeNames`:.
8888
*
89-
* @var array<string, string>
89+
* @var array<string, string>|null
9090
*/
9191
private $ExpressionAttributeNames;
9292

9393
/**
9494
* One or more values that can be substituted in an expression.
9595
*
96-
* @var array<string, AttributeValue>
96+
* @var array<string, AttributeValue>|null
9797
*/
9898
private $ExpressionAttributeValues;
9999

@@ -130,7 +130,7 @@ public function __construct(array $input = [])
130130
$this->ReturnConsumedCapacity = $input['ReturnConsumedCapacity'] ?? null;
131131
$this->ReturnItemCollectionMetrics = $input['ReturnItemCollectionMetrics'] ?? null;
132132
$this->ConditionExpression = $input['ConditionExpression'] ?? null;
133-
$this->ExpressionAttributeNames = $input['ExpressionAttributeNames'] ?? [];
133+
$this->ExpressionAttributeNames = $input['ExpressionAttributeNames'] ?? null;
134134

135135
$this->ExpressionAttributeValues = [];
136136
foreach ($input['ExpressionAttributeValues'] ?? [] as $key => $item) {
@@ -162,31 +162,31 @@ public function getConditionalOperator(): ?string
162162
*/
163163
public function getExpected(): array
164164
{
165-
return $this->Expected;
165+
return $this->Expected ?? [];
166166
}
167167

168168
/**
169169
* @return array<string, string>
170170
*/
171171
public function getExpressionAttributeNames(): array
172172
{
173-
return $this->ExpressionAttributeNames;
173+
return $this->ExpressionAttributeNames ?? [];
174174
}
175175

176176
/**
177177
* @return array<string, AttributeValue>
178178
*/
179179
public function getExpressionAttributeValues(): array
180180
{
181-
return $this->ExpressionAttributeValues;
181+
return $this->ExpressionAttributeValues ?? [];
182182
}
183183

184184
/**
185185
* @return array<string, AttributeValue>
186186
*/
187187
public function getKey(): array
188188
{
189-
return $this->Key;
189+
return $this->Key ?? [];
190190
}
191191

192192
/**
@@ -344,13 +344,17 @@ private function requestBody(): array
344344
throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__));
345345
}
346346
$payload['TableName'] = $v;
347+
if (null === $v = $this->Key) {
348+
throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__));
349+
}
347350

348-
foreach ($this->Key as $name => $v) {
351+
foreach ($v as $name => $v) {
349352
$payload['Key'][$name] = $v->requestBody();
350353
}
351-
352-
foreach ($this->Expected as $name => $v) {
353-
$payload['Expected'][$name] = $v->requestBody();
354+
if (null !== $v = $this->Expected) {
355+
foreach ($v as $name => $v) {
356+
$payload['Expected'][$name] = $v->requestBody();
357+
}
354358
}
355359
if (null !== $v = $this->ConditionalOperator) {
356360
if (!ConditionalOperator::exists($v)) {
@@ -379,13 +383,15 @@ private function requestBody(): array
379383
if (null !== $v = $this->ConditionExpression) {
380384
$payload['ConditionExpression'] = $v;
381385
}
382-
383-
foreach ($this->ExpressionAttributeNames as $name => $v) {
384-
$payload['ExpressionAttributeNames'][$name] = $v;
386+
if (null !== $v = $this->ExpressionAttributeNames) {
387+
foreach ($v as $name => $v) {
388+
$payload['ExpressionAttributeNames'][$name] = $v;
389+
}
385390
}
386-
387-
foreach ($this->ExpressionAttributeValues as $name => $v) {
388-
$payload['ExpressionAttributeValues'][$name] = $v->requestBody();
391+
if (null !== $v = $this->ExpressionAttributeValues) {
392+
foreach ($v as $name => $v) {
393+
$payload['ExpressionAttributeValues'][$name] = $v->requestBody();
394+
}
389395
}
390396

391397
return $payload;

0 commit comments

Comments
 (0)