Skip to content

Commit 01f4b16

Browse files
authored
Convert protocol functions to arrow functions (#174)
1 parent acaa058 commit 01f4b16

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ private void generateOperationSerializer(
213213
Symbol inputType = symbol.expectProperty("inputType", Symbol.class);
214214
String contextType = CodegenUtils.getOperationSerializerContextType(writer, context.getModel(), operation);
215215

216-
writer.openBlock("export async function $L(\n"
216+
writer.openBlock("export const $L = async(\n"
217217
+ " input: $T,\n"
218218
+ " context: $L\n"
219-
+ "): Promise<$T> {", "}", methodName, inputType, contextType, requestType, () -> {
219+
+ "): Promise<$T> => {", "}", methodName, inputType, contextType, requestType, () -> {
220220
writeHeaders(context, operation, bindingIndex);
221221
writeResolvedPath(context, operation, bindingIndex, trait);
222222
boolean hasQueryComponents = writeRequestQueryString(context, operation, bindingIndex, trait);
@@ -847,10 +847,10 @@ private void generateOperationDeserializer(
847847
String contextType = CodegenUtils.getOperationDeserializerContextType(writer, context.getModel(), operation);
848848

849849
// Handle the general response.
850-
writer.openBlock("export async function $L(\n"
850+
writer.openBlock("export const $L = async(\n"
851851
+ " output: $T,\n"
852852
+ " context: $L\n"
853-
+ "): Promise<$T> {", "}", methodName, responseType, contextType, outputType, () -> {
853+
+ "): Promise<$T> => {", "}", methodName, responseType, contextType, outputType, () -> {
854854
// Redirect error deserialization to the dispatcher if we receive an error range
855855
// status code that's not the modeled code (400 or higher). This allows for
856856
// returning other 2XX or 3XX codes that don't match the defined value.

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpProtocolGeneratorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ static Set<StructureShape> generateErrorDispatcher(
274274
Symbol outputType = symbol.expectProperty("outputType", Symbol.class);
275275
String errorMethodName = ProtocolGenerator.getDeserFunctionName(symbol, context.getProtocolName()) + "Error";
276276

277-
writer.openBlock("async function $L(\n"
277+
writer.openBlock("const $L = async(\n"
278278
+ " output: $T,\n"
279279
+ " context: __SerdeContext,\n"
280-
+ "): Promise<$T> {", "}", errorMethodName, responseType, outputType, () -> {
280+
+ "): Promise<$T> => {", "}", errorMethodName, responseType, outputType, () -> {
281281
// Prepare error response for parsing error code. If error code needs to be parsed from response body
282282
// then we collect body and parse it to JS object, otherwise leave the response body as is.
283283
if (shouldParseErrorBody) {

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ private void generateOperationSerializer(GenerationContext context, OperationSha
166166
// Add the normalized input type.
167167
Symbol inputType = symbol.expectProperty("inputType", Symbol.class);
168168

169-
writer.openBlock("export async function $L(\n"
169+
writer.openBlock("export const $L = async(\n"
170170
+ " input: $T,\n"
171171
+ " context: __SerdeContext\n"
172-
+ "): Promise<$T> {", "}", methodName, inputType, requestType, () -> {
172+
+ "): Promise<$T> => {", "}", methodName, inputType, requestType, () -> {
173173
writeRequestHeaders(context, operation);
174174
boolean hasRequestBody = writeRequestBody(context, operation);
175175
boolean hasHostPrefix = operation.hasTrait(EndpointTrait.class);
@@ -313,10 +313,10 @@ private void generateOperationDeserializer(GenerationContext context, OperationS
313313
Symbol outputType = symbol.expectProperty("outputType", Symbol.class);
314314

315315
// Handle the general response.
316-
writer.openBlock("export async function $L(\n"
316+
writer.openBlock("export const $L = async(\n"
317317
+ " output: $T,\n"
318318
+ " context: __SerdeContext\n"
319-
+ "): Promise<$T> {", "}", methodName, responseType, outputType, () -> {
319+
+ "): Promise<$T> => {", "}", methodName, responseType, outputType, () -> {
320320
// Redirect error deserialization to the dispatcher
321321
writer.openBlock("if (output.statusCode >= 400) {", "}", () -> {
322322
writer.write("return $L(output, context);", errorMethodName);

0 commit comments

Comments
 (0)