diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java b/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java index 3656413abe..7184044598 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java @@ -51,6 +51,7 @@ public abstract static class Builder { String throwsType = null; String throwsDescription = null; String deprecated = null; + String internalOnly = null; String returnDescription = null; List paramsList = new ArrayList<>(); List componentsList = new ArrayList<>(); @@ -71,6 +72,11 @@ public Builder setDeprecated(String deprecatedText) { return this; } + public Builder setInternalOnly(String internalOnlyText) { + internalOnly = internalOnlyText; + return this; + } + public Builder setReturn(String returnText) { returnDescription = returnText; return this; @@ -136,13 +142,20 @@ public boolean emptyComments() { return Strings.isNullOrEmpty(throwsType) && Strings.isNullOrEmpty(throwsDescription) && Strings.isNullOrEmpty(deprecated) + && Strings.isNullOrEmpty(internalOnly) && Strings.isNullOrEmpty(returnDescription) && paramsList.isEmpty() && componentsList.isEmpty(); } public JavaDocComment build() { - // @param, @throws, @return, and @deprecated should always get printed at the end. + // Add additional descriptive text before block tags. + if (!Strings.isNullOrEmpty(internalOnly)) { + componentsList.add( + String.format("

Warning: %s", HtmlEscaper.process(internalOnly))); + } + // @param, @throws, @return and @deprecated should always get printed at the + // end. componentsList.addAll(paramsList); if (!Strings.isNullOrEmpty(throwsType)) { componentsList.add( diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/CommentComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/CommentComposer.java index 3731961171..6e4bf0724f 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/CommentComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/CommentComposer.java @@ -49,6 +49,9 @@ public class CommentComposer { static final String DEPRECATED_METHOD_STRING = "This method is deprecated and will be removed in the next major version update."; + static final String INTERNAL_ONLY_METHOD_STRING = + "This method is for internal use only. Please do not use it directly."; + public static final CommentStatement APACHE_LICENSE_COMMENT = CommentStatement.withComment(BlockComment.withComment(APACHE_LICENSE_STRING)); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java index 47d819378f..16d21ef0f9 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java @@ -202,6 +202,10 @@ public static List createRpcMethodHeaderComment( methodJavadocBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING); } + if (method.isInternalApi()) { + methodJavadocBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING); + } + List comments = new ArrayList<>(); comments.add(CommentComposer.AUTO_GENERATED_METHOD_COMMENT); if (!methodJavadocBuilder.emptyComments()) { @@ -345,6 +349,10 @@ public static List createRpcCallableMethodHeaderComment( methodJavadocBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING); } + if (method.isInternalApi()) { + methodJavadocBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING); + } + return Arrays.asList( CommentComposer.AUTO_GENERATED_METHOD_COMMENT, CommentStatement.withComment(methodJavadocBuilder.build())); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java index eb906f2145..438cd9b274 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java @@ -59,31 +59,31 @@ public class SettingsCommentComposer { "Retries are configured for idempotent methods but not for non-idempotent methods."; public static final CommentStatement DEFAULT_SCOPES_COMMENT = - toSimpleComment("The default scopes of the service."); + toCommentStatement("The default scopes of the service."); public static final CommentStatement DEFAULT_EXECUTOR_PROVIDER_BUILDER_METHOD_COMMENT = - toSimpleComment("Returns a builder for the default ExecutorProvider for this service."); + toCommentStatement("Returns a builder for the default ExecutorProvider for this service."); public static final CommentStatement DEFAULT_SERVICE_NAME_METHOD_COMMENT = - toSimpleComment("Returns the default service name."); + toCommentStatement("Returns the default service name."); public static final CommentStatement DEFAULT_SERVICE_ENDPOINT_METHOD_COMMENT = - toSimpleComment("Returns the default service endpoint."); + toCommentStatement("Returns the default service endpoint."); public static final CommentStatement DEFAULT_SERVICE_MTLS_ENDPOINT_METHOD_COMMENT = - toSimpleComment("Returns the default mTLS service endpoint."); + toCommentStatement("Returns the default mTLS service endpoint."); public static final CommentStatement DEFAULT_SERVICE_SCOPES_METHOD_COMMENT = - toSimpleComment("Returns the default service scopes."); + toCommentStatement("Returns the default service scopes."); public static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT = - toSimpleComment("Returns a builder for the default credentials for this service."); + toCommentStatement("Returns a builder for the default credentials for this service."); public static final CommentStatement DEFAULT_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT = - toSimpleComment("Returns a builder for the default ChannelProvider for this service."); + toCommentStatement("Returns a builder for the default ChannelProvider for this service."); public static final CommentStatement NEW_BUILDER_METHOD_COMMENT = - toSimpleComment("Returns a new builder for this class."); + toCommentStatement("Returns a new builder for this class."); public static final CommentStatement TO_BUILDER_METHOD_COMMENT = - toSimpleComment("Returns a builder containing all the values of this settings class."); + toCommentStatement("Returns a builder containing all the values of this settings class."); public static final List APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS = Arrays.asList( @@ -103,9 +103,10 @@ public class SettingsCommentComposer { public SettingsCommentComposer(String transportPrefix) { this.newTransportBuilderMethodComment = - toSimpleComment(String.format("Returns a new %s builder for this class.", transportPrefix)); + toCommentStatement( + String.format("Returns a new %s builder for this class.", transportPrefix)); this.transportProviderBuilderMethodComment = - toSimpleComment( + toCommentStatement( String.format( "Returns a builder for the default %s ChannelProvider for this service.", transportPrefix)); @@ -120,23 +121,21 @@ public CommentStatement getTransportProviderBuilderMethodComment() { } public static CommentStatement createCallSettingsGetterComment( - String javaMethodName, boolean isMethodDeprecated) { - String methodComment = String.format(CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName); - return isMethodDeprecated - ? toDeprecatedSimpleComment(methodComment) - : toSimpleComment(methodComment); + String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) { + return toCommentStatement( + String.format(CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName), + isMethodDeprecated, + isMethodInternal); } public static CommentStatement createBuilderClassComment(String outerClassName) { - return toSimpleComment(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName)); + return toCommentStatement(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName)); } public static CommentStatement createCallSettingsBuilderGetterComment( - String javaMethodName, boolean isMethodDeprecated) { + String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) { String methodComment = String.format(CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN, javaMethodName); - return isMethodDeprecated - ? toDeprecatedSimpleComment(methodComment) - : toSimpleComment(methodComment); + return toCommentStatement(methodComment, isMethodDeprecated, isMethodInternal); } public static List createClassHeaderComments( @@ -201,15 +200,21 @@ public static List createClassHeaderComments( CommentStatement.withComment(javaDocCommentBuilder.build())); } - private static CommentStatement toSimpleComment(String comment) { - return CommentStatement.withComment(JavaDocComment.withComment(comment)); + private static CommentStatement toCommentStatement(String comment) { + return toCommentStatement(comment, false, false); } - private static CommentStatement toDeprecatedSimpleComment(String comment) { - return CommentStatement.withComment( - JavaDocComment.builder() - .addComment(comment) - .setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING) - .build()); + private static CommentStatement toCommentStatement( + String comment, boolean isDeprecated, boolean isInternal) { + JavaDocComment.Builder docBuilder = JavaDocComment.builder().addComment(comment); + docBuilder = + isDeprecated + ? docBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING) + : docBuilder; + docBuilder = + isInternal + ? docBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING) + : docBuilder; + return CommentStatement.withComment(docBuilder.build()); } } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java index 8eff00f1bb..0bd67e1663 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; @@ -62,6 +63,7 @@ import com.google.api.generator.gapic.composer.samplecode.ServiceClientMethodSampleComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.Field; import com.google.api.generator.gapic.model.GapicClass; @@ -103,7 +105,6 @@ import javax.annotation.Generated; public abstract class AbstractServiceClientClassComposer implements ClassComposer { - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private static final String CALLABLE_NAME_PATTERN = "%sCallable"; private static final String PAGED_CALLABLE_NAME_PATTERN = "%sPagedCallable"; private static final String OPERATION_CALLABLE_NAME_PATTERN = "%sOperationCallable"; @@ -127,6 +128,21 @@ protected TransportContext getTransportContext() { return transportContext; } + private static List createMethodAnnotations(Method method, TypeStore typeStore) { + List annotations = new ArrayList<>(); + if (method.isDeprecated()) { + annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); + } + + if (method.isInternalApi()) { + annotations.add( + AnnotationNode.withTypeAndDescription( + typeStore.get("InternalApi"), CommonStrings.INTERNAL_API_WARNING)); + } + + return annotations; + } + @Override public GapicClass generate(GapicContext context, Service service) { Map resourceNames = context.helperResourceNames(); @@ -136,7 +152,6 @@ public GapicClass generate(GapicContext context, Service service) { GapicClass.Kind kind = Kind.MAIN; String pakkage = service.pakkage(); boolean hasLroClient = service.hasStandardLroMethods(); - List samples = new ArrayList<>(); Map> grpcRpcsToJavaMethodNames = new HashMap<>(); Map> methodVariantsForClientHeader = new HashMap<>(); @@ -713,7 +728,8 @@ private static List createMethodVariants( TypeNode methodInputType = method.inputType(); TypeNode methodOutputType = method.isPaged() - ? typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) + ? typeStore.get( + String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) : method.outputType(); if (method.hasLro()) { LongrunningOperation lro = method.lro(); @@ -802,11 +818,8 @@ private static List createMethodVariants( methodVariantBuilder.setReturnType(methodOutputType).setReturnExpr(rpcInvocationExpr); } - if (method.isDeprecated()) { - methodVariantBuilder = - methodVariantBuilder.setAnnotations( - Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED))); - } + methodVariantBuilder = + methodVariantBuilder.setAnnotations(createMethodAnnotations(method, typeStore)); methodVariantBuilder = methodVariantBuilder.setBody(statements); javaMethods.add(methodVariantBuilder.build()); } @@ -826,9 +839,9 @@ private static MethodDefinition createMethodDefaultMethod( TypeNode methodInputType = method.inputType(); TypeNode methodOutputType = method.isPaged() - ? typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) + ? typeStore.get( + String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) : method.outputType(); - List annotations = new ArrayList<>(); if (method.hasLro()) { LongrunningOperation lro = method.lro(); methodOutputType = @@ -885,10 +898,6 @@ private static MethodDefinition createMethodDefaultMethod( .setName(String.format(method.hasLro() ? "%sAsync" : "%s", methodName)) .setArguments(Arrays.asList(requestArgVarExpr)); - if (method.isDeprecated()) { - annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); - } - if (isProtoEmptyType(methodOutputType)) { methodBuilder = methodBuilder @@ -899,8 +908,7 @@ private static MethodDefinition createMethodDefaultMethod( methodBuilder.setReturnExpr(callableMethodExpr).setReturnType(methodOutputType); } - methodBuilder.setAnnotations(annotations); - + methodBuilder.setAnnotations(createMethodAnnotations(method, typeStore)); return methodBuilder.build(); } @@ -1039,11 +1047,8 @@ private static MethodDefinition createCallableMethod( } MethodDefinition.Builder methodDefBuilder = MethodDefinition.builder(); - if (method.isDeprecated()) { - methodDefBuilder = - methodDefBuilder.setAnnotations( - Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED))); - } + + methodDefBuilder = methodDefBuilder.setAnnotations(createMethodAnnotations(method, typeStore)); return methodDefBuilder .setHeaderCommentStatements( @@ -1774,6 +1779,7 @@ private static TypeStore createTypes(Service service, Map messa ApiFutures.class, BackgroundResource.class, BetaApi.class, + InternalApi.class, BidiStreamingCallable.class, ClientStreamingCallable.class, Generated.class, @@ -1828,7 +1834,7 @@ private static void createVaporTypes(Service service, TypeStore typeStore) { service.pakkage(), service.methods().stream() .filter(m -> m.isPaged()) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service)); @@ -1846,7 +1852,7 @@ private static List getGenericsForCallable( return Arrays.asList( method.inputType().reference(), typeStore - .get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) + .get(String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) .reference()); } return Arrays.asList(method.inputType().reference(), method.outputType().reference()); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java index d4bf61034c..175d45bc41 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java @@ -47,6 +47,7 @@ import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.model.Field; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicClass.Kind; @@ -87,7 +88,6 @@ public abstract class AbstractServiceClientTestClassComposer implements ClassCom protected static final String CLIENT_VAR_NAME = "client"; private static final String MOCK_SERVICE_VAR_NAME_PATTERN = "mock%s"; - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; protected static final TypeStore FIXED_TYPESTORE = createStaticTypes(); protected static final AnnotationNode TEST_ANNOTATION = @@ -944,7 +944,7 @@ private void addDynamicTypes(GapicContext context, Service service, TypeStore ty service.pakkage(), service.methods().stream() .filter(m -> m.isPaged()) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service)); @@ -956,7 +956,7 @@ private void addDynamicTypes(GapicContext context, Service service, TypeStore ty } typeStore.put( service.pakkage(), - String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, mixinMethod.name()), + String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, mixinMethod.name()), true, ClassNames.getServiceClientClassName(service)); } @@ -995,7 +995,7 @@ protected static TypeNode getCallableType(Method protoMethod) { private static TypeNode getPagedResponseType(Method method, Service service) { return TypeNode.withReference( VaporReference.builder() - .setName(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) + .setName(String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) .setPakkage(service.pakkage()) .setEnclosingClassNames(ClassNames.getServiceClientClassName(service)) .setIsStaticImport(true) diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java index a54d5ced0c..e117097b10 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java @@ -16,6 +16,7 @@ import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -55,6 +56,7 @@ import com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicClass.Kind; @@ -70,7 +72,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -81,10 +82,7 @@ public abstract class AbstractServiceSettingsClassComposer implements ClassComposer { private static final String BUILDER_CLASS_NAME = "Builder"; - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; - private static final String OPERATION_SETTINGS_LITERAL = "OperationSettings"; - private static final String SETTINGS_LITERAL = "Settings"; protected static final TypeStore FIXED_TYPESTORE = createStaticTypes(); private final TransportContext transportContext; @@ -97,6 +95,21 @@ protected TransportContext getTransportContext() { return transportContext; } + private static List createMethodAnnotations(Method method) { + List annotations = new ArrayList<>(); + if (method.isDeprecated()) { + annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); + } + + if (method.isInternalApi()) { + annotations.add( + AnnotationNode.withTypeAndDescription( + FIXED_TYPESTORE.get("InternalApi"), CommonStrings.INTERNAL_API_WARNING)); + } + + return annotations; + } + @Override public GapicClass generate(GapicContext context, Service service) { String pakkage = service.pakkage(); @@ -133,16 +146,21 @@ public GapicClass generate(GapicContext context, Service service) { private static List createClassHeaderComments( Service service, TypeNode classType, List samples) { - // Pick the first pure unary rpc method, if no such method exists, then pick the first in the + // Pick the first public pure unary rpc method, if no such method exists, then pick the first + // public in the // list. + List publicMethods = + service.methods().stream() + .filter(m -> m.isInternalApi() == false) + .collect(Collectors.toList()); Optional methodOpt = - service.methods().isEmpty() + publicMethods.isEmpty() ? Optional.empty() : Optional.of( - service.methods().stream() + publicMethods.stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() - .orElse(service.methods().get(0))); + .orElse(publicMethods.get(0))); Optional methodNameOpt = methodOpt.isPresent() ? Optional.of(methodOpt.get().name()) : Optional.empty(); Optional sampleCode = @@ -156,9 +174,9 @@ private static List createClassHeaderComments( // Create a sample for a LRO method using LRO-specific RetrySettings, if one exists in the // service. Optional lroMethodOpt = - service.methods().isEmpty() + publicMethods.isEmpty() ? Optional.empty() - : service.methods().stream() + : publicMethods.stream() .filter(m -> m.stream() == Stream.NONE && m.hasLro()) .findFirst(); Optional lroMethodNameOpt = @@ -270,40 +288,36 @@ private static List createSettingsGetterMethods( List javaMethods = new ArrayList<>(); for (Method protoMethod : service.methods()) { String javaStyleName = JavaStyle.toLowerCamelCase(protoMethod.name()); - String javaMethodName = - String.format("%sSettings", JavaStyle.toLowerCamelCase(protoMethod.name())); + String javaMethodName = String.format("%sSettings", javaStyleName); MethodDefinition.Builder methodBuilder = methodMakerFn.apply(getCallSettingsType(protoMethod, typeStore), javaMethodName); - javaMethods.add( - methodBuilder - .setHeaderCommentStatements( - SettingsCommentComposer.createCallSettingsGetterComment( - getMethodNameFromSettingsVarName(javaMethodName), protoMethod.isDeprecated())) - .setAnnotations( - protoMethod.isDeprecated() - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList()) - .build()); + javaMethods.add(methodBuilderHelper(protoMethod, methodBuilder, javaMethodName)); if (protoMethod.hasLro()) { - javaMethodName = String.format("%sOperationSettings", javaStyleName); + String javaOperationSettingsMethodName = + String.format("%sOperationSettings", javaStyleName); methodBuilder = - methodMakerFn.apply(getOperationCallSettingsType(protoMethod), javaMethodName); + methodMakerFn.apply( + getOperationCallSettingsType(protoMethod), javaOperationSettingsMethodName); javaMethods.add( - methodBuilder - .setHeaderCommentStatements( - SettingsCommentComposer.createCallSettingsGetterComment( - getMethodNameFromSettingsVarName(javaMethodName), - protoMethod.isDeprecated())) - .setAnnotations( - protoMethod.isDeprecated() - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList()) - .build()); + methodBuilderHelper(protoMethod, methodBuilder, javaOperationSettingsMethodName)); } } return javaMethods; } + // Add method header comment statements and annotations. + private static MethodDefinition methodBuilderHelper( + Method protoMethod, MethodDefinition.Builder methodBuilder, String javaMethodName) { + return methodBuilder + .setHeaderCommentStatements( + SettingsCommentComposer.createCallSettingsGetterComment( + getMethodNameFromSettingsVarName(javaMethodName), + protoMethod.isDeprecated(), + protoMethod.isInternalApi())) + .setAnnotations(createMethodAnnotations(protoMethod)) + .build(); + } + private static MethodDefinition createCreatorMethod(Service service, TypeStore typeStore) { TypeNode stubClassType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service)); VariableExpr stubVarExpr = @@ -771,11 +785,10 @@ private static List createNestedBuilderSettingsGetterMethods( methodBuilder .setHeaderCommentStatements( SettingsCommentComposer.createCallSettingsBuilderGetterComment( - getMethodNameFromSettingsVarName(javaMethodName), protoMethod.isDeprecated())) - .setAnnotations( - protoMethod.isDeprecated() - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList()) + getMethodNameFromSettingsVarName(javaMethodName), + protoMethod.isDeprecated(), + protoMethod.isInternalApi())) + .setAnnotations(createMethodAnnotations(protoMethod)) .build()); if (protoMethod.hasLro()) { @@ -787,11 +800,9 @@ private static List createNestedBuilderSettingsGetterMethods( .setHeaderCommentStatements( SettingsCommentComposer.createCallSettingsBuilderGetterComment( getMethodNameFromSettingsVarName(javaMethodName), - protoMethod.isDeprecated())) - .setAnnotations( - protoMethod.isDeprecated() - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList()) + protoMethod.isDeprecated(), + protoMethod.isInternalApi())) + .setAnnotations(createMethodAnnotations(protoMethod)) .build()); } } @@ -822,6 +833,7 @@ private static TypeStore createStaticTypes() { ApiClientHeaderProvider.class, ApiFunction.class, BetaApi.class, + InternalApi.class, ClientContext.class, ClientSettings.class, Generated.class, @@ -862,7 +874,7 @@ private static TypeStore createDynamicTypes(Service service) { service.pakkage(), service.methods().stream() .filter(m -> m.isPaged()) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service)); @@ -939,7 +951,8 @@ private static TypeNode getCallSettingsTypeHelper( if (protoMethod.isPaged()) { generics.add( typeStore - .get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, protoMethod.name())) + .get( + String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, protoMethod.name())) .reference()); } @@ -960,11 +973,11 @@ private static TypeNode getStubSettingsBuilderType(Service service) { private static String getMethodNameFromSettingsVarName(String settingsVarName) { BiFunction methodNameSubstrFn = (s, literal) -> s.substring(0, s.length() - literal.length()); - if (settingsVarName.endsWith(OPERATION_SETTINGS_LITERAL)) { - return methodNameSubstrFn.apply(settingsVarName, OPERATION_SETTINGS_LITERAL); + if (settingsVarName.endsWith(CommonStrings.OPERATION_SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, CommonStrings.OPERATION_SETTINGS_LITERAL); } - if (settingsVarName.endsWith(SETTINGS_LITERAL)) { - return methodNameSubstrFn.apply(settingsVarName, SETTINGS_LITERAL); + if (settingsVarName.endsWith(CommonStrings.SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, CommonStrings.SETTINGS_LITERAL); } return settingsVarName; } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java index 312de889b6..5cdb08ff10 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java @@ -15,6 +15,7 @@ package com.google.api.generator.gapic.composer.common; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientStreamingCallable; @@ -34,6 +35,7 @@ import com.google.api.generator.gapic.composer.comment.StubCommentComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicClass.Kind; @@ -54,7 +56,6 @@ import javax.annotation.Generated; public abstract class AbstractServiceStubClassComposer implements ClassComposer { - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private final TransportContext transportContext; @@ -189,16 +190,21 @@ private MethodDefinition createCallableGetterHelper( } else if (isPaged) { genericRefs.add( typeStore - .get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) + .get(String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) .reference()); } else { genericRefs.add(method.outputType().reference()); } - List annotations = - method.isDeprecated() - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList(); + List annotations = new ArrayList<>(); + if (method.isDeprecated()) { + annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); + } + if (method.isInternalApi()) { + annotations.add( + AnnotationNode.withTypeAndDescription( + typeStore.get("InternalApi"), CommonStrings.INTERNAL_API_WARNING)); + } returnType = TypeNode.withReference(returnType.reference().copyAndSetGenerics(genericRefs)); @@ -256,6 +262,7 @@ private static TypeStore createTypes(Service service, Map messa Arrays.asList( BackgroundResource.class, BetaApi.class, + InternalApi.class, BidiStreamingCallable.class, ClientStreamingCallable.class, Generated.class, @@ -273,7 +280,7 @@ private static TypeStore createTypes(Service service, Map messa service.pakkage(), service.methods().stream() .filter(m -> m.isPaged()) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service)); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java index 2002cb6c6c..6357ee3f3c 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; import com.google.api.gax.batching.BatchingSettings; import com.google.api.gax.batching.FlowControlSettings; @@ -83,6 +84,7 @@ import com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer; import com.google.api.generator.gapic.composer.store.TypeStore; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.Field; import com.google.api.generator.gapic.model.GapicBatchingSettings; @@ -128,17 +130,12 @@ public abstract class AbstractServiceStubSettingsClassComposer implements ClassC private static final String BATCHING_DESC_PATTERN = "%s_BATCHING_DESC"; private static final String PAGE_STR_DESC_PATTERN = "%s_PAGE_STR_DESC"; private static final String PAGED_RESPONSE_FACTORY_PATTERN = "%s_PAGE_STR_FACT"; - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private static final String NESTED_BUILDER_CLASS_NAME = "Builder"; private static final String NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_NAME = "unaryMethodSettingsBuilders"; private static final String NESTED_RETRYABLE_CODE_DEFINITIONS_VAR_NAME = "RETRYABLE_CODE_DEFINITIONS"; private static final String NESTED_RETRY_PARAM_DEFINITIONS_VAR_NAME = "RETRY_PARAM_DEFINITIONS"; - - private static final String OPERATION_SETTINGS_LITERAL = "OperationSettings"; - private static final String SETTINGS_LITERAL = "Settings"; - private static final String DOT = "."; protected static final TypeStore FIXED_TYPESTORE = createStaticTypes(); @@ -173,13 +170,15 @@ public GapicClass generate(GapicContext context, Service service) { List samples = new ArrayList<>(); Set deprecatedSettingVarNames = new HashSet<>(); + Set internalSettingVarNames = new HashSet<>(); Map methodSettingsMemberVarExprs = createMethodSettingsClassMemberVarExprs( service, serviceConfig, typeStore, /* isNestedClass= */ false, - deprecatedSettingVarNames); + deprecatedSettingVarNames, + internalSettingVarNames); String className = ClassNames.getServiceStubSettingsClassName(service); List classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples); @@ -196,7 +195,11 @@ public GapicClass generate(GapicContext context, Service service) { service, serviceConfig, methodSettingsMemberVarExprs, messageTypes, typeStore)) .setMethods( createClassMethods( - service, methodSettingsMemberVarExprs, deprecatedSettingVarNames, typeStore)) + service, + methodSettingsMemberVarExprs, + deprecatedSettingVarNames, + internalSettingVarNames, + typeStore)) .setNestedClasses( Arrays.asList(createNestedBuilderClass(service, serviceConfig, typeStore))) .build(); @@ -410,16 +413,21 @@ private List createClassAnnotations(Service service) { private static List createClassHeaderComments( Service service, TypeNode classType, List samples) { - // Pick the first pure unary rpc method, if no such method exists, then pick the first in the + // Pick the first public pure unary rpc method, if no such method exists, then pick the first + // public in the // list. + List publicMethods = + service.methods().stream() + .filter(m -> m.isInternalApi() == false) + .collect(Collectors.toList()); Optional methodOpt = - service.methods().isEmpty() + publicMethods.isEmpty() ? Optional.empty() : Optional.of( - service.methods().stream() + publicMethods.stream() .filter(m -> m.stream() == Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() - .orElse(service.methods().get(0))); + .orElse(publicMethods.get(0))); Optional methodNameOpt = methodOpt.map(Method::name); Optional sampleCode = @@ -433,9 +441,9 @@ private static List createClassHeaderComments( // Create a sample for a LRO method using LRO-specific RetrySettings, if one exists in the // service. Optional lroMethodOpt = - service.methods().isEmpty() + publicMethods.isEmpty() ? Optional.empty() - : service.methods().stream() + : publicMethods.stream() .filter(m -> m.stream() == Stream.NONE && m.hasLro()) .findFirst(); Optional lroMethodNameOpt = @@ -475,7 +483,8 @@ private static Map createMethodSettingsClassMemberVarExprs GapicServiceConfig serviceConfig, TypeStore typeStore, boolean isNestedClass, - Set deprecatedSettingVarNames) { + Set deprecatedSettingVarNames, + Set internalSettingVarNames) { // Maintain insertion order. Map varExprs = new LinkedHashMap<>(); @@ -489,6 +498,9 @@ private static Map createMethodSettingsClassMemberVarExprs if (method.isDeprecated()) { deprecatedSettingVarNames.add(varName); } + if (method.isInternalApi()) { + internalSettingVarNames.add(varName); + } varExprs.put( varName, VariableExpr.withVariable( @@ -978,10 +990,12 @@ private List createClassMethods( Service service, Map methodSettingsMemberVarExprs, Set deprecatedSettingVarNames, + Set internalSettingVarNames, TypeStore typeStore) { List javaMethods = new ArrayList<>(); javaMethods.addAll( - createMethodSettingsGetterMethods(methodSettingsMemberVarExprs, deprecatedSettingVarNames)); + createMethodSettingsGetterMethods( + methodSettingsMemberVarExprs, deprecatedSettingVarNames, internalSettingVarNames)); javaMethods.add(createCreateStubMethod(service, typeStore)); javaMethods.addAll(createDefaultHelperAndGetterMethods(service, typeStore)); javaMethods.addAll( @@ -996,20 +1010,33 @@ private List createClassMethods( return javaMethods; } + private static List createMethodAnnotation( + boolean isDeprecated, boolean isInternal) { + List annotations = new ArrayList<>(); + if (isDeprecated) { + annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); + } + if (isInternal) { + annotations.add( + AnnotationNode.withTypeAndDescription( + FIXED_TYPESTORE.get("InternalApi"), CommonStrings.INTERNAL_API_WARNING)); + } + return annotations; + } + private static List createMethodSettingsGetterMethods( Map methodSettingsMemberVarExprs, - final Set deprecatedSettingVarNames) { + final Set deprecatedSettingVarNames, + final Set internalSettingVarNames) { Function, MethodDefinition> varToMethodFn = e -> { boolean isDeprecated = deprecatedSettingVarNames.contains(e.getKey()); + boolean isInternal = internalSettingVarNames.contains(e.getKey()); return MethodDefinition.builder() .setHeaderCommentStatements( SettingsCommentComposer.createCallSettingsGetterComment( - getMethodNameFromSettingsVarName(e.getKey()), isDeprecated)) - .setAnnotations( - isDeprecated - ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) - : Collections.emptyList()) + getMethodNameFromSettingsVarName(e.getKey()), isDeprecated, isInternal)) + .setAnnotations(createMethodAnnotation(isDeprecated, isInternal)) .setScope(ScopeNode.PUBLIC) .setReturnType(e.getValue().type()) .setName(e.getKey()) @@ -1348,13 +1375,15 @@ private ClassDefinition createNestedBuilderClass( .build()); Set nestedDeprecatedSettingVarNames = new HashSet<>(); + Set nestedInternalSettingVarNames = new HashSet<>(); Map nestedMethodSettingsMemberVarExprs = createMethodSettingsClassMemberVarExprs( service, serviceConfig, typeStore, /* isNestedClass= */ true, - nestedDeprecatedSettingVarNames); + nestedDeprecatedSettingVarNames, + nestedInternalSettingVarNames); // TODO(miraleung): Fill this out. return ClassDefinition.builder() @@ -1375,6 +1404,7 @@ private ClassDefinition createNestedBuilderClass( extendsType, nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames, + nestedInternalSettingVarNames, typeStore)) .build(); } @@ -1435,6 +1465,7 @@ private List createNestedClassMethods( TypeNode superType, Map nestedMethodSettingsMemberVarExprs, Set nestedDeprecatedSettingVarNames, + Set nestedInternalSettingVarNames, TypeStore typeStore) { List nestedClassMethods = new ArrayList<>(); nestedClassMethods.addAll( @@ -1446,7 +1477,9 @@ private List createNestedClassMethods( nestedClassMethods.add(createNestedClassUnaryMethodSettingsBuilderGetterMethod()); nestedClassMethods.addAll( createNestedClassSettingsBuilderGetterMethods( - nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames)); + nestedMethodSettingsMemberVarExprs, + nestedDeprecatedSettingVarNames, + nestedInternalSettingVarNames)); nestedClassMethods.add(createNestedClassBuildMethod(service, typeStore)); return nestedClassMethods; } @@ -1598,7 +1631,7 @@ private static List createNestedClassConstructorMethods( VariableExpr varExpr = e.getValue(); TypeNode varType = varExpr.type(); Preconditions.checkState( - e.getKey().endsWith(SETTINGS_LITERAL), + e.getKey().endsWith(CommonStrings.SETTINGS_LITERAL), String.format("%s expected to end with \"Settings\"", e.getKey())); String methodName = getMethodNameFromSettingsVarName(e.getKey()); @@ -1964,7 +1997,8 @@ private static MethodDefinition createNestedClassUnaryMethodSettingsBuilderGette private static List createNestedClassSettingsBuilderGetterMethods( Map nestedMethodSettingsMemberVarExprs, - Set nestedDeprecatedSettingVarNames) { + Set nestedDeprecatedSettingVarNames, + Set nestedInternalSettingVarNames) { Reference operationCallSettingsBuilderRef = ConcreteReference.withClazz(OperationCallSettings.Builder.class); Function isOperationCallSettingsBuilderFn = @@ -1972,26 +2006,22 @@ private static List createNestedClassSettingsBuilderGetterMeth t.reference() .copyAndSetGenerics(ImmutableList.of()) .equals(operationCallSettingsBuilderRef); - AnnotationNode deprecatedAnnotation = AnnotationNode.withType(TypeNode.DEPRECATED); List javaMethods = new ArrayList<>(); for (Map.Entry settingsVarEntry : nestedMethodSettingsMemberVarExprs.entrySet()) { String varName = settingsVarEntry.getKey(); VariableExpr settingsVarExpr = settingsVarEntry.getValue(); - List annotations = new ArrayList<>(); boolean isDeprecated = nestedDeprecatedSettingVarNames.contains(varName); - if (isDeprecated) { - annotations.add(deprecatedAnnotation); - } + boolean isInternal = nestedInternalSettingVarNames.contains(varName); javaMethods.add( MethodDefinition.builder() .setHeaderCommentStatements( SettingsCommentComposer.createCallSettingsBuilderGetterComment( - getMethodNameFromSettingsVarName(varName), isDeprecated)) - .setAnnotations(annotations) + getMethodNameFromSettingsVarName(varName), isDeprecated, isInternal)) + .setAnnotations(createMethodAnnotation(isDeprecated, isInternal)) .setScope(ScopeNode.PUBLIC) .setReturnType(settingsVarExpr.type()) .setName(settingsVarExpr.variable().identifier().name()) @@ -2032,6 +2062,7 @@ private static TypeStore createStaticTypes() { BatchingDescriptor.class, BatchingSettings.class, BetaApi.class, + InternalApi.class, ClientContext.class, Duration.class, Empty.class, @@ -2093,7 +2124,7 @@ private TypeStore createDynamicTypes(Service service, String pakkage) { service.pakkage(), service.methods().stream() .filter(m -> m.isPaged()) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service)); @@ -2172,7 +2203,8 @@ private static VariableExpr createNestedRetryParamDefinitionsVarExpr() { } private static String getPagedResponseTypeName(String methodName) { - return String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, JavaStyle.toUpperCamelCase(methodName)); + return String.format( + CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, JavaStyle.toUpperCamelCase(methodName)); } private static TypeNode getCallSettingsType( @@ -2250,11 +2282,11 @@ private static TypeNode getOperationCallSettingsType(Method method, boolean isSe private static String getMethodNameFromSettingsVarName(String settingsVarName) { BiFunction methodNameSubstrFn = (s, literal) -> s.substring(0, s.length() - literal.length()); - if (settingsVarName.endsWith(OPERATION_SETTINGS_LITERAL)) { - return methodNameSubstrFn.apply(settingsVarName, OPERATION_SETTINGS_LITERAL); + if (settingsVarName.endsWith(CommonStrings.OPERATION_SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, CommonStrings.OPERATION_SETTINGS_LITERAL); } - if (settingsVarName.endsWith(SETTINGS_LITERAL)) { - return methodNameSubstrFn.apply(settingsVarName, SETTINGS_LITERAL); + if (settingsVarName.endsWith(CommonStrings.SETTINGS_LITERAL)) { + return methodNameSubstrFn.apply(settingsVarName, CommonStrings.SETTINGS_LITERAL); } return settingsVarName; } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java index 6ebdfe6ed7..2a20ab21d0 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java @@ -58,6 +58,7 @@ import com.google.api.generator.engine.ast.VariableExpr; import com.google.api.generator.gapic.composer.comment.StubCommentComposer; import com.google.api.generator.gapic.composer.store.TypeStore; +import com.google.api.generator.gapic.composer.utils.CommonStrings; import com.google.api.generator.gapic.composer.utils.PackageChecker; import com.google.api.generator.gapic.model.Field; import com.google.api.generator.gapic.model.GapicClass; @@ -101,7 +102,6 @@ public abstract class AbstractTransportServiceStubClassComposer implements Class private static final Statement EMPTY_LINE_STATEMENT = EmptyLineStatement.create(); private static final String METHOD_DESCRIPTOR_NAME_PATTERN = "%sMethodDescriptor"; - private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private static final String PAGED_CALLABLE_CLASS_MEMBER_PATTERN = "%sPagedCallable"; private static final String BACKGROUND_RESOURCES_MEMBER_NAME = "backgroundResources"; @@ -491,7 +491,8 @@ private VariableExpr getPagedCallableExpr( typeStore .get( String.format( - PAGED_RESPONSE_TYPE_NAME_PATTERN, protoMethod.name())) + CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, + protoMethod.name())) .reference())))) .build()); } @@ -1239,7 +1240,7 @@ private TypeStore createDynamicTypes(Service service, String stubPakkage) { service.methods().stream() .filter(x -> x.isSupportedByTransport(getTransportContext().transport())) .filter(Method::isPaged) - .map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) + .map(m -> String.format(CommonStrings.PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())) .collect(Collectors.toList()), true, getTransportContext().classNames().getServiceClientClassName(service)); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java index 6181a2e9ae..c4e38e24a3 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java @@ -52,13 +52,23 @@ public static Sample composeClassHeaderSample( TypeNode clientType, Map resourceNames, Map messageTypes) { - // Use the first pure unary RPC method's sample code as showcase, if no such method exists, use - // the first method in the service's methods list. - Method method = + List publicMethods = service.methods().stream() + .filter(m -> m.isInternalApi() == false) + .collect(Collectors.toList()); + + // If all generated methods are INTERNAL, generate an empty service sample. + if (publicMethods.isEmpty()) { + return ServiceClientMethodSampleComposer.composeEmptyServiceSample(clientType, service); + } + + // Use the first public pure unary RPC method's sample code as showcase, if no such method + // exists, use the first public method in the service's methods list. + Method method = + publicMethods.stream() .filter(m -> m.stream() == Method.Stream.NONE && !m.hasLro() && !m.isPaged()) .findFirst() - .orElse(service.methods().get(0)); + .orElse(publicMethods.get(0)); if (method.stream() == Method.Stream.NONE) { if (method.methodSignatures().isEmpty()) { diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/utils/CommonStrings.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/utils/CommonStrings.java new file mode 100644 index 0000000000..201e50e8e7 --- /dev/null +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/utils/CommonStrings.java @@ -0,0 +1,24 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.api.generator.gapic.composer.utils; + +/** Provides Gapic common strings. */ +public class CommonStrings { + public static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; + public static final String INTERNAL_API_WARNING = + "This API is not intended for public consumption."; + public static final String SETTINGS_LITERAL = "Settings"; + public static final String OPERATION_SETTINGS_LITERAL = "OperationSettings"; +} diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Method.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Method.java index f8f815cc08..66acd065a3 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Method.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Method.java @@ -38,6 +38,8 @@ public enum Stream { public abstract TypeNode outputType(); + public abstract boolean isInternalApi(); + public abstract boolean isBatching(); public boolean isPaged() { @@ -136,6 +138,7 @@ public static Builder builder() { .setStream(Stream.NONE) .setAutoPopulatedFields(new ArrayList<>()) .setMethodSignatures(ImmutableList.of()) + .setIsInternalApi(false) .setIsBatching(false) .setIsDeprecated(false) .setOperationPollingMethod(false); @@ -162,6 +165,8 @@ public abstract static class Builder { public abstract Builder setOutputType(TypeNode outputType); + public abstract Builder setIsInternalApi(boolean isInternalApi); + public abstract Builder setStream(Stream stream); public abstract Builder setLro(LongrunningOperation lro); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index 2e17b9026b..975ccf58fa 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -25,6 +25,7 @@ import com.google.api.MethodSettings; import com.google.api.ResourceDescriptor; import com.google.api.ResourceProto; +import com.google.api.SelectiveGapicGeneration; import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.engine.ast.VaporReference; import com.google.api.generator.gapic.model.Field; @@ -91,6 +92,14 @@ import java.util.stream.IntStream; public class Parser { + enum SelectiveGapicType { + // Methods will be generated and exposed externally as usual. + PUBLIC, + // Methods will not be generated. + HIDDEN, + // Methods will be generated and tagged @InternalApi (internal use) during generation. + INTERNAL + } private static final Logger LOGGER = Logger.getLogger(Parser.class.getName()); private static final String COMMA = ","; @@ -427,14 +436,14 @@ public static List parseService( Transport.GRPC); } - static boolean shouldIncludeMethodInGeneration( + static SelectiveGapicType getMethodSelectiveGapicType( MethodDescriptor method, Optional serviceYamlProtoOpt, String protoPackage) { // default to include all when no service yaml or no library setting section. if (!serviceYamlProtoOpt.isPresent() || serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsCount() == 0) { - return true; + return SelectiveGapicType.PUBLIC; } List librarySettingsList = serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsList(); @@ -451,45 +460,55 @@ static boolean shouldIncludeMethodInGeneration( + "Disregarding selective generation settings.", librarySettingsList.get(0).getVersion(), protoPackage)); } - return true; + return SelectiveGapicType.PUBLIC; } // librarySettingsList is technically a list, but is processed upstream and // only leave with 1 element. Otherwise, it is a misconfiguration and // should be caught upstream. - List includeMethodsList = - librarySettingsList - .get(0) - .getJavaSettings() - .getCommon() - .getSelectiveGapicGeneration() - .getMethodsList(); - // default to include all when nothing specified, this could be no java section - // specified in library setting, or the method list is empty - if (includeMethodsList.isEmpty()) { - return true; + SelectiveGapicGeneration selectiveGapicGenerationConfig = + librarySettingsList.get(0).getJavaSettings().getCommon().getSelectiveGapicGeneration(); + + List includeMethodsList = selectiveGapicGenerationConfig.getMethodsList(); + + Boolean generateOmittedAsInternal = + selectiveGapicGenerationConfig.getGenerateOmittedAsInternal(); + + // Set method to PUBLIC if no SelectiveGapicGeneration Configuration is configured and + // GenerateOmittedAsInternal is false. + if (includeMethodsList.isEmpty() && generateOmittedAsInternal == false) { + return SelectiveGapicType.PUBLIC; + } + + // Set method to PUBLIC if the method is in the allow list. + if (includeMethodsList.contains(method.getFullName())) { + return SelectiveGapicType.PUBLIC; } + // Otherwise, generate this method as INTERNAL or HIDDEN based on GenerateOmittedAsInternal + // flag. - return includeMethodsList.contains(method.getFullName()); + return generateOmittedAsInternal ? SelectiveGapicType.INTERNAL : SelectiveGapicType.HIDDEN; } + // A service is considered empty if it contains no methods, or only methods marked as HIDDEN. private static boolean isEmptyService( ServiceDescriptor serviceDescriptor, Optional serviceYamlProtoOpt, String protoPackage) { List methodsList = serviceDescriptor.getMethods(); - List methodListSelected = + List methodListNotHidden = methodsList.stream() .filter( method -> - shouldIncludeMethodInGeneration(method, serviceYamlProtoOpt, protoPackage)) + getMethodSelectiveGapicType(method, serviceYamlProtoOpt, protoPackage) + != SelectiveGapicType.HIDDEN) .collect(Collectors.toList()); - if (methodListSelected.isEmpty()) { + if (methodListNotHidden.isEmpty()) { LOGGER.log( Level.WARNING, - "Service {0} has no RPC methods and will not be generated", + "Service {0} has no public or internal RPC methods and will not be generated", serviceDescriptor.getName()); } - return methodListSelected.isEmpty(); + return methodListNotHidden.isEmpty(); } public static List parseService( @@ -785,7 +804,10 @@ static List parseMethods( Map> autoPopulatedMethodsWithFields = parseAutoPopulatedMethodsAndFields(serviceYamlProtoOpt); for (MethodDescriptor protoMethod : serviceDescriptor.getMethods()) { - if (!shouldIncludeMethodInGeneration(protoMethod, serviceYamlProtoOpt, protoPackage)) { + SelectiveGapicType methodSelectiveGapicType = + getMethodSelectiveGapicType(protoMethod, serviceYamlProtoOpt, protoPackage); + // Skip generation for methods marked as HIDDEN + if (methodSelectiveGapicType == SelectiveGapicType.HIDDEN) { continue; } // Parse the method. @@ -838,6 +860,7 @@ static List parseMethods( .setName(protoMethod.getName()) .setInputType(inputType) .setOutputType(TypeParser.parseType(protoMethod.getOutputType())) + .setIsInternalApi(methodSelectiveGapicType == SelectiveGapicType.INTERNAL) .setStream( Method.toStream(protoMethod.isClientStreaming(), protoMethod.isServerStreaming())) .setLro(parseLro(servicePackage, protoMethod, messageTypes)) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java index 2d39575e81..4919e5982b 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java @@ -188,8 +188,9 @@ void createJavaDocComment_multipleParamsAndReturn() { } @Test - void createJavaDocComment_throwsAndDeprecatedAndReturn() { - // No matter how many times or order `setThrows`, `setDeprecated`, `setReturn` are called, + void createJavaDocComment_throwsAndDeprecatedAndInternalAndReturn() { + // No matter how many times or order `setThrows`, `setDeprecated`, `setInternalOnly`, + // `setReturn` are called, // only one @throws, @deprecated, and @return will be printed. String throwsType = "com.google.api.gax.rpc.ApiException"; String throwsDescription = "if the remote call fails."; @@ -199,6 +200,9 @@ void createJavaDocComment_throwsAndDeprecatedAndReturn() { String deprecatedText = "Use the {@link ArchivedBookName} class instead."; String deprecatedText_print = "Use the {@link ShelfBookName} class instead."; + String internalOnlyText = + "This method is for internal use only. Please do not use it directly."; + String returnText = "This is the incorrect method return text."; String returnText_print = "This is the correct method return text."; @@ -207,12 +211,14 @@ void createJavaDocComment_throwsAndDeprecatedAndReturn() { .setThrows(throwsType, throwsDescription) .setDeprecated(deprecatedText) .setReturn(returnText) + .setInternalOnly(internalOnlyText) .setThrows(throwsType_print, throwsDescription_print) .setDeprecated(deprecatedText_print) .setReturn(returnText_print) .build(); String expected = LineFormatter.lines( + "

Warning: This method is for internal use only. Please do not use it directly.\n", "@throws java.lang.RuntimeException if the remote call fails.\n", "@deprecated Use the {@link ShelfBookName} class instead.\n", "@return This is the correct method return text."); @@ -223,10 +229,13 @@ void createJavaDocComment_throwsAndDeprecatedAndReturn() { void createJavaDocComment_allComponents() { // No matter what order `setThrows`, `setDeprecated`, and `setReturn` are called, // They will be printed at the end. And `@param` should be grouped, - // they should always be printed right before `@throws`, `@deprecated`, and `@return`. + // they should always be printed right before `@throws`, `@deprecated` and + // `@return`. // All other add methods should keep the order of how they are added. String content = "this is a test comment"; String deprecatedText = "Use the {@link ArchivedBookName} class instead."; + String internalOnlyText = + "This method is for internal use only. Please do not use it directly."; String returnText = "This is the method return text."; String paramName1 = "shelfName"; String paramDescription1 = "The name of the shelf where books are published to."; @@ -253,6 +262,7 @@ void createJavaDocComment_allComponents() { .addParagraph(paragraph2) .addOrderedList(orderedList) .addParam(paramName2, paramDescription2) + .setInternalOnly(internalOnlyText) .build(); String expected = LineFormatter.lines( @@ -266,6 +276,7 @@ void createJavaDocComment_allComponents() { "

  • A request object method.\n", "
  • A callable method.\n", "\n", + "

    Warning: This method is for internal use only. Please do not use it directly.\n", "@param shelfName The name of the shelf where books are published to.\n", "@param shelf The shelf to create.\n", "@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n", diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java index 7df2fc017c..2654eb6015 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java @@ -33,27 +33,38 @@ private static Stream data() { "EchoClient", GrpcTestProtoLoader.instance().parseShowcaseEcho(), "localhost:7469", - "v1beta1"), + "v1beta1", + 0), Arguments.of( "DeprecatedServiceClient", GrpcTestProtoLoader.instance().parseDeprecatedService(), "localhost:7469", - "v1"), + "v1", + 0), Arguments.of( "IdentityClient", GrpcTestProtoLoader.instance().parseShowcaseIdentity(), "localhost:7469", - "v1beta1"), + "v1beta1", + 0), Arguments.of( "BookshopClient", GrpcTestProtoLoader.instance().parseBookshopService(), "localhost:2665", - "v1beta1"), + "v1beta1", + 0), Arguments.of( "MessagingClient", GrpcTestProtoLoader.instance().parseShowcaseMessaging(), "localhost:7469", - "v1beta1")); + "v1beta1", + 0), + Arguments.of( + "EchoServiceSelectiveGapicClient", + GrpcTestProtoLoader.instance().parseSelectiveGenerationTesting(), + "localhost:7469", + "v1beta1", + 1)); } @ParameterizedTest @@ -62,8 +73,9 @@ void generateServiceClientClasses( String name, GapicContext context, String apiShortNameExpected, - String packageVersionExpected) { - Service service = context.services().get(0); + String packageVersionExpected, + int serviceIndex) { + Service service = context.services().get(serviceIndex); GapicClass clazz = ServiceClientClassComposer.instance().generate(context, service); Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden"); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java index 90e0df1a2a..da503cd09f 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java @@ -32,12 +32,20 @@ static Stream data() { "EchoSettings", TestProtoLoader.instance().parseShowcaseEcho(), "localhost:7469", - "v1beta1"), + "v1beta1", + 0), Arguments.of( "DeprecatedServiceSettings", TestProtoLoader.instance().parseDeprecatedService(), "localhost:7469", - "v1")); + "v1", + 0), + Arguments.of( + "EchoServiceSelectiveGapicServiceSettings", + TestProtoLoader.instance().parseSelectiveGenerationTesting(), + "localhost:7469", + "v1beta1", + 1)); } @ParameterizedTest @@ -46,8 +54,9 @@ void generateServiceSettingsClasses( String name, GapicContext context, String apiShortNameExpected, - String packageVersionExpected) { - Service service = context.services().get(0); + String packageVersionExpected, + int serviceIndex) { + Service service = context.services().get(serviceIndex); GapicClass clazz = ServiceSettingsClassComposer.instance().generate(context, service); Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden"); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java index 15317cab94..21d57f02b8 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java @@ -27,9 +27,19 @@ class ServiceStubClassComposerTest { static Stream data() { return Stream.of( - Arguments.of("EchoStub", TestProtoLoader.instance().parseShowcaseEcho(), "", ""), + Arguments.of("EchoStub", TestProtoLoader.instance().parseShowcaseEcho(), "", "", 0), Arguments.of( - "DeprecatedServiceStub", TestProtoLoader.instance().parseDeprecatedService(), "", "")); + "DeprecatedServiceStub", + TestProtoLoader.instance().parseDeprecatedService(), + "", + "", + 0), + Arguments.of( + "EchoServiceSelectiveGapicClientStub", + TestProtoLoader.instance().parseSelectiveGenerationTesting(), + "", + "", + 1)); } @ParameterizedTest @@ -38,8 +48,9 @@ void generateServiceStubClasses( String name, GapicContext context, String apiShortNameExpected, - String packageVersionExpected) { - Service service = context.services().get(0); + String packageVersionExpected, + int serviceIndex) { + Service service = context.services().get(serviceIndex); GapicClass clazz = ServiceStubClassComposer.instance().generate(context, service); Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden"); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java index 203b9f3894..fb6c34d451 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java @@ -31,27 +31,38 @@ static Stream data() { "LoggingServiceV2StubSettings", GrpcTestProtoLoader.instance().parseLogging(), "logging", - "v2"), + "v2", + 0), Arguments.of( "PublisherStubSettings", GrpcTestProtoLoader.instance().parsePubSubPublisher(), "pubsub", - "v1"), + "v1", + 0), Arguments.of( "EchoStubSettings", GrpcTestProtoLoader.instance().parseShowcaseEcho(), "localhost:7469", - "v1beta1"), + "v1beta1", + 0), Arguments.of( "DeprecatedServiceStubSettings", GrpcTestProtoLoader.instance().parseDeprecatedService(), "localhost:7469", - "v1"), + "v1", + 0), Arguments.of( "ApiVersionTestingStubSettings", GrpcTestProtoLoader.instance().parseApiVersionTesting(), "localhost:7469", - "v1")); + "v1", + 0), + Arguments.of( + "EchoServiceSelectiveGapicStubSettings", + GrpcTestProtoLoader.instance().parseSelectiveGenerationTesting(), + "localhost:7469", + "v1beta1", + 1)); } @ParameterizedTest @@ -60,8 +71,9 @@ void generateServiceStubSettingsClasses( String name, GapicContext context, String apiShortNameExpected, - String packageVersionExpected) { - Service service = context.services().get(0); + String packageVersionExpected, + int serviceIndex) { + Service service = context.services().get(serviceIndex); GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, service); Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden"); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClient.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClient.golden new file mode 100644 index 0000000000..731ebe1834 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClient.golden @@ -0,0 +1,641 @@ +package com.google.selective.generate.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.selective.generate.v1beta1.stub.EchoServiceShouldGeneratePartialUsualStub; +import com.google.selective.generate.v1beta1.stub.EchoServiceShouldGeneratePartialUsualStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * This class provides the ability to make remote calls to the backing service through method calls + * that map to API methods. Sample code to get started: + * + *

    {@code
    + * // This snippet has been automatically generated and should be regarded as a code template only.
    + * // It will require modifications to work:
    + * // - It may require correct/in-range values for request initialization.
    + * // - It may require specifying regional endpoints when creating the service client as shown in
    + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    + * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    + *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    + *   EchoResponse response =
    + *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual();
    + * }
    + * }
    + * + *

    Note: close() needs to be called on the EchoServiceShouldGeneratePartialUsualClient object to + * clean up resources such as threads. In the example above, try-with-resources is used, which + * automatically calls close(). + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Methods
    MethodDescriptionMethod Variants

    EchoShouldGenerateAsUsual

    + *

    Request object method variants only take one parameter, a request object, which must be constructed before the call.

    + *
      + *
    • echoShouldGenerateAsUsual(EchoRequest request) + *

    + *

    "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

    + *
      + *
    • echoShouldGenerateAsUsual() + *

    • echoShouldGenerateAsUsual(FoobarName name) + *

    • echoShouldGenerateAsUsual(String name) + *

    + *

    Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

    + *
      + *
    • echoShouldGenerateAsUsualCallable() + *

    + *

    ChatShouldGenerateAsUsual

    + *

    Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

    + *
      + *
    • chatShouldGenerateAsUsualCallable() + *

    + *

    ChatAgainShouldGenerateAsUsual

    + *

    Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

    + *
      + *
    • chatAgainShouldGenerateAsUsualCallable() + *

    + *

    ChatShouldGenerateAsInternal

    + *

    Request object method variants only take one parameter, a request object, which must be constructed before the call.

    + *
      + *
    • chatShouldGenerateAsInternal(EchoRequest request) + *

    + *

    "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

    + *
      + *
    • chatShouldGenerateAsInternal() + *

    • chatShouldGenerateAsInternal(FoobarName name) + *

    • chatShouldGenerateAsInternal(String name) + *

    + *

    Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

    + *
      + *
    • chatShouldGenerateAsInternalCallable() + *

    + *

    EchoShouldGenerateAsInternal

    + *

    Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

    + *
      + *
    • echoShouldGenerateAsInternalCallable() + *

    + *
    + * + *

    See the individual methods for example code. + * + *

    Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

    This class can be customized by passing in a custom instance of + * EchoServiceShouldGeneratePartialUsualSettings to create(). For example: + * + *

    To customize credentials: + * + *

    {@code
    + * // This snippet has been automatically generated and should be regarded as a code template only.
    + * // It will require modifications to work:
    + * // - It may require correct/in-range values for request initialization.
    + * // - It may require specifying regional endpoints when creating the service client as shown in
    + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    + * EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings =
    + *     EchoServiceShouldGeneratePartialUsualSettings.newBuilder()
    + *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    + *         .build();
    + * EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    + *     EchoServiceShouldGeneratePartialUsualClient.create(
    + *         echoServiceShouldGeneratePartialUsualSettings);
    + * }
    + * + *

    To customize the endpoint: + * + *

    {@code
    + * // This snippet has been automatically generated and should be regarded as a code template only.
    + * // It will require modifications to work:
    + * // - It may require correct/in-range values for request initialization.
    + * // - It may require specifying regional endpoints when creating the service client as shown in
    + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    + * EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings =
    + *     EchoServiceShouldGeneratePartialUsualSettings.newBuilder().setEndpoint(myEndpoint).build();
    + * EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    + *     EchoServiceShouldGeneratePartialUsualClient.create(
    + *         echoServiceShouldGeneratePartialUsualSettings);
    + * }
    + * + *

    Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoServiceShouldGeneratePartialUsualClient implements BackgroundResource { + private final EchoServiceShouldGeneratePartialUsualSettings settings; + private final EchoServiceShouldGeneratePartialUsualStub stub; + + /** + * Constructs an instance of EchoServiceShouldGeneratePartialUsualClient with default settings. + */ + public static final EchoServiceShouldGeneratePartialUsualClient create() throws IOException { + return create(EchoServiceShouldGeneratePartialUsualSettings.newBuilder().build()); + } + + /** + * Constructs an instance of EchoServiceShouldGeneratePartialUsualClient, using the given + * settings. The channels are created based on the settings passed in, or defaults for any + * settings that are not set. + */ + public static final EchoServiceShouldGeneratePartialUsualClient create( + EchoServiceShouldGeneratePartialUsualSettings settings) throws IOException { + return new EchoServiceShouldGeneratePartialUsualClient(settings); + } + + /** + * Constructs an instance of EchoServiceShouldGeneratePartialUsualClient, using the given stub for + * making calls. This is for advanced usage - prefer using + * create(EchoServiceShouldGeneratePartialUsualSettings). + */ + public static final EchoServiceShouldGeneratePartialUsualClient create( + EchoServiceShouldGeneratePartialUsualStub stub) { + return new EchoServiceShouldGeneratePartialUsualClient(stub); + } + + /** + * Constructs an instance of EchoServiceShouldGeneratePartialUsualClient, using the given + * settings. This is protected so that it is easy to make a subclass, but otherwise, the static + * factory methods should be preferred. + */ + protected EchoServiceShouldGeneratePartialUsualClient( + EchoServiceShouldGeneratePartialUsualSettings settings) throws IOException { + this.settings = settings; + this.stub = + ((EchoServiceShouldGeneratePartialUsualStubSettings) settings.getStubSettings()) + .createStub(); + } + + protected EchoServiceShouldGeneratePartialUsualClient( + EchoServiceShouldGeneratePartialUsualStub stub) { + this.settings = null; + this.stub = stub; + } + + public final EchoServiceShouldGeneratePartialUsualSettings getSettings() { + return settings; + } + + public EchoServiceShouldGeneratePartialUsualStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual();
    +   * }
    +   * }
    + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final EchoResponse echoShouldGenerateAsUsual() { + EchoRequest request = EchoRequest.newBuilder().build(); + return echoShouldGenerateAsUsual(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   FoobarName name = FoobarName.of("[PROJECT]", "[FOOBAR]");
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(name);
    +   * }
    +   * }
    + * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final EchoResponse echoShouldGenerateAsUsual(FoobarName name) { + EchoRequest request = + EchoRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return echoShouldGenerateAsUsual(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   String name = FoobarName.of("[PROJECT]", "[FOOBAR]").toString();
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(name);
    +   * }
    +   * }
    + * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final EchoResponse echoShouldGenerateAsUsual(String name) { + EchoRequest request = EchoRequest.newBuilder().setName(name).build(); + return echoShouldGenerateAsUsual(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(request);
    +   * }
    +   * }
    + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final EchoResponse echoShouldGenerateAsUsual(EchoRequest request) { + return echoShouldGenerateAsUsualCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   ApiFuture future =
    +   *       echoServiceShouldGeneratePartialUsualClient
    +   *           .echoShouldGenerateAsUsualCallable()
    +   *           .futureCall(request);
    +   *   // Do something.
    +   *   EchoResponse response = future.get();
    +   * }
    +   * }
    + */ + public final UnaryCallable echoShouldGenerateAsUsualCallable() { + return stub.echoShouldGenerateAsUsualCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   BidiStream bidiStream =
    +   *       echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsUsualCallable().call();
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   bidiStream.send(request);
    +   *   for (EchoResponse response : bidiStream) {
    +   *     // Do something when a response is received.
    +   *   }
    +   * }
    +   * }
    + */ + public final BidiStreamingCallable + chatShouldGenerateAsUsualCallable() { + return stub.chatShouldGenerateAsUsualCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   BidiStream bidiStream =
    +   *       echoServiceShouldGeneratePartialUsualClient
    +   *           .chatAgainShouldGenerateAsUsualCallable()
    +   *           .call();
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   bidiStream.send(request);
    +   *   for (EchoResponse response : bidiStream) {
    +   *     // Do something when a response is received.
    +   *   }
    +   * }
    +   * }
    + */ + public final BidiStreamingCallable + chatAgainShouldGenerateAsUsualCallable() { + return stub.chatAgainShouldGenerateAsUsualCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *
    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal();
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @InternalApi("This API is not intended for public consumption.") + public final EchoResponse chatShouldGenerateAsInternal() { + EchoRequest request = EchoRequest.newBuilder().build(); + return chatShouldGenerateAsInternal(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   FoobarName name = FoobarName.of("[PROJECT]", "[FOOBAR]");
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(name);
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @InternalApi("This API is not intended for public consumption.") + public final EchoResponse chatShouldGenerateAsInternal(FoobarName name) { + EchoRequest request = + EchoRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return chatShouldGenerateAsInternal(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   String name = FoobarName.of("[PROJECT]", "[FOOBAR]").toString();
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(name);
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @InternalApi("This API is not intended for public consumption.") + public final EchoResponse chatShouldGenerateAsInternal(String name) { + EchoRequest request = EchoRequest.newBuilder().setName(name).build(); + return chatShouldGenerateAsInternal(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   EchoResponse response =
    +   *       echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(request);
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @InternalApi("This API is not intended for public consumption.") + public final EchoResponse chatShouldGenerateAsInternal(EchoRequest request) { + return chatShouldGenerateAsInternalCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   ApiFuture future =
    +   *       echoServiceShouldGeneratePartialUsualClient
    +   *           .chatShouldGenerateAsInternalCallable()
    +   *           .futureCall(request);
    +   *   // Do something.
    +   *   EchoResponse response = future.get();
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public final UnaryCallable chatShouldGenerateAsInternalCallable() { + return stub.chatShouldGenerateAsInternalCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sample code: + * + *

    {@code
    +   * // This snippet has been automatically generated and should be regarded as a code template only.
    +   * // It will require modifications to work:
    +   * // - It may require correct/in-range values for request initialization.
    +   * // - It may require specifying regional endpoints when creating the service client as shown in
    +   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    +   * try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient =
    +   *     EchoServiceShouldGeneratePartialUsualClient.create()) {
    +   *   BidiStream bidiStream =
    +   *       echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsInternalCallable().call();
    +   *   EchoRequest request =
    +   *       EchoRequest.newBuilder()
    +   *           .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString())
    +   *           .setFoobar(Foobar.newBuilder().build())
    +   *           .build();
    +   *   bidiStream.send(request);
    +   *   for (EchoResponse response : bidiStream) {
    +   *     // Do something when a response is received.
    +   *   }
    +   * }
    +   * }
    + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public final BidiStreamingCallable + echoShouldGenerateAsInternalCallable() { + return stub.echoShouldGenerateAsInternalCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClientStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClientStub.golden new file mode 100644 index 0000000000..d654e9644c --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicClientStub.golden @@ -0,0 +1,49 @@ +package com.google.selective.generate.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the EchoServiceShouldGeneratePartialUsual service API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class EchoServiceShouldGeneratePartialUsualStub implements BackgroundResource { + + public UnaryCallable echoShouldGenerateAsUsualCallable() { + throw new UnsupportedOperationException("Not implemented: echoShouldGenerateAsUsualCallable()"); + } + + public BidiStreamingCallable chatShouldGenerateAsUsualCallable() { + throw new UnsupportedOperationException("Not implemented: chatShouldGenerateAsUsualCallable()"); + } + + public BidiStreamingCallable chatAgainShouldGenerateAsUsualCallable() { + throw new UnsupportedOperationException( + "Not implemented: chatAgainShouldGenerateAsUsualCallable()"); + } + + @InternalApi("This API is not intended for public consumption.") + public UnaryCallable chatShouldGenerateAsInternalCallable() { + throw new UnsupportedOperationException( + "Not implemented: chatShouldGenerateAsInternalCallable()"); + } + + @InternalApi("This API is not intended for public consumption.") + public BidiStreamingCallable echoShouldGenerateAsInternalCallable() { + throw new UnsupportedOperationException( + "Not implemented: echoShouldGenerateAsInternalCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicServiceSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicServiceSettings.golden new file mode 100644 index 0000000000..07332f7c75 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicServiceSettings.golden @@ -0,0 +1,262 @@ +package com.google.selective.generate.v1beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.selective.generate.v1beta1.stub.EchoServiceShouldGeneratePartialUsualStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoServiceShouldGeneratePartialUsualClient}. + * + *

    The default instance has everything set to sensible defaults: + * + *

      + *
    • The default service address (localhost) and default port (7469) are used. + *
    • Credentials are acquired automatically through Application Default Credentials. + *
    • Retries are configured for idempotent methods but not for non-idempotent methods. + *
    + * + *

    The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

    For example, to set the + * [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings) + * of echoShouldGenerateAsUsual: + * + *

    {@code
    + * // This snippet has been automatically generated and should be regarded as a code template only.
    + * // It will require modifications to work:
    + * // - It may require correct/in-range values for request initialization.
    + * // - It may require specifying regional endpoints when creating the service client as shown in
    + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    + * EchoServiceShouldGeneratePartialUsualSettings.Builder
    + *     echoServiceShouldGeneratePartialUsualSettingsBuilder =
    + *         EchoServiceShouldGeneratePartialUsualSettings.newBuilder();
    + * echoServiceShouldGeneratePartialUsualSettingsBuilder
    + *     .echoShouldGenerateAsUsualSettings()
    + *     .setRetrySettings(
    + *         echoServiceShouldGeneratePartialUsualSettingsBuilder
    + *             .echoShouldGenerateAsUsualSettings()
    + *             .getRetrySettings()
    + *             .toBuilder()
    + *             .setInitialRetryDelayDuration(Duration.ofSeconds(1))
    + *             .setInitialRpcTimeoutDuration(Duration.ofSeconds(5))
    + *             .setMaxAttempts(5)
    + *             .setMaxRetryDelayDuration(Duration.ofSeconds(30))
    + *             .setMaxRpcTimeoutDuration(Duration.ofSeconds(60))
    + *             .setRetryDelayMultiplier(1.3)
    + *             .setRpcTimeoutMultiplier(1.5)
    + *             .setTotalTimeoutDuration(Duration.ofSeconds(300))
    + *             .build());
    + * EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings =
    + *     echoServiceShouldGeneratePartialUsualSettingsBuilder.build();
    + * }
    + * + * Please refer to the [Client Side Retry + * Guide](https://github.com/googleapis/google-cloud-java/blob/main/docs/client_retries.md) for + * additional support in setting retries. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoServiceShouldGeneratePartialUsualSettings + extends ClientSettings { + + /** Returns the object with the settings used for calls to echoShouldGenerateAsUsual. */ + public UnaryCallSettings echoShouldGenerateAsUsualSettings() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings) getStubSettings()) + .echoShouldGenerateAsUsualSettings(); + } + + /** Returns the object with the settings used for calls to chatShouldGenerateAsUsual. */ + public StreamingCallSettings chatShouldGenerateAsUsualSettings() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings) getStubSettings()) + .chatShouldGenerateAsUsualSettings(); + } + + /** Returns the object with the settings used for calls to chatAgainShouldGenerateAsUsual. */ + public StreamingCallSettings chatAgainShouldGenerateAsUsualSettings() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings) getStubSettings()) + .chatAgainShouldGenerateAsUsualSettings(); + } + + /** + * Returns the object with the settings used for calls to chatShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public UnaryCallSettings chatShouldGenerateAsInternalSettings() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings) getStubSettings()) + .chatShouldGenerateAsInternalSettings(); + } + + /** + * Returns the object with the settings used for calls to echoShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public StreamingCallSettings echoShouldGenerateAsInternalSettings() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings) getStubSettings()) + .echoShouldGenerateAsInternalSettings(); + } + + public static final EchoServiceShouldGeneratePartialUsualSettings create( + EchoServiceShouldGeneratePartialUsualStubSettings stub) throws IOException { + return new EchoServiceShouldGeneratePartialUsualSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return EchoServiceShouldGeneratePartialUsualStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return EchoServiceShouldGeneratePartialUsualStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return EchoServiceShouldGeneratePartialUsualStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return EchoServiceShouldGeneratePartialUsualStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return EchoServiceShouldGeneratePartialUsualStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return EchoServiceShouldGeneratePartialUsualStubSettings.defaultTransportChannelProvider(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return EchoServiceShouldGeneratePartialUsualStubSettings + .defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoServiceShouldGeneratePartialUsualSettings(Builder settingsBuilder) + throws IOException { + super(settingsBuilder); + } + + /** Builder for EchoServiceShouldGeneratePartialUsualSettings. */ + public static class Builder + extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(EchoServiceShouldGeneratePartialUsualStubSettings.newBuilder(clientContext)); + } + + protected Builder(EchoServiceShouldGeneratePartialUsualSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(EchoServiceShouldGeneratePartialUsualStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(EchoServiceShouldGeneratePartialUsualStubSettings.newBuilder()); + } + + public EchoServiceShouldGeneratePartialUsualStubSettings.Builder getStubSettingsBuilder() { + return ((EchoServiceShouldGeneratePartialUsualStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to echoShouldGenerateAsUsual. */ + public UnaryCallSettings.Builder + echoShouldGenerateAsUsualSettings() { + return getStubSettingsBuilder().echoShouldGenerateAsUsualSettings(); + } + + /** Returns the builder for the settings used for calls to chatShouldGenerateAsUsual. */ + public StreamingCallSettings.Builder + chatShouldGenerateAsUsualSettings() { + return getStubSettingsBuilder().chatShouldGenerateAsUsualSettings(); + } + + /** Returns the builder for the settings used for calls to chatAgainShouldGenerateAsUsual. */ + public StreamingCallSettings.Builder + chatAgainShouldGenerateAsUsualSettings() { + return getStubSettingsBuilder().chatAgainShouldGenerateAsUsualSettings(); + } + + /** + * Returns the builder for the settings used for calls to chatShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public UnaryCallSettings.Builder + chatShouldGenerateAsInternalSettings() { + return getStubSettingsBuilder().chatShouldGenerateAsInternalSettings(); + } + + /** + * Returns the builder for the settings used for calls to echoShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public StreamingCallSettings.Builder + echoShouldGenerateAsInternalSettings() { + return getStubSettingsBuilder().echoShouldGenerateAsInternalSettings(); + } + + @Override + public EchoServiceShouldGeneratePartialUsualSettings build() throws IOException { + return new EchoServiceShouldGeneratePartialUsualSettings(this); + } + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicStubSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicStubSettings.golden new file mode 100644 index 0000000000..5cf83e9e4b --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicStubSettings.golden @@ -0,0 +1,379 @@ +package com.google.selective.generate.v1beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoServiceShouldGeneratePartialUsualStub}. + * + *

    The default instance has everything set to sensible defaults: + * + *

      + *
    • The default service address (localhost) and default port (7469) are used. + *
    • Credentials are acquired automatically through Application Default Credentials. + *
    • Retries are configured for idempotent methods but not for non-idempotent methods. + *
    + * + *

    The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

    For example, to set the + * [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings) + * of echoShouldGenerateAsUsual: + * + *

    {@code
    + * // This snippet has been automatically generated and should be regarded as a code template only.
    + * // It will require modifications to work:
    + * // - It may require correct/in-range values for request initialization.
    + * // - It may require specifying regional endpoints when creating the service client as shown in
    + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    + * EchoServiceShouldGeneratePartialUsualStubSettings.Builder
    + *     echoServiceShouldGeneratePartialUsualSettingsBuilder =
    + *         EchoServiceShouldGeneratePartialUsualStubSettings.newBuilder();
    + * echoServiceShouldGeneratePartialUsualSettingsBuilder
    + *     .echoShouldGenerateAsUsualSettings()
    + *     .setRetrySettings(
    + *         echoServiceShouldGeneratePartialUsualSettingsBuilder
    + *             .echoShouldGenerateAsUsualSettings()
    + *             .getRetrySettings()
    + *             .toBuilder()
    + *             .setInitialRetryDelayDuration(Duration.ofSeconds(1))
    + *             .setInitialRpcTimeoutDuration(Duration.ofSeconds(5))
    + *             .setMaxAttempts(5)
    + *             .setMaxRetryDelayDuration(Duration.ofSeconds(30))
    + *             .setMaxRpcTimeoutDuration(Duration.ofSeconds(60))
    + *             .setRetryDelayMultiplier(1.3)
    + *             .setRpcTimeoutMultiplier(1.5)
    + *             .setTotalTimeoutDuration(Duration.ofSeconds(300))
    + *             .build());
    + * EchoServiceShouldGeneratePartialUsualStubSettings
    + *     echoServiceShouldGeneratePartialUsualSettings =
    + *         echoServiceShouldGeneratePartialUsualSettingsBuilder.build();
    + * }
    + * + * Please refer to the [Client Side Retry + * Guide](https://github.com/googleapis/google-cloud-java/blob/main/docs/client_retries.md) for + * additional support in setting retries. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoServiceShouldGeneratePartialUsualStubSettings + extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings echoShouldGenerateAsUsualSettings; + private final StreamingCallSettings chatShouldGenerateAsUsualSettings; + private final StreamingCallSettings + chatAgainShouldGenerateAsUsualSettings; + private final UnaryCallSettings chatShouldGenerateAsInternalSettings; + private final StreamingCallSettings + echoShouldGenerateAsInternalSettings; + + /** Returns the object with the settings used for calls to echoShouldGenerateAsUsual. */ + public UnaryCallSettings echoShouldGenerateAsUsualSettings() { + return echoShouldGenerateAsUsualSettings; + } + + /** Returns the object with the settings used for calls to chatShouldGenerateAsUsual. */ + public StreamingCallSettings chatShouldGenerateAsUsualSettings() { + return chatShouldGenerateAsUsualSettings; + } + + /** Returns the object with the settings used for calls to chatAgainShouldGenerateAsUsual. */ + public StreamingCallSettings chatAgainShouldGenerateAsUsualSettings() { + return chatAgainShouldGenerateAsUsualSettings; + } + + /** + * Returns the object with the settings used for calls to chatShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public UnaryCallSettings chatShouldGenerateAsInternalSettings() { + return chatShouldGenerateAsInternalSettings; + } + + /** + * Returns the object with the settings used for calls to echoShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public StreamingCallSettings echoShouldGenerateAsInternalSettings() { + return echoShouldGenerateAsInternalSettings; + } + + public EchoServiceShouldGeneratePartialUsualStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcEchoServiceShouldGeneratePartialUsualStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + @ObsoleteApi("Use getEndpoint() instead") + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", + GaxProperties.getLibraryVersion( + EchoServiceShouldGeneratePartialUsualStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoServiceShouldGeneratePartialUsualStubSettings(Builder settingsBuilder) + throws IOException { + super(settingsBuilder); + + echoShouldGenerateAsUsualSettings = settingsBuilder.echoShouldGenerateAsUsualSettings().build(); + chatShouldGenerateAsUsualSettings = settingsBuilder.chatShouldGenerateAsUsualSettings().build(); + chatAgainShouldGenerateAsUsualSettings = + settingsBuilder.chatAgainShouldGenerateAsUsualSettings().build(); + chatShouldGenerateAsInternalSettings = + settingsBuilder.chatShouldGenerateAsInternalSettings().build(); + echoShouldGenerateAsInternalSettings = + settingsBuilder.echoShouldGenerateAsInternalSettings().build(); + } + + /** Builder for EchoServiceShouldGeneratePartialUsualStubSettings. */ + public static class Builder + extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder + echoShouldGenerateAsUsualSettings; + private final StreamingCallSettings.Builder + chatShouldGenerateAsUsualSettings; + private final StreamingCallSettings.Builder + chatAgainShouldGenerateAsUsualSettings; + private final UnaryCallSettings.Builder + chatShouldGenerateAsInternalSettings; + private final StreamingCallSettings.Builder + echoShouldGenerateAsInternalSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + echoShouldGenerateAsUsualSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + chatShouldGenerateAsUsualSettings = StreamingCallSettings.newBuilder(); + chatAgainShouldGenerateAsUsualSettings = StreamingCallSettings.newBuilder(); + chatShouldGenerateAsInternalSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + echoShouldGenerateAsInternalSettings = StreamingCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoShouldGenerateAsUsualSettings, chatShouldGenerateAsInternalSettings); + initDefaults(this); + } + + protected Builder(EchoServiceShouldGeneratePartialUsualStubSettings settings) { + super(settings); + + echoShouldGenerateAsUsualSettings = settings.echoShouldGenerateAsUsualSettings.toBuilder(); + chatShouldGenerateAsUsualSettings = settings.chatShouldGenerateAsUsualSettings.toBuilder(); + chatAgainShouldGenerateAsUsualSettings = + settings.chatAgainShouldGenerateAsUsualSettings.toBuilder(); + chatShouldGenerateAsInternalSettings = + settings.chatShouldGenerateAsInternalSettings.toBuilder(); + echoShouldGenerateAsInternalSettings = + settings.echoShouldGenerateAsInternalSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoShouldGenerateAsUsualSettings, chatShouldGenerateAsInternalSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .echoShouldGenerateAsUsualSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .chatShouldGenerateAsInternalSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to echoShouldGenerateAsUsual. */ + public UnaryCallSettings.Builder + echoShouldGenerateAsUsualSettings() { + return echoShouldGenerateAsUsualSettings; + } + + /** Returns the builder for the settings used for calls to chatShouldGenerateAsUsual. */ + public StreamingCallSettings.Builder + chatShouldGenerateAsUsualSettings() { + return chatShouldGenerateAsUsualSettings; + } + + /** Returns the builder for the settings used for calls to chatAgainShouldGenerateAsUsual. */ + public StreamingCallSettings.Builder + chatAgainShouldGenerateAsUsualSettings() { + return chatAgainShouldGenerateAsUsualSettings; + } + + /** + * Returns the builder for the settings used for calls to chatShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public UnaryCallSettings.Builder + chatShouldGenerateAsInternalSettings() { + return chatShouldGenerateAsInternalSettings; + } + + /** + * Returns the builder for the settings used for calls to echoShouldGenerateAsInternal. + * + *

    Warning: This method is for internal use only. Please do not use it directly. + */ + @InternalApi("This API is not intended for public consumption.") + public StreamingCallSettings.Builder + echoShouldGenerateAsInternalSettings() { + return echoShouldGenerateAsInternalSettings; + } + + @Override + public EchoServiceShouldGeneratePartialUsualStubSettings build() throws IOException { + return new EchoServiceShouldGeneratePartialUsualStubSettings(this); + } + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsPublic.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsPublic.golden new file mode 100644 index 0000000000..79c040a4c1 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsPublic.golden @@ -0,0 +1,58 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_ChatAgainShouldGenerateAsPublic_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncChatAgainShouldGenerateAsPublic { + + public static void main(String[] args) throws Exception { + asyncChatAgainShouldGenerateAsPublic(); + } + + public static void asyncChatAgainShouldGenerateAsPublic() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + BidiStream bidiStream = + echoServiceShouldGeneratePartialPublicClient + .chatAgainShouldGenerateAsPublicCallable() + .call(); + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_ChatAgainShouldGenerateAsPublic_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..e745bdb237 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatAgainShouldGenerateAsUsual.golden @@ -0,0 +1,58 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatAgainShouldGenerateAsUsual_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncChatAgainShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + asyncChatAgainShouldGenerateAsUsual(); + } + + public static void asyncChatAgainShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + BidiStream bidiStream = + echoServiceShouldGeneratePartialUsualClient + .chatAgainShouldGenerateAsUsualCallable() + .call(); + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatAgainShouldGenerateAsUsual_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsInternal.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsInternal.golden new file mode 100644 index 0000000000..dca5a1b9f4 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsInternal.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_async] +import com.google.api.core.ApiFuture; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncChatShouldGenerateAsInternal { + + public static void main(String[] args) throws Exception { + asyncChatShouldGenerateAsInternal(); + } + + public static void asyncChatShouldGenerateAsInternal() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + ApiFuture future = + echoServiceShouldGeneratePartialUsualClient + .chatShouldGenerateAsInternalCallable() + .futureCall(request); + // Do something. + EchoResponse response = future.get(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsPublic.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsPublic.golden new file mode 100644 index 0000000000..74eb1d0118 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsPublic.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_ChatShouldGenerateAsPublic_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncChatShouldGenerateAsPublic { + + public static void main(String[] args) throws Exception { + asyncChatShouldGenerateAsPublic(); + } + + public static void asyncChatShouldGenerateAsPublic() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + BidiStream bidiStream = + echoServiceShouldGeneratePartialPublicClient.chatShouldGenerateAsPublicCallable().call(); + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_ChatShouldGenerateAsPublic_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..0cbc13407c --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncChatShouldGenerateAsUsual.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsUsual_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncChatShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + asyncChatShouldGenerateAsUsual(); + } + + public static void asyncChatShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + BidiStream bidiStream = + echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsUsualCallable().call(); + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsUsual_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsInternal.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsInternal.golden new file mode 100644 index 0000000000..64d8dd2a4c --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsInternal.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsInternal_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncEchoShouldGenerateAsInternal { + + public static void main(String[] args) throws Exception { + asyncEchoShouldGenerateAsInternal(); + } + + public static void asyncEchoShouldGenerateAsInternal() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + BidiStream bidiStream = + echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsInternalCallable().call(); + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsInternal_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsPublic.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsPublic.golden new file mode 100644 index 0000000000..1da3c77914 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsPublic.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_async] +import com.google.api.core.ApiFuture; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncEchoShouldGenerateAsPublic { + + public static void main(String[] args) throws Exception { + asyncEchoShouldGenerateAsPublic(); + } + + public static void asyncEchoShouldGenerateAsPublic() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + ApiFuture future = + echoServiceShouldGeneratePartialPublicClient + .echoShouldGenerateAsPublicCallable() + .futureCall(request); + // Do something. + EchoResponse response = future.get(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..ec63a3c587 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/AsyncEchoShouldGenerateAsUsual.golden @@ -0,0 +1,56 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_async] +import com.google.api.core.ApiFuture; +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class AsyncEchoShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + asyncEchoShouldGenerateAsUsual(); + } + + public static void asyncEchoShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + ApiFuture future = + echoServiceShouldGeneratePartialUsualClient + .echoShouldGenerateAsUsualCallable() + .futureCall(request); + // Do something. + EchoResponse response = future.get(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_async] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternal.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternal.golden new file mode 100644 index 0000000000..18017ebfc3 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternal.golden @@ -0,0 +1,51 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_sync] +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncChatShouldGenerateAsInternal { + + public static void main(String[] args) throws Exception { + syncChatShouldGenerateAsInternal(); + } + + public static void syncChatShouldGenerateAsInternal() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(request); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalFoobarname.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalFoobarname.golden new file mode 100644 index 0000000000..f217b8f4ef --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalFoobarname.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_Foobarname_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncChatShouldGenerateAsInternalFoobarname { + + public static void main(String[] args) throws Exception { + syncChatShouldGenerateAsInternalFoobarname(); + } + + public static void syncChatShouldGenerateAsInternalFoobarname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + FoobarName name = FoobarName.of("[PROJECT]", "[FOOBAR]"); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_Foobarname_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalNoargs.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalNoargs.golden new file mode 100644 index 0000000000..9b3c95e017 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalNoargs.golden @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_Noargs_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; + +public class SyncChatShouldGenerateAsInternalNoargs { + + public static void main(String[] args) throws Exception { + syncChatShouldGenerateAsInternalNoargs(); + } + + public static void syncChatShouldGenerateAsInternalNoargs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_Noargs_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalString.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalString.golden new file mode 100644 index 0000000000..1a0216d16d --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncChatShouldGenerateAsInternalString.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_String_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncChatShouldGenerateAsInternalString { + + public static void main(String[] args) throws Exception { + syncChatShouldGenerateAsInternalString(); + } + + public static void syncChatShouldGenerateAsInternalString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + String name = FoobarName.of("[PROJECT]", "[FOOBAR]").toString(); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.chatShouldGenerateAsInternal(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_ChatShouldGenerateAsInternal_String_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetCredentialsProvider.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetCredentialsProvider.golden new file mode 100644 index 0000000000..9ea2dc09f3 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetCredentialsProvider.golden @@ -0,0 +1,46 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualSettings; +import com.google.selective.generate.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings = + EchoServiceShouldGeneratePartialUsualSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create( + echoServiceShouldGeneratePartialUsualSettings); + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_Create_SetCredentialsProvider_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetEndpoint.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetEndpoint.golden new file mode 100644 index 0000000000..1b58cbe100 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncCreateSetEndpoint.golden @@ -0,0 +1,43 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_Create_SetEndpoint_sync] +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualSettings; +import com.google.selective.generate.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings = + EchoServiceShouldGeneratePartialUsualSettings.newBuilder().setEndpoint(myEndpoint).build(); + EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create( + echoServiceShouldGeneratePartialUsualSettings); + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_Create_SetEndpoint_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublic.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublic.golden new file mode 100644 index 0000000000..02533c5d40 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublic.golden @@ -0,0 +1,51 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_sync] +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsPublic { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsPublic(); + } + + public static void syncEchoShouldGenerateAsPublic() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + EchoResponse response = + echoServiceShouldGeneratePartialPublicClient.echoShouldGenerateAsPublic(request); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicFoobarname.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicFoobarname.golden new file mode 100644 index 0000000000..586d181fe4 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicFoobarname.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_Foobarname_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsPublicFoobarname { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsPublicFoobarname(); + } + + public static void syncEchoShouldGenerateAsPublicFoobarname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + FoobarName name = FoobarName.of("[PROJECT]", "[FOOBAR]"); + EchoResponse response = + echoServiceShouldGeneratePartialPublicClient.echoShouldGenerateAsPublic(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_Foobarname_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicNoargs.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicNoargs.golden new file mode 100644 index 0000000000..9e61ddb98b --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicNoargs.golden @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_Noargs_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; + +public class SyncEchoShouldGenerateAsPublicNoargs { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsPublicNoargs(); + } + + public static void syncEchoShouldGenerateAsPublicNoargs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + EchoResponse response = + echoServiceShouldGeneratePartialPublicClient.echoShouldGenerateAsPublic(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_Noargs_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicString.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicString.golden new file mode 100644 index 0000000000..a035c1000e --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsPublicString.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_String_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialPublicClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsPublicString { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsPublicString(); + } + + public static void syncEchoShouldGenerateAsPublicString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialPublicClient echoServiceShouldGeneratePartialPublicClient = + EchoServiceShouldGeneratePartialPublicClient.create()) { + String name = FoobarName.of("[PROJECT]", "[FOOBAR]").toString(); + EchoResponse response = + echoServiceShouldGeneratePartialPublicClient.echoShouldGenerateAsPublic(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialPublic_EchoShouldGenerateAsPublic_String_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..af978eee1e --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsual.golden @@ -0,0 +1,51 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_sync] +import com.google.selective.generate.v1beta1.EchoRequest; +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.Foobar; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsual(); + } + + public static void syncEchoShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setName(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setParent(FoobarName.of("[PROJECT]", "[FOOBAR]").toString()) + .setFoobar(Foobar.newBuilder().build()) + .build(); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(request); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualFoobarname.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualFoobarname.golden new file mode 100644 index 0000000000..c2e469912a --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualFoobarname.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_Foobarname_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsUsualFoobarname { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsualFoobarname(); + } + + public static void syncEchoShouldGenerateAsUsualFoobarname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + FoobarName name = FoobarName.of("[PROJECT]", "[FOOBAR]"); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_Foobarname_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualNoargs.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualNoargs.golden new file mode 100644 index 0000000000..b080af1eb4 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualNoargs.golden @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_Noargs_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; + +public class SyncEchoShouldGenerateAsUsualNoargs { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsualNoargs(); + } + + public static void syncEchoShouldGenerateAsUsualNoargs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_Noargs_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualString.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualString.golden new file mode 100644 index 0000000000..e4142b60d3 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/echoserviceselectivegapicclient/SyncEchoShouldGenerateAsUsualString.golden @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_String_sync] +import com.google.selective.generate.v1beta1.EchoResponse; +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualClient; +import com.google.selective.generate.v1beta1.FoobarName; + +public class SyncEchoShouldGenerateAsUsualString { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsualString(); + } + + public static void syncEchoShouldGenerateAsUsualString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoServiceShouldGeneratePartialUsualClient echoServiceShouldGeneratePartialUsualClient = + EchoServiceShouldGeneratePartialUsualClient.create()) { + String name = FoobarName.of("[PROJECT]", "[FOOBAR]").toString(); + EchoResponse response = + echoServiceShouldGeneratePartialUsualClient.echoShouldGenerateAsUsual(name); + } + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsual_EchoShouldGenerateAsUsual_String_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/SyncEchoShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/SyncEchoShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..64beddd0cd --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/SyncEchoShouldGenerateAsUsual.golden @@ -0,0 +1,58 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsualSettings_EchoShouldGenerateAsUsual_sync] +import com.google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsualSettings; +import java.time.Duration; + +public class SyncEchoShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsual(); + } + + public static void syncEchoShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoServiceShouldGeneratePartialUsualSettings.Builder + echoServiceShouldGeneratePartialUsualSettingsBuilder = + EchoServiceShouldGeneratePartialUsualSettings.newBuilder(); + echoServiceShouldGeneratePartialUsualSettingsBuilder + .echoShouldGenerateAsUsualSettings() + .setRetrySettings( + echoServiceShouldGeneratePartialUsualSettingsBuilder + .echoShouldGenerateAsUsualSettings() + .getRetrySettings() + .toBuilder() + .setInitialRetryDelayDuration(Duration.ofSeconds(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(5)) + .setMaxAttempts(5) + .setMaxRetryDelayDuration(Duration.ofSeconds(30)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(60)) + .setRetryDelayMultiplier(1.3) + .setRpcTimeoutMultiplier(1.5) + .setTotalTimeoutDuration(Duration.ofSeconds(300)) + .build()); + EchoServiceShouldGeneratePartialUsualSettings echoServiceShouldGeneratePartialUsualSettings = + echoServiceShouldGeneratePartialUsualSettingsBuilder.build(); + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsualSettings_EchoShouldGenerateAsUsual_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoShouldGenerateAsUsual.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoShouldGenerateAsUsual.golden new file mode 100644 index 0000000000..8daf4e32c6 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoShouldGenerateAsUsual.golden @@ -0,0 +1,59 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.selective.generate.v1beta1.stub.samples; + +// [START goldensample_generated_EchoServiceShouldGeneratePartialUsualStubSettings_EchoShouldGenerateAsUsual_sync] +import com.google.selective.generate.v1beta1.stub.EchoServiceShouldGeneratePartialUsualStubSettings; +import java.time.Duration; + +public class SyncEchoShouldGenerateAsUsual { + + public static void main(String[] args) throws Exception { + syncEchoShouldGenerateAsUsual(); + } + + public static void syncEchoShouldGenerateAsUsual() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoServiceShouldGeneratePartialUsualStubSettings.Builder + echoServiceShouldGeneratePartialUsualSettingsBuilder = + EchoServiceShouldGeneratePartialUsualStubSettings.newBuilder(); + echoServiceShouldGeneratePartialUsualSettingsBuilder + .echoShouldGenerateAsUsualSettings() + .setRetrySettings( + echoServiceShouldGeneratePartialUsualSettingsBuilder + .echoShouldGenerateAsUsualSettings() + .getRetrySettings() + .toBuilder() + .setInitialRetryDelayDuration(Duration.ofSeconds(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(5)) + .setMaxAttempts(5) + .setMaxRetryDelayDuration(Duration.ofSeconds(30)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(60)) + .setRetryDelayMultiplier(1.3) + .setRpcTimeoutMultiplier(1.5) + .setTotalTimeoutDuration(Duration.ofSeconds(300)) + .build()); + EchoServiceShouldGeneratePartialUsualStubSettings + echoServiceShouldGeneratePartialUsualSettings = + echoServiceShouldGeneratePartialUsualSettingsBuilder.build(); + } +} +// [END goldensample_generated_EchoServiceShouldGeneratePartialUsualStubSettings_EchoShouldGenerateAsUsual_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java index fc551eb571..48a7e4175e 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java @@ -29,6 +29,7 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.utils.LineFormatter; import com.google.protobuf.Descriptors; +import com.google.selective.generate.v1beta1.SelectiveApiGenerationOuterClass; import com.google.showcase.v1beta1.EchoOuterClass; import java.util.Arrays; import java.util.Collections; @@ -42,6 +43,7 @@ class ServiceClientHeaderSampleComposerTest { private static final String SHOWCASE_PACKAGE_NAME = "com.google.showcase.v1beta1"; + private static final String SELECTIVE_API_PACKAGE_NAME = "com.google.selective.generate.v1beta1"; private static final String LRO_PACKAGE_NAME = "com.google.longrunning"; private static final String PROTO_PACKAGE_NAME = "com.google.protobuf"; private static final String PAGINATED_FIELD_NAME = "page_size"; @@ -214,6 +216,7 @@ void composeClassHeaderSample_firstMethodHasNoSignatures() { writeStatements( ServiceClientHeaderSampleComposer.composeClassHeaderSample( service, clientType, resourceNames, messageTypes)); + System.out.println("results: " + results); String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", @@ -228,6 +231,7 @@ void composeClassHeaderSample_firstMethodHasNoSignatures() { " .build();\n", " EchoResponse response = echoClient.echo(request);\n", "}"); + System.out.println("results: " + expected); Assert.assertEquals(results, expected); } @@ -289,6 +293,137 @@ void composeClassHeaderSample_firstMethodIsStream() { Assert.assertEquals(results, expected); } + @Test + void composeClassHeaderSample_firstMethodIsInternal() { + Descriptors.FileDescriptor selectiveApiGenerationFileDescriptor = + SelectiveApiGenerationOuterClass.getDescriptor(); + Map resourceNames = + Parser.parseResourceNames(selectiveApiGenerationFileDescriptor); + Map messageTypes = Parser.parseMessages(selectiveApiGenerationFileDescriptor); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + Method internalMethod = + Method.builder() + .setName("ChatShouldGenerateAsInternal") + .setInputType(inputType) + .setOutputType(outputType) + .setIsInternalApi(true) + .build(); + Method publicMethod = + Method.builder() + .setName("ChatShouldGenerateAsUsual") + .setInputType(inputType) + .setOutputType(outputType) + .setIsInternalApi(false) + .build(); + Service service = + Service.builder() + .setName("EchoServiceShouldGeneratePartialUsual") + .setDefaultHost("localhost:7469") + .setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")) + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .setProtoPakkage(SELECTIVE_API_PACKAGE_NAME) + .setOriginalJavaPackage(SELECTIVE_API_PACKAGE_NAME) + .setOverriddenName("EchoServiceShouldGeneratePartialUsual") + .setMethods(Arrays.asList(internalMethod, publicMethod)) + .build(); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoServiceSelectiveApiClient") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + String results = + writeStatements( + ServiceClientHeaderSampleComposer.composeClassHeaderSample( + service, clientType, resourceNames, messageTypes)); + String expected = + LineFormatter.lines( + "try (EchoServiceSelectiveApiClient echoServiceSelectiveApiClient =\n" + + " EchoServiceSelectiveApiClient.create()) {\n" + + " EchoRequest request =\n" + + " EchoRequest.newBuilder()\n" + + " .setName(FoobarName.of(\"[PROJECT]\", \"[FOOBAR]\").toString())\n" + + " .setParent(\n" + + " FoobarbazName.ofProjectFoobarbazName(\"[PROJECT]\", \"[FOOBARBAZ]\").toString())\n" + + " .setFoobar(Foobar.newBuilder().build())\n" + + " .build();\n" + + " EchoResponse response = echoServiceSelectiveApiClient.chatShouldGenerateAsUsual(request);\n" + + "}"); + Assert.assertEquals(results, expected); + } + + @Test + void composeClassHeaderSample_allMethodsAreInternal() { + Descriptors.FileDescriptor selectiveApiGenerationFileDescriptor = + SelectiveApiGenerationOuterClass.getDescriptor(); + Map resourceNames = + Parser.parseResourceNames(selectiveApiGenerationFileDescriptor); + Map messageTypes = Parser.parseMessages(selectiveApiGenerationFileDescriptor); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + Method internalMethod1 = + Method.builder() + .setName("ChatShouldGenerateAsInternal") + .setInputType(inputType) + .setOutputType(outputType) + .setIsInternalApi(true) + .build(); + Method internalMethod2 = + Method.builder() + .setName("EchoShouldGenerateAsInternal") + .setInputType(inputType) + .setOutputType(outputType) + .setIsInternalApi(true) + .build(); + Service service = + Service.builder() + .setName("EchoServiceShouldGeneratePartialUsual") + .setDefaultHost("localhost:7469") + .setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")) + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .setProtoPakkage(SELECTIVE_API_PACKAGE_NAME) + .setOriginalJavaPackage(SELECTIVE_API_PACKAGE_NAME) + .setOverriddenName("EchoServiceShouldGeneratePartialUsual") + .setMethods(Arrays.asList(internalMethod1, internalMethod2)) + .build(); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoServiceSelectiveApiClient") + .setPakkage(SELECTIVE_API_PACKAGE_NAME) + .build()); + String results = + writeStatements( + ServiceClientHeaderSampleComposer.composeClassHeaderSample( + service, clientType, resourceNames, messageTypes)); + String expected = + LineFormatter.lines( + "try (EchoServiceSelectiveApiClient echoServiceSelectiveApiClient =\n" + + " EchoServiceSelectiveApiClient.create()) {}"); + Assert.assertEquals(expected, results); + } + /*Testing composeSetCredentialsSample*/ @Test void composeSetCredentialsSample() { diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java index 6e8ffa7232..6ddf533cbb 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java @@ -22,10 +22,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.api.ClientLibrarySettings; +import com.google.api.CommonLanguageSettings; import com.google.api.FieldInfo.Format; +import com.google.api.JavaSettings; import com.google.api.MethodSettings; import com.google.api.Publishing; import com.google.api.PythonSettings; +import com.google.api.SelectiveGapicGeneration; import com.google.api.Service; import com.google.api.generator.engine.ast.ConcreteReference; import com.google.api.generator.engine.ast.Reference; @@ -39,6 +42,7 @@ import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.model.ResourceReference; import com.google.api.generator.gapic.model.Transport; +import com.google.api.generator.gapic.protoparser.Parser.SelectiveGapicType; import com.google.api.version.test.ApiVersionTestingOuterClass; import com.google.auto.populate.field.AutoPopulateFieldTestingOuterClass; import com.google.bookshop.v1beta1.BookshopProto; @@ -738,7 +742,7 @@ void selectiveGenerationTest_shouldExcludeUnusedResourceNames() { } @Test - void selectiveGenerationTest_shouldGenerateOnlySelectiveMethods() { + void selectiveGenerationTest_shouldGenerateOnlySelectiveMethodsWithGenerateOmittedFalse() { FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); Map messageTypes = Parser.parseMessages(fileDescriptor); Map resourceNames = Parser.parseResourceNames(fileDescriptor); @@ -756,15 +760,61 @@ void selectiveGenerationTest_shouldGenerateOnlySelectiveMethods() { Parser.parseService( fileDescriptor, messageTypes, resourceNames, serviceYamlOpt, new HashSet<>()); assertEquals(1, services.size()); - assertEquals("EchoServiceShouldGeneratePartial", services.get(0).overriddenName()); + assertEquals("EchoServiceShouldGeneratePartialUsual", services.get(0).overriddenName()); assertEquals(3, services.get(0).methods().size()); for (Method method : services.get(0).methods()) { - assertTrue(method.name().contains("ShouldInclude")); + assertTrue(method.name().contains("ShouldGenerate")); + assertFalse(method.isInternalApi()); } } @Test - void selectiveGenerationTest_shouldGenerateAllIfNoPublishingSectionInServiceYaml() { + void selectiveGenerationTest_shouldGenerateOmittedAsInternalWithGenerateOmittedTrue() { + FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); + Map messageTypes = Parser.parseMessages(fileDescriptor); + Map resourceNames = Parser.parseResourceNames(fileDescriptor); + + // test with service yaml file to show usage of this feature, test itself + // can be done without this file and build a Service object from code. + String serviceYamlFilename = "selective_api_generation_generate_omitted_v1beta1.yaml"; + String testFilesDirectory = "src/test/resources/"; + Path serviceYamlPath = Paths.get(testFilesDirectory, serviceYamlFilename); + Optional serviceYamlOpt = + ServiceYamlParser.parse(serviceYamlPath.toString()); + Assert.assertTrue(serviceYamlOpt.isPresent()); + + List services = + Parser.parseService( + fileDescriptor, messageTypes, resourceNames, serviceYamlOpt, new HashSet<>()); + + assertEquals(3, services.size()); + // Tests a service with public methods only. + assertEquals("EchoServiceShouldGenerateAllAsUsual", services.get(0).overriddenName()); + assertEquals(3, services.get(0).methods().size()); + for (Method method : services.get(0).methods()) { + assertFalse(method.isInternalApi()); + } + + // Tests a service with partial public methods and partial internal methods. + assertEquals("EchoServiceShouldGeneratePartialUsual", services.get(1).overriddenName()); + assertEquals(5, services.get(1).methods().size()); + for (Method method : services.get(1).methods()) { + if (method.name().contains("ShouldGenerateAsUsual")) { + assertFalse(method.isInternalApi()); + } else { + assertTrue(method.isInternalApi()); + } + } + // Tests a service with internal methods only. + assertEquals("EchoServiceShouldGenerateAllInternal", services.get(2).overriddenName()); + assertEquals(2, services.get(2).methods().size()); + for (Method method : services.get(2).methods()) { + assertTrue(method.isInternalApi()); + } + } + + @Test + void selectiveGenerationTest_shouldGenerateAsPublicIfNoPublishingSectionInServiceYaml() { Service service = Service.newBuilder() .setTitle("Selective generation testing with no publishing section") @@ -776,12 +826,13 @@ void selectiveGenerationTest_shouldGenerateAllIfNoPublishingSectionInServiceYaml List methods = fileDescriptor.getServices().get(0).getMethods(); String protoPackage = "google.selective.generate.v1beta1"; - assertTrue( - Parser.shouldIncludeMethodInGeneration(methods.get(0), Optional.of(service), protoPackage)); + assertEquals( + Parser.getMethodSelectiveGapicType(methods.get(0), Optional.of(service), protoPackage), + SelectiveGapicType.PUBLIC); } @Test - void selectiveGenerationTest_shouldIncludeMethodInGenerationWhenProtoPackageMismatch() { + void selectiveGenerationTest_shouldGenerateAsPublicWhenProtoPackageMismatch() { String protoPackage = "google.selective.generate.v1beta1"; // situation where service yaml has different version stated @@ -800,12 +851,13 @@ void selectiveGenerationTest_shouldIncludeMethodInGenerationWhenProtoPackageMism FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); List methods = fileDescriptor.getServices().get(0).getMethods(); - assertTrue( - Parser.shouldIncludeMethodInGeneration(methods.get(0), Optional.of(service), protoPackage)); + assertEquals( + Parser.getMethodSelectiveGapicType(methods.get(0), Optional.of(service), protoPackage), + SelectiveGapicType.PUBLIC); } @Test - void selectiveGenerationTest_shouldGenerateAllIfNoJavaSectionInServiceYaml() { + void selectiveGenerationTest_shouldGenerateAsPublicIfNoJavaSectionInServiceYaml() { String protoPackage = "google.selective.generate.v1beta1"; // situation where service yaml has other language settings but no @@ -830,8 +882,63 @@ void selectiveGenerationTest_shouldGenerateAllIfNoJavaSectionInServiceYaml() { FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); List methods = fileDescriptor.getServices().get(0).getMethods(); - assertTrue( - Parser.shouldIncludeMethodInGeneration(methods.get(0), Optional.of(service), protoPackage)); + assertEquals( + Parser.getMethodSelectiveGapicType(methods.get(0), Optional.of(service), protoPackage), + SelectiveGapicType.PUBLIC); + } + + @Test + void selectiveGenerationTest_shouldGenerateAsPublicIfMethodInList() { + String protoPackage = "google.selective.generate.v1beta1"; + String methodsAllowList = + "google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual"; + Service service = + createServiceWithSelectiveGapicConfiguration(protoPackage, methodsAllowList, true); + + FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); + // methodToGenerate from fileDescriptor: + // google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual + MethodDescriptor methodToGenerate = fileDescriptor.getServices().get(1).getMethods().get(0); + + assertEquals( + Parser.getMethodSelectiveGapicType(methodToGenerate, Optional.of(service), protoPackage), + SelectiveGapicType.PUBLIC); + } + + @Test + void selectiveGenerationTest_shouldGenerateAsInternalIfMethodNotInListWithGenerateOmittedTrue() { + String protoPackage = "google.selective.generate.v1beta1"; + String methodsAllowList = + "google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual"; + Service service = + createServiceWithSelectiveGapicConfiguration(protoPackage, methodsAllowList, true); + + FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); + // methodToGenerate from fileDescriptor: + // google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatShouldGenerateAsInternal + MethodDescriptor methodToGenerate = fileDescriptor.getServices().get(1).getMethods().get(3); + + assertEquals( + Parser.getMethodSelectiveGapicType(methodToGenerate, Optional.of(service), protoPackage), + SelectiveGapicType.INTERNAL); + } + + @Test + void selectiveGenerationTest_shouldGenerateAsHiddenIfMethodNotInListWithGenerateOmittedFalse() { + String protoPackage = "google.selective.generate.v1beta1"; + String methodsAllowList = + "google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual"; + Service service = + createServiceWithSelectiveGapicConfiguration(protoPackage, methodsAllowList, false); + + FileDescriptor fileDescriptor = SelectiveApiGenerationOuterClass.getDescriptor(); + // methodToGenerate from fileDescriptor: + // google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatShouldGenerateAsInternal + MethodDescriptor methodToGenerate = fileDescriptor.getServices().get(1).getMethods().get(3); + + assertEquals( + Parser.getMethodSelectiveGapicType(methodToGenerate, Optional.of(service), protoPackage), + SelectiveGapicType.HIDDEN); } private void assertMethodArgumentEquals( @@ -844,4 +951,33 @@ private void assertMethodArgumentEquals( private static Reference createStatusReference() { return VaporReference.builder().setName("Status").setPakkage("com.google.rpc").build(); } + + private static Service createServiceWithSelectiveGapicConfiguration( + String protoPackage, String methodsAllowList, boolean generateOmittedAsInternal) { + // Create a service with method allow-list and generateOmittedAsInternal flag. + JavaSettings java_settings = + JavaSettings.newBuilder() + .setLibraryPackage("com.google.foobar.v1") + .putServiceClassNames("com.google.foo.v1.BarService", "BazService") + .setCommon( + CommonLanguageSettings.newBuilder() + .setSelectiveGapicGeneration( + SelectiveGapicGeneration.newBuilder() + .addMethods(methodsAllowList) + .setGenerateOmittedAsInternal(generateOmittedAsInternal))) + .build(); + ClientLibrarySettings clientLibrarySettings = + ClientLibrarySettings.newBuilder() + .setVersion(protoPackage) + .setJavaSettings(java_settings) + .build(); + Publishing publishing = + Publishing.newBuilder().addLibrarySettings(clientLibrarySettings).build(); + Service service = + Service.newBuilder() + .setTitle("Selective generation test") + .setPublishing(publishing) + .build(); + return service; + } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java index 4172581d06..1030e8231e 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java @@ -39,6 +39,7 @@ import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.pubsub.v1.PubsubProto; +import com.google.selective.generate.v1beta1.SelectiveApiGenerationOuterClass; import com.google.showcase.v1beta1.EchoOuterClass; import com.google.showcase.v1beta1.IdentityOuterClass; import com.google.showcase.v1beta1.MessagingOuterClass; @@ -361,6 +362,49 @@ public GapicContext parseAutoPopulateFieldTesting() { .build(); } + public GapicContext parseSelectiveGenerationTesting() { + FileDescriptor selectiveGenerationFileDescriptor = + SelectiveApiGenerationOuterClass.getDescriptor(); + ServiceDescriptor selectiveGenerationServiceDescriptor = + selectiveGenerationFileDescriptor.getServices().get(1); + assertEquals( + "EchoServiceShouldGeneratePartialUsual", selectiveGenerationServiceDescriptor.getName()); + + String serviceYamlFilename = "selective_api_generation_generate_omitted_v1beta1.yaml"; + Path serviceYamlPath = Paths.get(testFilesDirectory, serviceYamlFilename); + Optional serviceYamlOpt = + ServiceYamlParser.parse(serviceYamlPath.toString()); + assertTrue(serviceYamlOpt.isPresent()); + + Map messageTypes = Parser.parseMessages(selectiveGenerationFileDescriptor); + Map resourceNames = + Parser.parseResourceNames(selectiveGenerationFileDescriptor); + Set outputResourceNames = new HashSet<>(); + List services = + Parser.parseService( + selectiveGenerationFileDescriptor, + messageTypes, + resourceNames, + serviceYamlOpt, + outputResourceNames); + + String jsonFilename = "selective_api_generation_grpc_service_config.json"; + Path jsonPath = Paths.get(testFilesDirectory, jsonFilename); + Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); + assertTrue(configOpt.isPresent()); + GapicServiceConfig config = configOpt.get(); + return GapicContext.builder() + .setMessages(messageTypes) + .setResourceNames(resourceNames) + .setServices(services) + .setHelperResourceNames(outputResourceNames) + .setServiceYamlProto(serviceYamlOpt.orElse(null)) + .setGapicMetadataEnabled(true) + .setServiceConfig(config) + .setTransport(transport) + .build(); + } + public GapicContext parsePubSubPublisher() { FileDescriptor serviceFileDescriptor = PubsubProto.getDescriptor(); FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor(); diff --git a/gapic-generator-java/src/test/proto/selective_api_generation.proto b/gapic-generator-java/src/test/proto/selective_api_generation.proto index 06da2c2e41..e75ee58134 100644 --- a/gapic-generator-java/src/test/proto/selective_api_generation.proto +++ b/gapic-generator-java/src/test/proto/selective_api_generation.proto @@ -38,15 +38,16 @@ option (google.api.resource_definition) = { // This proto is used to test selective api generation // covered scenarios: -// - A service with several rpcs, part of them should be generated -// - A service with several rpcs, none of them should be generated -// This proto should be tested side-by-side with yaml file: -// - selective_api_generation_v1beta1.yaml +// - A service with several rpcs, all of them should be generated as public methods +// - A service with several rpcs, part of them should be generated as public methods +// - A service with several rpcs, none of them should be generated as public methods +// This proto should be tested side-by-side with yaml files: +// - selective_api_generation_v1beta1.yaml or - selective_api_generation_generate_omitted_v1beta1.yaml -service EchoServiceShouldGeneratePartial { +service EchoServiceShouldGenerateAllAsUsual { option (google.api.default_host) = "localhost:7469"; - rpc EchoShouldInclude(EchoRequest) returns (EchoResponse) { + rpc EchoShouldGenerateAsUsual(EchoRequest) returns (EchoResponse) { option (google.api.http) = { post: "/v1beta1/echo:echo" body: "*" @@ -55,28 +56,53 @@ service EchoServiceShouldGeneratePartial { option (google.api.method_signature) = ""; } - rpc ChatShouldInclude(stream EchoRequest) returns (stream EchoResponse); + rpc ChatShouldGenerateAsUsual(stream EchoRequest) returns (stream EchoResponse); - rpc ChatAgainShouldInclude(stream EchoRequest) returns (stream EchoResponse) { + rpc ChatAgainShouldGenerateAsUsual(stream EchoRequest) returns (stream EchoResponse) { option (google.api.method_signature) = "content"; } +} + +service EchoServiceShouldGeneratePartialUsual { + option (google.api.default_host) = "localhost:7469"; + + rpc EchoShouldGenerateAsUsual(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1beta1/echo:echo" + body: "*" + }; + option (google.api.method_signature) = "name"; + option (google.api.method_signature) = ""; + } - rpc AnExcludedMethod(stream EchoRequestWithFoobarbaz) returns (stream EchoResponse); + rpc ChatShouldGenerateAsUsual(stream EchoRequest) returns (stream EchoResponse); - rpc AnotherExcludedMethod(stream EchoRequest) returns (stream EchoResponse); + rpc ChatAgainShouldGenerateAsUsual(stream EchoRequest) returns (stream EchoResponse) { + option (google.api.method_signature) = "content"; + } + + rpc ChatShouldGenerateAsInternal(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1beta1/echo:echo" + body: "*" + }; + option (google.api.method_signature) = "name"; + option (google.api.method_signature) = ""; + }; + rpc EchoShouldGenerateAsInternal(stream EchoRequest) returns (stream EchoResponse); } -service EchoServiceShouldGenerateNone { +service EchoServiceShouldGenerateAllInternal { option (google.api.default_host) = "localhost:7469"; option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; - rpc Echo(EchoRequest) returns (EchoResponse) { + rpc EchoShouldGenerateAsInternal(EchoRequest) returns (EchoResponse) { option (google.api.method_signature) = "content"; } - rpc ChatAgain(stream EchoRequest) returns (stream EchoResponse) { + rpc ChatShouldGenerateAsInternal(stream EchoRequest) returns (stream EchoResponse) { option (google.api.method_signature) = "content"; } } diff --git a/gapic-generator-java/src/test/resources/selective_api_generation_generate_omitted_v1beta1.yaml b/gapic-generator-java/src/test/resources/selective_api_generation_generate_omitted_v1beta1.yaml new file mode 100644 index 0000000000..74669ff7b6 --- /dev/null +++ b/gapic-generator-java/src/test/resources/selective_api_generation_generate_omitted_v1beta1.yaml @@ -0,0 +1,27 @@ +type: google.api.Service +config_version: 3 +name: selective_api_generation_testing.googleapis.com +title: Selective Generation Testing API + +publishing: + # ... + library_settings: + - version: google.selective.generate.v1beta1 + java_settings: + common: + selective_gapic_generation: + methods: + - google.selective.generate.v1beta1.EchoServiceShouldGenerateAllAsUsual.EchoShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGenerateAllAsUsual.ChatShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGenerateAllAsUsual.ChatAgainShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatAgainShouldGenerateAsUsual + generate_omitted_as_internal: true + reference_docs_uri: www.abc.net + destinations: + - PACKAGE_MANAGER + python_settings: + common: + destinations: + - PACKAGE_MANAGER diff --git a/gapic-generator-java/src/test/resources/selective_api_generation_v1beta1.yaml b/gapic-generator-java/src/test/resources/selective_api_generation_v1beta1.yaml index 021e257c50..cd99776e80 100644 --- a/gapic-generator-java/src/test/resources/selective_api_generation_v1beta1.yaml +++ b/gapic-generator-java/src/test/resources/selective_api_generation_v1beta1.yaml @@ -11,9 +11,10 @@ publishing: common: selective_gapic_generation: methods: - - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartial.EchoShouldInclude - - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartial.ChatShouldInclude - - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartial.ChatAgainShouldInclude + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.EchoShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatShouldGenerateAsUsual + - google.selective.generate.v1beta1.EchoServiceShouldGeneratePartialUsual.ChatAgainShouldGenerateAsUsual + generate_omitted_as_internal: false reference_docs_uri: www.abc.net destinations: - PACKAGE_MANAGER