5
5
namespace AsyncAws \CodeGenerator \Generator ;
6
6
7
7
use AsyncAws \CodeGenerator \Definition \ListShape ;
8
+ use AsyncAws \CodeGenerator \Definition \MapShape ;
8
9
use AsyncAws \CodeGenerator \Definition \Operation ;
9
10
use AsyncAws \CodeGenerator \Definition \Pagination ;
11
+ use AsyncAws \CodeGenerator \Definition \Shape ;
10
12
use AsyncAws \CodeGenerator \Definition \StructureShape ;
11
13
use AsyncAws \CodeGenerator \Generator \CodeGenerator \TypeGenerator ;
12
14
use AsyncAws \CodeGenerator \Generator \Naming \NamespaceRegistry ;
@@ -165,7 +167,7 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
165
167
'PROPERTY_NAME ' => GeneratorHelper::normalizeName ($ resultKey ),
166
168
'PAGE_LOADER_CODE ' => $ this ->generateOutputPaginationLoader (
167
169
strtr ('yield from $page->PROPERTY_ACCESSOR; ' , ['PROPERTY_ACCESSOR ' => GeneratorHelper::normalizeName ($ resultKey )]),
168
- $ common , $ moreResult , $ outputToken , $ pagination , $ classBuilder , $ operation
170
+ $ common , $ moreResult , $ outputToken , $ pagination , $ classBuilder , $ operation, $ shape
169
171
),
170
172
]));
171
173
}
@@ -182,7 +184,7 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
182
184
'PROPERTY_ACCESSOR ' => 'get ' . ucfirst (GeneratorHelper::normalizeName ($ resultKeys [0 ])),
183
185
]);
184
186
} else {
185
- $ body = $ this ->generateOutputPaginationLoader ($ iteratorBody , $ common , $ moreResult , $ outputToken , $ pagination , $ classBuilder , $ operation );
187
+ $ body = $ this ->generateOutputPaginationLoader ($ iteratorBody , $ common , $ moreResult , $ outputToken , $ pagination , $ classBuilder , $ operation, $ shape );
186
188
}
187
189
188
190
$ classBuilder ->addMethod ('getIterator ' )
@@ -197,22 +199,39 @@ private function generateOutputPagination(Operation $operation, Pagination $pagi
197
199
/**
198
200
* @param string[] $outputToken
199
201
*/
200
- private function generateOutputPaginationLoader (string $ iterator , string $ common , string $ moreResult , array $ outputToken , Pagination $ pagination , ClassBuilder $ classBuilder , Operation $ operation ): string
202
+ private function generateOutputPaginationLoader (string $ iterator , string $ common , string $ moreResult , array $ outputToken , Pagination $ pagination , ClassBuilder $ classBuilder , Operation $ operation, StructureShape $ shape ): string
201
203
{
202
204
if (empty ($ outputToken )) {
203
205
return strtr ($ iterator , ['$page-> ' => '$this-> ' ]);
204
206
}
205
207
206
208
$ inputToken = $ pagination ->getInputToken ();
209
+ $ moreCondition = '' ;
210
+ $ moreShape = null ;
207
211
if (!$ moreResult ) {
208
- $ moreCondition = '' ;
209
212
foreach ($ outputToken as $ property ) {
210
- $ moreCondition .= 'null !== ' . $ this ->generateGetter ('$page ' , $ property , (bool ) $ common );
213
+ $ moreResult = $ property ;
214
+ $ moreShape = $ shape ->getMember ($ moreResult )->getShape ();
211
215
212
216
break ;
213
217
}
214
218
} else {
215
- $ moreCondition = $ this ->generateGetter ('$page ' , $ moreResult , (bool ) $ common );
219
+ if ($ common ) {
220
+ $ shape = $ shape ->getMember ($ common )->getShape ();
221
+ }
222
+ if ($ shape instanceof StructureShape) {
223
+ $ moreShape = $ shape ->getMember ($ moreResult )->getShape ();
224
+ }
225
+ }
226
+
227
+ if ($ moreResult ) {
228
+ if ($ moreShape instanceof ListShape || $ moreShape instanceof MapShape) {
229
+ $ moreCondition .= '[] !== ' . $ this ->generateGetter ('$page ' , $ moreResult , (bool ) $ common );
230
+ } elseif ($ moreShape instanceof Shape && 'boolean ' === $ moreShape ->getType ()) {
231
+ $ moreCondition .= $ this ->generateGetter ('$page ' , $ moreResult , (bool ) $ common );
232
+ } else {
233
+ $ moreCondition .= 'null !== ' . $ this ->generateGetter ('$page ' , $ moreResult , (bool ) $ common );
234
+ }
216
235
}
217
236
$ setter = '' ;
218
237
foreach ($ inputToken as $ index => $ property ) {
0 commit comments