From c4c9a5d17dbbf833d54b6329835b25694108e16c Mon Sep 17 00:00:00 2001 From: skotambkar Date: Fri, 4 Dec 2020 19:47:14 -0800 Subject: [PATCH] fix operation interface generator for incorrect exceptions --- .../OperationInterfaceGenerator.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/OperationInterfaceGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/OperationInterfaceGenerator.java index 58b008d0a..ded793b6b 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/OperationInterfaceGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/OperationInterfaceGenerator.java @@ -15,9 +15,10 @@ package software.amazon.smithy.go.codegen.integration; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import java.util.TreeSet; -import software.amazon.smithy.codegen.core.CodegenException; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.go.codegen.GoDelegator; @@ -38,7 +39,19 @@ */ public class OperationInterfaceGenerator implements GoIntegration { - private static Set listOfClientInterfaceOperations = new TreeSet<>(); + private static Map> mapOfClientInterfaceOperations = new HashMap<>(); + + /** + * Returns name of an API client interface. + * + * @param operationSymbol Symbol of operation shape for which Api client interface is being generated. + * @return name of the interface. + */ + public static String getApiClientInterfaceName( + Symbol operationSymbol + ) { + return String.format("%sAPIClient", operationSymbol.getName()); + } @Override public void processFinalizedModel( @@ -47,6 +60,7 @@ public void processFinalizedModel( ) { ServiceShape serviceShape = settings.getService(model); TopDownIndex topDownIndex = TopDownIndex.of(model); + Set listOfClientInterfaceOperations = new TreeSet<>(); // fetch operations for which paginated trait is applied topDownIndex.getContainedOperations(serviceShape).stream() @@ -55,7 +69,7 @@ public void processFinalizedModel( if (serviceShape.hasTrait(PaginatedTrait.class)) { topDownIndex.getContainedOperations(serviceShape).stream() - .forEach(operationShape -> listOfClientInterfaceOperations.add(operationShape.getId())); + .forEach(operationShape -> listOfClientInterfaceOperations.add(operationShape.toShapeId())); } // fetch operations for which waitable trait is applied @@ -63,12 +77,11 @@ public void processFinalizedModel( .filter(operationShape -> operationShape.hasTrait(WaitableTrait.class)) .forEach(operationShape -> listOfClientInterfaceOperations.add(operationShape.getId())); - if (listOfClientInterfaceOperations.isEmpty()) { - throw new CodegenException("empty operations"); + if (!listOfClientInterfaceOperations.isEmpty()) { + mapOfClientInterfaceOperations.put(serviceShape.getId(), listOfClientInterfaceOperations); } } - @Override public void writeAdditionalFiles( GoSettings settings, @@ -76,12 +89,17 @@ public void writeAdditionalFiles( SymbolProvider symbolProvider, GoDelegator goDelegator ) { - listOfClientInterfaceOperations.stream().forEach(shapeId -> { - OperationShape operationShape = model.expectShape(shapeId, OperationShape.class); - goDelegator.useShapeWriter(operationShape, writer -> { - generateApiClientInterface(writer, model, symbolProvider, operationShape); + ShapeId serviceId = settings.getService(model).getId(); + + if (mapOfClientInterfaceOperations.containsKey(serviceId)) { + Set listOfClientInterfaceOperations = mapOfClientInterfaceOperations.get(serviceId); + listOfClientInterfaceOperations.stream().forEach(shapeId -> { + OperationShape operationShape = model.expectShape(shapeId, OperationShape.class); + goDelegator.useShapeWriter(operationShape, writer -> { + generateApiClientInterface(writer, model, symbolProvider, operationShape); + }); }); - }); + } } private void generateApiClientInterface( @@ -111,16 +129,4 @@ private void generateApiClientInterface( writer.write("var _ $T = (*Client)(nil)", interfaceSymbol); writer.write(""); } - - /** - * Returns name of an API client interface. - * - * @param operationSymbol Symbol of operation shape for which Api client interface is being generated. - * @return name of the interface. - */ - public static String getApiClientInterfaceName( - Symbol operationSymbol - ) { - return String.format("%sAPIClient", operationSymbol.getName()); - } }