Skip to content

Commit badd554

Browse files
authored
fix: make BetaApi the getHttpJsonOperationsClient() in case of multitransport clients (#1007)
All multitransport user-facing features are already declared `BetaApi`, `getHttpJsonOperationsClient()` was missing it by mistake.
1 parent 0d88268 commit badd554

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@
9090
import java.util.Arrays;
9191
import java.util.Collections;
9292
import java.util.HashMap;
93-
import java.util.HashSet;
9493
import java.util.Iterator;
9594
import java.util.LinkedHashMap;
9695
import java.util.List;
9796
import java.util.Map;
9897
import java.util.Objects;
9998
import java.util.Optional;
100-
import java.util.Set;
10199
import java.util.concurrent.TimeUnit;
102100
import java.util.function.BiFunction;
103101
import java.util.function.Function;
@@ -507,17 +505,23 @@ private List<MethodDefinition> createGetterMethods(
507505
"getSettings", typeStore.get(ClassNames.getServiceSettingsClassName(service)));
508506
methodNameToTypes.put("getStub", typeStore.get(ClassNames.getServiceStubClassName(service)));
509507

510-
Set<String> getOperationsClientMethodNames = new HashSet<>();
508+
Map<String, List<AnnotationNode>> getOperationsClientMethod = new HashMap<>();
509+
AnnotationNode betaAnnotation =
510+
AnnotationNode.builder().setType(typeStore.get("BetaApi")).build();
511511

512512
if (hasLroClient) {
513513
Iterator<String> opClientNamesIt = getTransportContext().operationsClientNames().iterator();
514514
Iterator<TypeNode> opClientTypesIt = getTransportContext().operationsClientTypes().iterator();
515-
515+
List<AnnotationNode> operationClientGetterAnnotations = new ArrayList<>();
516516
while (opClientNamesIt.hasNext() && opClientTypesIt.hasNext()) {
517517
String opClientMethodName =
518518
String.format("get%s", JavaStyle.toUpperCamelCase(opClientNamesIt.next()));
519-
getOperationsClientMethodNames.add(opClientMethodName);
519+
getOperationsClientMethod.put(opClientMethodName, operationClientGetterAnnotations);
520520
methodNameToTypes.put(opClientMethodName, opClientTypesIt.next());
521+
// Only first (default transport) getter is non-beta, all others are
522+
if (operationClientGetterAnnotations.isEmpty()) {
523+
operationClientGetterAnnotations = Collections.singletonList(betaAnnotation);
524+
}
521525
}
522526
}
523527

@@ -528,10 +532,12 @@ private List<MethodDefinition> createGetterMethods(
528532
TypeNode methodReturnType = e.getValue();
529533
String returnVariableName = JavaStyle.toLowerCamelCase(methodName.substring(3));
530534
MethodDefinition.Builder methodBuilder = MethodDefinition.builder();
531-
if (getOperationsClientMethodNames.contains(methodName)) {
535+
List<AnnotationNode> annotations = getOperationsClientMethod.get(methodName);
536+
if (annotations != null) {
532537
methodBuilder =
533538
methodBuilder.setHeaderCommentStatements(
534539
ServiceClientCommentComposer.GET_OPERATIONS_CLIENT_METHOD_COMMENT);
540+
methodBuilder.setAnnotations(annotations);
535541
}
536542
return methodBuilder
537543
.setScope(ScopeNode.PUBLIC)

src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public class EchoClient implements BackgroundResource {
172172
* Returns the OperationsClient that can be used to query the status of a long-running operation
173173
* returned by another API method call.
174174
*/
175+
@BetaApi
175176
public final OperationsClient getHttpJsonOperationsClient() {
176177
return httpJsonOperationsClient;
177178
}

0 commit comments

Comments
 (0)