diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java index cc6ee5b4f0..cf99df8d15 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java @@ -90,14 +90,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; import java.util.function.Function; @@ -507,17 +505,23 @@ private List createGetterMethods( "getSettings", typeStore.get(ClassNames.getServiceSettingsClassName(service))); methodNameToTypes.put("getStub", typeStore.get(ClassNames.getServiceStubClassName(service))); - Set getOperationsClientMethodNames = new HashSet<>(); + Map> getOperationsClientMethod = new HashMap<>(); + AnnotationNode betaAnnotation = + AnnotationNode.builder().setType(typeStore.get("BetaApi")).build(); if (hasLroClient) { Iterator opClientNamesIt = getTransportContext().operationsClientNames().iterator(); Iterator opClientTypesIt = getTransportContext().operationsClientTypes().iterator(); - + List operationClientGetterAnnotations = new ArrayList<>(); while (opClientNamesIt.hasNext() && opClientTypesIt.hasNext()) { String opClientMethodName = String.format("get%s", JavaStyle.toUpperCamelCase(opClientNamesIt.next())); - getOperationsClientMethodNames.add(opClientMethodName); + getOperationsClientMethod.put(opClientMethodName, operationClientGetterAnnotations); methodNameToTypes.put(opClientMethodName, opClientTypesIt.next()); + // Only first (default transport) getter is non-beta, all others are + if (operationClientGetterAnnotations.isEmpty()) { + operationClientGetterAnnotations = Collections.singletonList(betaAnnotation); + } } } @@ -528,10 +532,12 @@ private List createGetterMethods( TypeNode methodReturnType = e.getValue(); String returnVariableName = JavaStyle.toLowerCamelCase(methodName.substring(3)); MethodDefinition.Builder methodBuilder = MethodDefinition.builder(); - if (getOperationsClientMethodNames.contains(methodName)) { + List annotations = getOperationsClientMethod.get(methodName); + if (annotations != null) { methodBuilder = methodBuilder.setHeaderCommentStatements( ServiceClientCommentComposer.GET_OPERATIONS_CLIENT_METHOD_COMMENT); + methodBuilder.setAnnotations(annotations); } return methodBuilder .setScope(ScopeNode.PUBLIC) diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden index 95f3ef9b99..00e33df2b6 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden @@ -172,6 +172,7 @@ public class EchoClient implements BackgroundResource { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ + @BetaApi public final OperationsClient getHttpJsonOperationsClient() { return httpJsonOperationsClient; }