Skip to content

Commit

Permalink
fix: make BetaApi the getHttpJsonOperationsClient() in case of mu…
Browse files Browse the repository at this point in the history
…ltitransport clients (#1007)

All multitransport user-facing features are already declared `BetaApi`, `getHttpJsonOperationsClient()` was missing it by  mistake.
  • Loading branch information
vam-google committed Jun 16, 2022
1 parent 0d88268 commit badd554
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -507,17 +505,23 @@ private List<MethodDefinition> createGetterMethods(
"getSettings", typeStore.get(ClassNames.getServiceSettingsClassName(service)));
methodNameToTypes.put("getStub", typeStore.get(ClassNames.getServiceStubClassName(service)));

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

if (hasLroClient) {
Iterator<String> opClientNamesIt = getTransportContext().operationsClientNames().iterator();
Iterator<TypeNode> opClientTypesIt = getTransportContext().operationsClientTypes().iterator();

List<AnnotationNode> 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);
}
}
}

Expand All @@ -528,10 +532,12 @@ private List<MethodDefinition> createGetterMethods(
TypeNode methodReturnType = e.getValue();
String returnVariableName = JavaStyle.toLowerCamelCase(methodName.substring(3));
MethodDefinition.Builder methodBuilder = MethodDefinition.builder();
if (getOperationsClientMethodNames.contains(methodName)) {
List<AnnotationNode> annotations = getOperationsClientMethod.get(methodName);
if (annotations != null) {
methodBuilder =
methodBuilder.setHeaderCommentStatements(
ServiceClientCommentComposer.GET_OPERATIONS_CLIENT_METHOD_COMMENT);
methodBuilder.setAnnotations(annotations);
}
return methodBuilder
.setScope(ScopeNode.PUBLIC)
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit badd554

Please sign in to comment.