Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/CodeGenerator/src/Generator/PaginationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace AsyncAws\CodeGenerator\Generator;

use AsyncAws\CodeGenerator\Definition\ListShape;
use AsyncAws\CodeGenerator\Definition\MapShape;
use AsyncAws\CodeGenerator\Definition\Operation;
use AsyncAws\CodeGenerator\Definition\Pagination;
use AsyncAws\CodeGenerator\Definition\Shape;
use AsyncAws\CodeGenerator\Definition\StructureShape;
use AsyncAws\CodeGenerator\Generator\CodeGenerator\TypeGenerator;
use AsyncAws\CodeGenerator\Generator\Naming\NamespaceRegistry;
Expand Down Expand Up @@ -165,7 +167,7 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
'PROPERTY_NAME' => GeneratorHelper::normalizeName($resultKey),
'PAGE_LOADER_CODE' => $this->generateOutputPaginationLoader(
strtr('yield from $page->PROPERTY_ACCESSOR;', ['PROPERTY_ACCESSOR' => GeneratorHelper::normalizeName($resultKey)]),
$common, $moreResult, $outputToken, $pagination, $classBuilder, $operation
$common, $moreResult, $outputToken, $pagination, $classBuilder, $operation, $shape
),
]));
}
Expand All @@ -182,7 +184,7 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
'PROPERTY_ACCESSOR' => 'get' . ucfirst(GeneratorHelper::normalizeName($resultKeys[0])),
]);
} else {
$body = $this->generateOutputPaginationLoader($iteratorBody, $common, $moreResult, $outputToken, $pagination, $classBuilder, $operation);
$body = $this->generateOutputPaginationLoader($iteratorBody, $common, $moreResult, $outputToken, $pagination, $classBuilder, $operation, $shape);
}

$classBuilder->addMethod('getIterator')
Expand All @@ -197,22 +199,39 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
/**
* @param string[] $outputToken
*/
private function generateOutputPaginationLoader(string $iterator, string $common, string $moreResult, array $outputToken, Pagination $pagination, ClassBuilder $classBuilder, Operation $operation): string
private function generateOutputPaginationLoader(string $iterator, string $common, string $moreResult, array $outputToken, Pagination $pagination, ClassBuilder $classBuilder, Operation $operation, StructureShape $shape): string
{
if (empty($outputToken)) {
return strtr($iterator, ['$page->' => '$this->']);
}

$inputToken = $pagination->getInputToken();
$moreCondition = '';
$moreShape = null;
if (!$moreResult) {
$moreCondition = '';
foreach ($outputToken as $property) {
$moreCondition .= 'null !== ' . $this->generateGetter('$page', $property, (bool) $common);
$moreResult = $property;
$moreShape = $shape->getMember($moreResult)->getShape();

break;
}
} else {
$moreCondition = $this->generateGetter('$page', $moreResult, (bool) $common);
if ($common) {
$shape = $shape->getMember($common)->getShape();
}
if ($shape instanceof StructureShape) {
$moreShape = $shape->getMember($moreResult)->getShape();
}
}

if ($moreResult) {
if ($moreShape instanceof ListShape || $moreShape instanceof MapShape) {
$moreCondition .= '[] !== ' . $this->generateGetter('$page', $moreResult, (bool) $common);
} elseif ($moreShape instanceof Shape && 'boolean' === $moreShape->getType()) {
$moreCondition .= $this->generateGetter('$page', $moreResult, (bool) $common);
} else {
$moreCondition .= 'null !== ' . $this->generateGetter('$page', $moreResult, (bool) $common);
}
}
$setter = '';
foreach ($inputToken as $index => $property) {
Expand Down
4 changes: 4 additions & 0 deletions src/Service/DynamoDb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NOT RELEASED

### Changed

- fix pagination when next token is an array

## 3.3.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Service/DynamoDb/src/Result/BatchGetItemOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getConsumedCapacity(bool $currentPageOnly = false): iterable
$page = $this;
while (true) {
$page->initialize();
if (null !== $page->unprocessedKeys) {
if ([] !== $page->unprocessedKeys) {
$input->setRequestItems($page->unprocessedKeys);

$this->registerPrefetch($nextPage = $client->batchGetItem($input));
Expand Down
2 changes: 1 addition & 1 deletion src/Service/DynamoDb/src/Result/QueryOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getItems(bool $currentPageOnly = false): iterable
$page = $this;
while (true) {
$page->initialize();
if (null !== $page->lastEvaluatedKey) {
if ([] !== $page->lastEvaluatedKey) {
$input->setExclusiveStartKey($page->lastEvaluatedKey);

$this->registerPrefetch($nextPage = $client->query($input));
Expand Down
2 changes: 1 addition & 1 deletion src/Service/DynamoDb/src/Result/ScanOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getItems(bool $currentPageOnly = false): iterable
$page = $this;
while (true) {
$page->initialize();
if (null !== $page->lastEvaluatedKey) {
if ([] !== $page->lastEvaluatedKey) {
$input->setExclusiveStartKey($page->lastEvaluatedKey);

$this->registerPrefetch($nextPage = $client->scan($input));
Expand Down