Skip to content

Commit

Permalink
update codegen function
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Apr 30, 2021
1 parent 98b57a4 commit d8d74c9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ protected void deserializeError(GenerationContext context, StructureShape shape)
writer.write("output := &$T{}", symbol);
writer.insertTrailingNewline();
if (isShapeWithResponseBindings(context.getModel(), shape, HttpBinding.Location.DOCUMENT)) {
String functionName = shape.hasTrait(SyntheticClone.class) ?
ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName()) :
ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());
String functionName;
if (shape.hasTrait(SyntheticClone.class)) {
functionName = ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName());
} else {
functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());
}

writer.addUseImports(SmithyGoDependency.IO);
initializeXmlDecoder(writer, "errorBody", "output");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
Model model = context.getModel();
Shape payloadShape = model.expectShape(memberShape.getTarget());

String functionName = payloadShape.hasTrait(SyntheticClone.class) ?
ProtocolGenerator.getOperationDocumentSerFuncName(
payloadShape, context.getProtocolName()) :
ProtocolGenerator.getDocumentSerializerFunctionName(
payloadShape, context.getService(), context.getProtocolName());
String functionName;
if (payloadShape.hasTrait(SyntheticClone.class)) {
functionName = ProtocolGenerator.getOperationDocumentSerFuncName(
payloadShape, context.getProtocolName());
} else {
functionName = ProtocolGenerator.getDocumentSerializerFunctionName(
payloadShape, context.getService(), context.getProtocolName());
}

writer.addUseImports(SmithyGoDependency.SMITHY_JSON);
writer.write("jsonEncoder := smithyjson.NewEncoder()");
Expand Down Expand Up @@ -244,11 +247,15 @@ private void writeMiddlewareDocumentBindingDeserializerDelegator(
Shape shape,
String operand
) {
String functionName = shape.hasTrait(SyntheticClone.class) ?
ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName()) :
ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());

String functionName;
if (shape.hasTrait(SyntheticClone.class)) {
functionName = ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName());
} else {
functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());
}

writer.write("err = $L(&$L, shape)", functionName, operand);
writer.openBlock("if err != nil {", "}", () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,14 @@ private void writeMiddlewareDocumentBindingDeserializerDelegator(
XmlProtocolUtils.initializeXmlDecoder(writer, "response.Body", "out, metadata,", "nil");
writer.addUseImports(SmithyGoDependency.IO);

String functionName = shape.hasTrait(SyntheticClone.class) ?
ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName()) :
ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());
String functionName;
if (shape.hasTrait(SyntheticClone.class)) {
functionName = ProtocolGenerator.getOperationDocumentDeserFuncName(
shape, context.getProtocolName());
} else {
functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());
}

writer.write("err = $L(&$L, decoder)", functionName, operand);
XmlProtocolUtils.handleDecodeError(writer, "out, metadata,");
Expand Down

0 comments on commit d8d74c9

Please sign in to comment.