20
20
import java .util .Comparator ;
21
21
import java .util .List ;
22
22
import java .util .Set ;
23
+ import java .util .TreeMap ;
23
24
import java .util .TreeSet ;
24
25
import java .util .logging .Logger ;
25
26
import software .amazon .smithy .codegen .core .CodegenException ;
39
40
import software .amazon .smithy .model .shapes .Shape ;
40
41
import software .amazon .smithy .model .shapes .ShapeIndex ;
41
42
import software .amazon .smithy .model .shapes .StringShape ;
43
+ import software .amazon .smithy .model .shapes .StructureShape ;
42
44
import software .amazon .smithy .model .shapes .TimestampShape ;
43
45
import software .amazon .smithy .model .traits .HttpTrait ;
44
46
import software .amazon .smithy .model .traits .TimestampFormatTrait .Format ;
@@ -352,7 +354,7 @@ private String getInputValue(
352
354
Shape target
353
355
) {
354
356
if (isNativeSimpleType (target )) {
355
- return dataSource ;
357
+ return dataSource + ".toString()" ;
356
358
} else if (target instanceof TimestampShape ) {
357
359
HttpBindingIndex httpIndex = context .getModel ().getKnowledge (HttpBindingIndex .class );
358
360
Format format = httpIndex .determineTimestampFormat (member , bindingType , getDocumentTimestampFormat ());
@@ -373,9 +375,9 @@ private String getInputValue(
373
375
* blob. By default, this base64 encodes content in headers and query strings,
374
376
* and passes through for payloads.
375
377
*
376
- * @param dataSource The in-code location of the data to provide an output of
377
- * ({@code output.foo}, {@code entry}, etc.)
378
378
* @param bindingType How this value is bound to the operation input.
379
+ * @param dataSource The in-code location of the data to provide an input of
380
+ * ({@code input.foo}, {@code entry}, etc.)
379
381
* @return Returns a value or expression of the input blob.
380
382
*/
381
383
private String getBlobInputParam (Location bindingType , String dataSource ) {
@@ -397,8 +399,8 @@ private String getBlobInputParam(Location bindingType, String dataSource) {
397
399
* relies on the HTTP implementation for query strings.
398
400
*
399
401
* @param bindingType How this value is bound to the operation input.
400
- * @param dataSource The in-code location of the data to provide an output of
401
- * ({@code output .foo}, {@code entry}, etc.)
402
+ * @param dataSource The in-code location of the data to provide an input of
403
+ * ({@code input .foo}, {@code entry}, etc.)
402
404
* @return Returns a value or expression of the input collection.
403
405
*/
404
406
private String getCollectionInputParam (
@@ -482,18 +484,19 @@ private void generateOperationDeserializer(
482
484
// Only set a type and the members if we have output.
483
485
operation .getOutput ().ifPresent (outputId -> {
484
486
writer .write ("__type: $S," , outputId .getName ());
485
- List <HttpBinding > documentBindings = bindingIndex .getResponseBindings (operation , Location .DOCUMENT );
486
- // Track all shapes bound to the document so their deserializers may be generated.
487
- documentBindings .forEach (binding -> {
488
- // Set all the members to undefined to meet type constraints.
489
- writer .write ("$L: undefined," , binding .getMemberName ());
490
- Shape target = shapeIndex .getShape (binding .getMember ().getTarget ()).get ();
491
- documentDeserializingShapes .add (target );
492
- });
487
+ // Set all the members to undefined to meet type constraints.
488
+ StructureShape target = shapeIndex .getShape (outputId ).get ().asStructureShape ().get ();
489
+ new TreeMap <>(target .getAllMembers ())
490
+ .forEach ((memberName , memberShape ) -> writer .write ("$L: undefined," , memberName ));
493
491
});
494
492
});
495
493
readHeaders (context , operation , bindingIndex );
496
- readResponseBody (context , operation , bindingIndex );
494
+ List <HttpBinding > documentBindings = readResponseBody (context , operation , bindingIndex );
495
+ // Track all shapes bound to the document so their deserializers may be generated.
496
+ documentBindings .forEach (binding -> {
497
+ Shape target = shapeIndex .getShape (binding .getMember ().getTarget ()).get ();
498
+ documentDeserializingShapes .add (target );
499
+ });
497
500
writer .write ("return Promise.resolve(contents);" );
498
501
});
499
502
writer .write ("" );
0 commit comments