@@ -125,7 +125,7 @@ public ApplicationProtocol getApplicationProtocol() {
125
125
/**
126
126
* Generates serialization functions for shapes in the passed set. These functions
127
127
* should return a value that can then be serialized by the implementation of
128
- * {@code serializeInputDocument }. The {@link DocumentShapeSerVisitor} and {@link DocumentMemberSerVisitor}
128
+ * {@code serializeDocument }. The {@link DocumentShapeSerVisitor} and {@link DocumentMemberSerVisitor}
129
129
* are provided to reduce the effort of this implementation.
130
130
*
131
131
* @param context The generation context.
@@ -136,7 +136,7 @@ public ApplicationProtocol getApplicationProtocol() {
136
136
/**
137
137
* Generates deserialization functions for shapes in the passed set. These functions
138
138
* should return a value that can then be deserialized by the implementation of
139
- * {@code deserializeOutputDocument }. The {@link DocumentShapeDeserVisitor} and
139
+ * {@code deserializeDocument }. The {@link DocumentShapeDeserVisitor} and
140
140
* {@link DocumentMemberDeserVisitor} are provided to reduce the effort of this implementation.
141
141
*
142
142
* @param context The generation context.
@@ -429,7 +429,8 @@ private void generateOperationResponseSerializer(
429
429
+ "): Promise<$T> => {" , "}" , methodName , outputType , responseType , () -> {
430
430
writeEmptyEndpoint (context );
431
431
writeOperationStatusCode (context , operation , bindingIndex , trait );
432
- writeResponseHeaders (context , operation , bindingIndex , () -> writeDefaultHeaders (context , operation ));
432
+ writeResponseHeaders (context , operation , bindingIndex ,
433
+ () -> writeDefaultHeaders (context , operation , false ));
433
434
434
435
List <HttpBinding > bodyBindings = writeResponseBody (context , operation , bindingIndex );
435
436
if (!bodyBindings .isEmpty ()) {
@@ -480,7 +481,7 @@ private void generateErrorSerializationImplementation(GenerationContext context,
480
481
HttpBindingIndex bindingIndex ) {
481
482
TypeScriptWriter writer = context .getWriter ();
482
483
writeErrorStatusCode (context , error );
483
- writeResponseHeaders (context , error , bindingIndex , () -> writeDefaultErrorHeaders (context , error ));
484
+ writeResponseHeaders (context , error , bindingIndex , () -> writeDefaultHeaders (context , error , false ));
484
485
485
486
List <HttpBinding > bodyBindings = writeResponseBody (context , error , bindingIndex );
486
487
if (!bodyBindings .isEmpty ()) {
@@ -722,7 +723,7 @@ private void writeRequestHeaders(
722
723
// Only set the content type if one can be determined.
723
724
bindingIndex .determineRequestContentType (operation , getDocumentContentType ()).ifPresent (contentType ->
724
725
writer .write ("'content-type': $S," , contentType ));
725
- writeDefaultHeaders (context , operation );
726
+ writeDefaultHeaders (context , operation , true );
726
727
727
728
operation .getInput ().ifPresent (outputId -> {
728
729
for (HttpBinding binding : bindingIndex .getRequestBindings (operation , Location .HEADER )) {
@@ -803,7 +804,7 @@ private List<HttpBinding> writeRequestBody(
803
804
List <HttpBinding > payloadBindings = bindingIndex .getRequestBindings (operation , Location .PAYLOAD );
804
805
List <HttpBinding > documentBindings = bindingIndex .getRequestBindings (operation , Location .DOCUMENT );
805
806
boolean shouldWriteDefaultBody = bindingIndex .getRequestBindings (operation ).isEmpty ();
806
- return writeBody (context , operation , payloadBindings , documentBindings , shouldWriteDefaultBody );
807
+ return writeBody (context , operation , payloadBindings , documentBindings , shouldWriteDefaultBody , true );
807
808
}
808
809
809
810
private List <HttpBinding > writeResponseBody (
@@ -817,15 +818,16 @@ private List<HttpBinding> writeResponseBody(
817
818
List <HttpBinding > payloadBindings = bindingIndex .getResponseBindings (operationOrError , Location .PAYLOAD );
818
819
List <HttpBinding > documentBindings = bindingIndex .getResponseBindings (operationOrError , Location .DOCUMENT );
819
820
boolean shouldWriteDefaultBody = bindingIndex .getResponseBindings (operationOrError ).isEmpty ();
820
- return writeBody (context , operation , payloadBindings , documentBindings , shouldWriteDefaultBody );
821
+ return writeBody (context , operation , payloadBindings , documentBindings , shouldWriteDefaultBody , false );
821
822
}
822
823
823
824
private List <HttpBinding > writeBody (
824
825
GenerationContext context ,
825
826
OperationShape operation ,
826
827
List <HttpBinding > payloadBindings ,
827
828
List <HttpBinding > documentBindings ,
828
- boolean shouldWriteDefaultBody
829
+ boolean shouldWriteDefaultBody ,
830
+ boolean isInput
829
831
) {
830
832
TypeScriptWriter writer = context .getWriter ();
831
833
// Write the default `body` property.
@@ -835,7 +837,7 @@ private List<HttpBinding> writeBody(
835
837
if (!payloadBindings .isEmpty ()) {
836
838
// There can only be one payload binding.
837
839
HttpBinding payloadBinding = payloadBindings .get (0 );
838
- serializeInputPayload (context , operation , payloadBinding );
840
+ serializePayload (context , operation , payloadBinding , true );
839
841
return payloadBindings ;
840
842
}
841
843
@@ -844,7 +846,7 @@ private List<HttpBinding> writeBody(
844
846
if (!documentBindings .isEmpty () || shouldWriteDefaultBody ) {
845
847
documentBindings .sort (Comparator .comparing (HttpBinding ::getMemberName ));
846
848
847
- serializeInputDocument (context , operation , documentBindings );
849
+ serializeDocumentBody (context , operation , documentBindings , isInput );
848
850
return documentBindings ;
849
851
}
850
852
@@ -1110,34 +1112,14 @@ private String getTimestampInputParam(
1110
1112
* }</pre>
1111
1113
*
1112
1114
* @param context The generation context.
1113
- * @param operation The operation being generated.
1115
+ * @param operationOrError The operation or error being generated.
1116
+ * @param isInput Whether the headers for an input or output/error are being generated.
1114
1117
*/
1115
- protected void writeDefaultHeaders (GenerationContext context , OperationShape operation ) {
1118
+ protected void writeDefaultHeaders (GenerationContext context , Shape operationOrError , boolean isInput ) {
1116
1119
}
1117
1120
1118
1121
/**
1119
- * Writes any additional HTTP headers required by the protocol implementation for errors.
1120
- *
1121
- * <p>Two parameters will be available in scope:
1122
- * <ul>
1123
- * <li>{@code input: <T>}: the type generated for the operation's error.</li>
1124
- * <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
1125
- * </ul>
1126
- *
1127
- * <p>For example:
1128
- *
1129
- * <pre>{@code
1130
- * "foo": "This is a custom header",
1131
- * }</pre>
1132
- *
1133
- * @param context The generation context.
1134
- * @param error The error being generated.
1135
- */
1136
- protected void writeDefaultErrorHeaders (GenerationContext context , StructureShape error ) {
1137
- }
1138
-
1139
- /**
1140
- * Writes the code needed to serialize the input document of a request.
1122
+ * Writes the code needed to serialize a protocol document.
1141
1123
*
1142
1124
* <p>Implementations of this method are expected to set a value to the
1143
1125
* {@code body} variable that will be serialized as the request body.
@@ -1155,15 +1137,16 @@ protected void writeDefaultErrorHeaders(GenerationContext context, StructureShap
1155
1137
* }
1156
1138
* body = JSON.stringify(bodyParams);
1157
1139
* }</pre>
1158
- *
1159
- * @param context The generation context.
1140
+ * @param context The generation context.
1160
1141
* @param operation The operation being generated.
1161
1142
* @param documentBindings The bindings to place in the document.
1143
+ * @param isInput Whether the input or output/error of the operation is being serialized.
1162
1144
*/
1163
- protected abstract void serializeInputDocument (
1145
+ protected abstract void serializeDocumentBody (
1164
1146
GenerationContext context ,
1165
1147
OperationShape operation ,
1166
- List <HttpBinding > documentBindings
1148
+ List <HttpBinding > documentBindings ,
1149
+ boolean isInput
1167
1150
);
1168
1151
1169
1152
/**
@@ -1180,15 +1163,16 @@ protected abstract void serializeInputDocument(
1180
1163
* body = context.base64Encoder(input.body);
1181
1164
* }
1182
1165
* }</pre>
1183
- *
1184
- * @param context The generation context.
1166
+ * @param context The generation context.
1185
1167
* @param operation The operation being generated.
1186
1168
* @param payloadBinding The payload binding to serialize.
1169
+ * @param isInput Whether the input or output/error of the operation is being serialized.
1187
1170
*/
1188
- protected void serializeInputPayload (
1171
+ protected void serializePayload (
1189
1172
GenerationContext context ,
1190
1173
OperationShape operation ,
1191
- HttpBinding payloadBinding
1174
+ HttpBinding payloadBinding ,
1175
+ boolean isInput
1192
1176
) {
1193
1177
TypeScriptWriter writer = context .getWriter ();
1194
1178
SymbolProvider symbolProvider = context .getSymbolProvider ();
@@ -1627,7 +1611,7 @@ private List<HttpBinding> readErrorResponseBody(
1627
1611
writer .write ("const data: any = $L;" , getErrorBodyLocation (context , "parsedOutput.body" ));
1628
1612
List <HttpBinding > responseBindings = bindingIndex .getResponseBindings (error , Location .DOCUMENT );
1629
1613
responseBindings .sort (Comparator .comparing (HttpBinding ::getMemberName ));
1630
- deserializeOutputDocument (context , error , responseBindings );
1614
+ deserializeDocumentBody (context , error , responseBindings , false );
1631
1615
return responseBindings ;
1632
1616
} else {
1633
1617
// Deserialize response body just like in a normal response.
@@ -1741,7 +1725,7 @@ private List<HttpBinding> readRequestBody(
1741
1725
List <HttpBinding > documentBindings = bindingIndex .getRequestBindings (operation , Location .DOCUMENT );
1742
1726
documentBindings .sort (Comparator .comparing (HttpBinding ::getMemberName ));
1743
1727
List <HttpBinding > payloadBindings = bindingIndex .getRequestBindings (operation , Location .PAYLOAD );
1744
- return readBody (context , operation , documentBindings , payloadBindings , Collections .emptyList ());
1728
+ return readBody (context , operation , documentBindings , payloadBindings , Collections .emptyList (), false );
1745
1729
}
1746
1730
1747
1731
private List <HttpBinding > readResponseBody (
@@ -1754,15 +1738,16 @@ private List<HttpBinding> readResponseBody(
1754
1738
List <HttpBinding > payloadBindings = bindingIndex .getResponseBindings (operationOrError , Location .PAYLOAD );
1755
1739
List <HttpBinding > responseCodeBindings = bindingIndex .getResponseBindings (
1756
1740
operationOrError , Location .RESPONSE_CODE );
1757
- return readBody (context , operationOrError , documentBindings , payloadBindings , responseCodeBindings );
1741
+ return readBody (context , operationOrError , documentBindings , payloadBindings , responseCodeBindings , true );
1758
1742
}
1759
1743
1760
1744
private List <HttpBinding > readBody (
1761
1745
GenerationContext context ,
1762
1746
Shape operationOrError ,
1763
1747
List <HttpBinding > documentBindings ,
1764
1748
List <HttpBinding > payloadBindings ,
1765
- List <HttpBinding > responseCodeBindings
1749
+ List <HttpBinding > responseCodeBindings ,
1750
+ boolean isInput
1766
1751
) {
1767
1752
TypeScriptWriter writer = context .getWriter ();
1768
1753
SymbolProvider symbolProvider = context .getSymbolProvider ();
@@ -1776,7 +1761,7 @@ private List<HttpBinding> readBody(
1776
1761
}
1777
1762
writer .write ("const data: any = $L;" , bodyLocation );
1778
1763
1779
- deserializeOutputDocument (context , operationOrError , documentBindings );
1764
+ deserializeDocumentBody (context , operationOrError , documentBindings , isInput );
1780
1765
}
1781
1766
if (!payloadBindings .isEmpty ()) {
1782
1767
HttpBinding payloadBinding = readResponsePayload (context , payloadBindings .get (0 ));
@@ -2325,7 +2310,7 @@ protected String getErrorBodyLocation(GenerationContext context, String outputLo
2325
2310
}
2326
2311
2327
2312
/**
2328
- * Writes the code needed to deserialize the output document of a response .
2313
+ * Writes the code needed to deserialize a protocol document.
2329
2314
*
2330
2315
* <p>Implementations of this method are expected to set members in the
2331
2316
* {@code contents} variable that represents the type generated for the
@@ -2340,14 +2325,15 @@ protected String getErrorBodyLocation(GenerationContext context, String outputLo
2340
2325
* contents.fieldList = deserializeAws_restJson1_1FieldList(data.fieldList, context);
2341
2326
* }
2342
2327
* }</pre>
2343
- *
2344
2328
* @param context The generation context.
2345
2329
* @param operationOrError The operation or error with a document being deserialized.
2346
2330
* @param documentBindings The bindings to read from the document.
2331
+ * @param isInput Whether the input or output/error of the operation is being deserialized.
2347
2332
*/
2348
- protected abstract void deserializeOutputDocument (
2333
+ protected abstract void deserializeDocumentBody (
2349
2334
GenerationContext context ,
2350
2335
Shape operationOrError ,
2351
- List <HttpBinding > documentBindings
2336
+ List <HttpBinding > documentBindings ,
2337
+ boolean isInput
2352
2338
);
2353
2339
}
0 commit comments