diff --git a/src/main/java/com/google/api/generator/gapic/composer/Composer.java b/src/main/java/com/google/api/generator/gapic/composer/Composer.java index 02e1dc9bcc..adf5f03432 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/Composer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/Composer.java @@ -60,8 +60,8 @@ public static List generateServiceClasses( @Nonnull Map resourceNames, @Nonnull Map messageTypes) { List clazzes = new ArrayList<>(); - clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes)); - clazzes.addAll(generateClientSettingsClasses(service, messageTypes)); + clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes, resourceNames)); + clazzes.addAll(generateClientSettingsClasses(service, messageTypes, resourceNames)); clazzes.addAll(generateMocksAndTestClasses(service, resourceNames, messageTypes)); // TODO(miraleung): Generate test classes. return clazzes; @@ -76,7 +76,10 @@ public static List generateResourceNameHelperClasses( } public static List generateStubClasses( - Service service, GapicServiceConfig serviceConfig, Map messageTypes) { + Service service, + GapicServiceConfig serviceConfig, + Map messageTypes, + Map resourceNames) { List clazzes = new ArrayList<>(); clazzes.add(ServiceStubClassComposer.instance().generate(service, messageTypes)); clazzes.add( @@ -87,9 +90,10 @@ public static List generateStubClasses( } public static List generateClientSettingsClasses( - Service service, Map messageTypes) { + Service service, Map messageTypes, Map resourceNames) { List clazzes = new ArrayList<>(); - clazzes.add(ServiceClientClassComposer.instance().generate(service, messageTypes)); + clazzes.add( + ServiceClientClassComposer.instance().generate(service, messageTypes, resourceNames)); clazzes.add(ServiceSettingsClassComposer.instance().generate(service, messageTypes)); return clazzes; } diff --git a/src/main/java/com/google/api/generator/gapic/composer/DefaultValueComposer.java b/src/main/java/com/google/api/generator/gapic/composer/DefaultValueComposer.java index a8d89f3932..c1b826851d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/DefaultValueComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/DefaultValueComposer.java @@ -50,7 +50,7 @@ public class DefaultValueComposer { TypeNode.withReference(ConcreteReference.withClazz(ByteString.class)); static Expr createDefaultValue( - MethodArgument methodArg, Map resourceNames) { + MethodArgument methodArg, Map resourceNames, boolean useSampleCode) { if (methodArg.isResourceNameHelper()) { Preconditions.checkState( methodArg.field().hasResourceReference(), @@ -71,18 +71,29 @@ static Expr createDefaultValue( } if (methodArg.type().equals(methodArg.field().type())) { - return createDefaultValue(methodArg.field()); + return createDefaultValue(methodArg.field(), resourceNames, useSampleCode); } return createDefaultValue( - Field.builder().setName(methodArg.name()).setType(methodArg.type()).build()); + Field.builder().setName(methodArg.name()).setType(methodArg.type()).build(), + resourceNames, + useSampleCode); + } + + static Expr createDefaultValue( + Field f, Map resourceNames, Boolean useSampleCode) { + return createDefaultValue(f, resourceNames, false, useSampleCode); } static Expr createDefaultValue(Field f) { - return createDefaultValue(f, false); + return createDefaultValue(f, new HashMap<>(), false, false); } - static Expr createDefaultValue(Field f, boolean useExplicitInitTypeInGenerics) { + static Expr createDefaultValue( + Field f, + Map resourceNames, + boolean useExplicitInitTypeInGenerics, + boolean useSampleCode) { if (f.isRepeated()) { ConcreteReference.Builder refBuilder = ConcreteReference.builder().setClazz(f.isMap() ? HashMap.class : ArrayList.class); @@ -123,6 +134,13 @@ static Expr createDefaultValue(Field f, boolean useExplicitInitTypeInGenerics) { } if (f.type().equals(TypeNode.STRING)) { + if (useSampleCode + && f.hasResourceReference() + && resourceNames.containsKey(f.resourceReference().resourceTypeString())) { + ResourceName resourceName = resourceNames.get(f.resourceReference().resourceTypeString()); + return createDefaultValue( + resourceName, resourceNames.values().stream().collect(Collectors.toList()), f.name()); + } return ValueExpr.withValue( StringObjectValue.withValue(String.format("%s%s", f.name(), f.name().hashCode()))); } @@ -255,7 +273,7 @@ static Expr createSimpleMessageBuilderExpr( .setReturnType(TypeNode.STRING) .build(); } else { - defaultExpr = createDefaultValue(field, true); + defaultExpr = createDefaultValue(field, resourceNames, true, false); } builderExpr = MethodInvocationExpr.builder() diff --git a/src/main/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposer.java b/src/main/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposer.java new file mode 100644 index 0000000000..7fa778b0c3 --- /dev/null +++ b/src/main/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposer.java @@ -0,0 +1,208 @@ +// Copyright 2020 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; + +import com.google.api.generator.engine.ast.AssignmentExpr; +import com.google.api.generator.engine.ast.ConcreteReference; +import com.google.api.generator.engine.ast.Expr; +import com.google.api.generator.engine.ast.ExprStatement; +import com.google.api.generator.engine.ast.MethodInvocationExpr; +import com.google.api.generator.engine.ast.TryCatchStatement; +import com.google.api.generator.engine.ast.TypeNode; +import com.google.api.generator.engine.ast.Variable; +import com.google.api.generator.engine.ast.VariableExpr; +import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; +import com.google.api.generator.gapic.utils.JavaStyle; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class MethodSampleCodeHelperComposer { + private static String RESPONSE = "response"; + + public static TryCatchStatement composeUnaryRpcMethodSampleCode( + Method method, + List arguments, + TypeNode clientType, + Map resourceNames) { + VariableExpr clientVarExpr = createVariableExpr(getClientName(clientType), clientType); + // Assign each method arguments with its default value. + Map methodArgVarExprMap = createMethodArgumentsVariableExprs(arguments); + List methodArgumentsAssignmentExpr = + assignMethodArgumentsWithDefaultValues(arguments, methodArgVarExprMap, resourceNames); + List methodVarExprs = + createMethodArgVarExprs(arguments, methodArgVarExprMap, resourceNames); + // Invoke current method based on return type. + // e.g. if return void, echoClient.echo(..); or, + // e.g. if return other type, EchoResponse response = echoClient.echo(...); + boolean returnsVoid = isProtoEmptyType(method.outputType()); + Expr responseExpr = null; + if (returnsVoid) { + responseExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(method.name())) + .setArguments(methodVarExprs) + .setReturnType(clientType) + .build(); + } else { + responseExpr = + createAssignExprForVariableWithClientMethod( + createVariableExpr(RESPONSE, method.outputType()), + clientVarExpr, + JavaStyle.toLowerCamelCase(method.name()), + methodVarExprs); + } + + List bodyExpr = new ArrayList<>(); + bodyExpr.addAll(methodArgumentsAssignmentExpr); + bodyExpr.add(responseExpr); + + return TryCatchStatement.builder() + .setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr)) + .setTryBody( + bodyExpr.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())) + .setIsSampleCode(true) + .build(); + } + + // ==================================Helpers===================================================// + + // Assign client variable expr with create client. + // e.g EchoClient echoClient = EchoClient.create() + private static AssignmentExpr assignClientVariableWithCreateMethodExpr( + VariableExpr clientVarExpr) { + return AssignmentExpr.builder() + .setVariableExpr(clientVarExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr( + MethodInvocationExpr.builder() + .setStaticReferenceType(clientVarExpr.variable().type()) + .setReturnType(clientVarExpr.variable().type()) + .setMethodName("create") + .build()) + .build(); + } + + // Create a Map where key is method's argument name, and value is its VariableExpr. + private static Map createMethodArgumentsVariableExprs( + List arguments) { + return arguments.stream() + .collect( + Collectors.toMap( + methodArg -> methodArg.name(), + methodArg -> + createVariableExpr( + JavaStyle.toLowerCamelCase(methodArg.name()), methodArg.type()))); + } + + // Return a list of AssignmentExpr for method argument with its default value. + private static List assignMethodArgumentsWithDefaultValues( + List arguments, + Map argVarExprs, + Map resourceNames) { + List resourceNameList = resourceNames.values().stream().collect(Collectors.toList()); + return arguments.stream() + .map( + arg -> { + Expr defaultValueExpr = + DefaultValueComposer.createDefaultValue(arg, resourceNames, false); + if (!arg.isResourceNameHelper() && arg.type().equals(TypeNode.STRING) && arg.field().hasResourceReference() && resourceNames.containsKey(arg.field().resourceReference().resourceTypeString())) { + ResourceName resourceName = + resourceNames.get(arg.field().resourceReference().resourceTypeString()); + defaultValueExpr = DefaultValueComposer.createDefaultValue(resourceName, resourceNameList, arg.field().name()); + } + VariableExpr argVarExpr = + (arg.field().hasResourceReference() && !arg.isResourceNameHelper()) + ? getMethodArgumentResourceReferenceVariableExpr(arg, defaultValueExpr) + : argVarExprs.get(arg.name()); + return createAssignmentExpr(argVarExpr, defaultValueExpr); + }) + .collect(Collectors.toList()); + } + + private static VariableExpr getMethodArgumentResourceReferenceVariableExpr( + MethodArgument methodArg, Expr defaultValueExpr) { + TypeNode resourceReferenceType = + methodArg.field().resourceReference().isChildType() + ? TypeNode.withReference( + ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class)) + : defaultValueExpr.type(); + return createVariableExpr(JavaStyle.toLowerCamelCase(methodArg.name()), resourceReferenceType); + } + + private static List createMethodArgVarExprs( + List arguments, + Map methodArgVarExprMap, + Map resourceNames) { + return arguments.stream() + .map( + arg -> { + if (!arg.isResourceNameHelper() + && arg.field().hasResourceReference() + && resourceNames.containsKey( + arg.field().resourceReference().resourceTypeString())) { + return MethodInvocationExpr.builder() + .setExprReferenceExpr(methodArgVarExprMap.get(arg.name())) + .setMethodName("toString") + .build(); + } + return methodArgVarExprMap.get(arg.name()); + }) + .collect(Collectors.toList()); + } + + private static Expr createAssignExprForVariableWithClientMethod( + VariableExpr variableExpr, + VariableExpr clientVarExpr, + String methodName, + List argumentsVarExprs) { + MethodInvocationExpr clientMethodInvocationExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(methodName)) + .setArguments(argumentsVarExprs) + .setReturnType(variableExpr.variable().type()) + .build(); + return AssignmentExpr.builder() + .setVariableExpr(variableExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(clientMethodInvocationExpr) + .build(); + } + + private static String getClientName(TypeNode clientType) { + return JavaStyle.toLowerCamelCase(clientType.reference().name()); + } + + private static boolean isProtoEmptyType(TypeNode type) { + return type.reference().pakkage().equals("com.google.protobuf") + && type.reference().name().equals("Empty"); + } + + private static AssignmentExpr createAssignmentExpr(VariableExpr variableExpr, Expr valueExpr) { + return AssignmentExpr.builder() + .setVariableExpr(variableExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(valueExpr) + .build(); + } + + private static VariableExpr createVariableExpr(String variableName, TypeNode type) { + return VariableExpr.builder() + .setVariable(Variable.builder().setName(variableName).setType(type).build()) + .build(); + } +} diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java index 5f6a00f4d8..d86d9dffcb 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java @@ -62,6 +62,7 @@ import com.google.api.generator.gapic.model.Method; import com.google.api.generator.gapic.model.Method.Stream; import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.utils.JavaStyle; import com.google.common.annotations.VisibleForTesting; @@ -84,7 +85,7 @@ import java.util.stream.Collectors; import javax.annotation.Generated; -public class ServiceClientClassComposer implements ClassComposer { +public class ServiceClientClassComposer { private static final ServiceClientClassComposer INSTANCE = new ServiceClientClassComposer(); private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private static final String CALLABLE_NAME_PATTERN = "%sCallable"; @@ -108,8 +109,10 @@ public static ServiceClientClassComposer instance() { return INSTANCE; } - @Override - public GapicClass generate(Service service, Map messageTypes) { + public GapicClass generate( + Service service, Map messageTypes, Map resourceNames) { + // TODO(miraleung): Clean up the hierarchy to avoid pass another parameter (resourceNames is + // only used for composing sample code). See b/174257081. Map types = createTypes(service, messageTypes); String className = getClientClassName(service); GapicClass.Kind kind = Kind.MAIN; @@ -129,7 +132,8 @@ public GapicClass generate(Service service, Map messageTypes) { .setName(className) .setImplementsTypes(createClassImplements(types)) .setStatements(createFieldDeclarations(service, types, hasLroClient)) - .setMethods(createClassMethods(service, messageTypes, types, hasLroClient)) + .setMethods( + createClassMethods(service, messageTypes, types, resourceNames, hasLroClient)) .setNestedClasses(createNestedPagingClasses(service, messageTypes, types)) .build(); return GapicClass.create(kind, classDef); @@ -152,12 +156,13 @@ private static List createClassMethods( Service service, Map messageTypes, Map types, + Map resourceNames, boolean hasLroClient) { List methods = new ArrayList<>(); methods.addAll(createStaticCreatorMethods(service, types)); methods.addAll(createConstructorMethods(service, types, hasLroClient)); methods.addAll(createGetterMethods(service, types, hasLroClient)); - methods.addAll(createServiceMethods(service, messageTypes, types)); + methods.addAll(createServiceMethods(service, messageTypes, types, resourceNames)); methods.addAll(createBackgroundResourceMethods(service, types)); return methods; } @@ -471,11 +476,16 @@ private static List createGetterMethods( } private static List createServiceMethods( - Service service, Map messageTypes, Map types) { + Service service, + Map messageTypes, + Map types, + Map resourceNames) { List javaMethods = new ArrayList<>(); + String clientName = getClientClassName(service); for (Method method : service.methods()) { if (method.stream().equals(Stream.NONE)) { - javaMethods.addAll(createMethodVariants(method, messageTypes, types)); + javaMethods.addAll( + createMethodVariants(method, messageTypes, types, clientName, resourceNames)); javaMethods.add(createMethodDefaultMethod(method, types)); } if (method.hasLro()) { @@ -490,7 +500,11 @@ private static List createServiceMethods( } private static List createMethodVariants( - Method method, Map messageTypes, Map types) { + Method method, + Map messageTypes, + Map types, + String clientName, + Map resourceNames) { List javaMethods = new ArrayList<>(); String methodName = JavaStyle.toLowerCamelCase(method.name()); TypeNode methodInputType = method.inputType(); @@ -552,10 +566,19 @@ private static List createMethodVariants( .setReturnType(methodOutputType) .build(); + String methodSampleCode = ""; + if (!method.isPaged() && !method.hasLro()) { + // TODO(summerji): Remove the condition check once finished the implementation on paged + // sample code and lro sample code. + methodSampleCode = + ServiceClientSampleCodeComposer.composeRpcMethodHeaderSampleCode( + method, signature, types.get(clientName), resourceNames); + } MethodDefinition.Builder methodVariantBuilder = MethodDefinition.builder() .setHeaderCommentStatements( - ServiceClientCommentComposer.createRpcMethodHeaderComment(method, signature)) + ServiceClientCommentComposer.createRpcMethodHeaderComment( + method, signature, methodSampleCode)) .setScope(ScopeNode.PUBLIC) .setIsFinal(true) .setName(String.format(method.hasLro() ? "%sAsync" : "%s", methodName)) diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java index 09507cd30f..2d512a4ad0 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java @@ -162,7 +162,7 @@ static CommentStatement createCreateMethodStubArgComment( } static List createRpcMethodHeaderComment( - Method method, List methodArguments) { + Method method, List methodArguments, String sampleCode) { JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder(); if (method.hasDescription()) { @@ -170,8 +170,10 @@ static List createRpcMethodHeaderComment( processProtobufComment(method.description(), methodJavadocBuilder, null); } - // methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING); - // TODO(summerji): Add sample code here and uncomment the above. + if (!sampleCode.isEmpty()) { + methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING); + methodJavadocBuilder.addSampleCode(sampleCode); + } if (methodArguments.isEmpty()) { methodJavadocBuilder.addParam( @@ -196,7 +198,8 @@ static List createRpcMethodHeaderComment( } static List createRpcMethodHeaderComment(Method method) { - return createRpcMethodHeaderComment(method, Collections.emptyList()); + // TODO(summerji): Refactor this method when implement default method sample code. + return createRpcMethodHeaderComment(method, Collections.emptyList(), ""); } static CommentStatement createMethodNoArgComment(String serviceName) { diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java index 4f40f9fd71..9858b3781d 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java @@ -28,9 +28,13 @@ import com.google.api.generator.engine.writer.JavaWriterVisitor; import com.google.api.generator.gapic.composer.samplecode.SampleCodeJavaFormatter; import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter; +import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.utils.JavaStyle; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class ServiceClientSampleCodeComposer { @@ -161,6 +165,16 @@ public static String composeClassHeaderEndpointSampleCode( ExprStatement.withExpr(initClientVarExpr))); } + public static String composeRpcMethodHeaderSampleCode( + Method method, + List arguments, + TypeNode clientType, + Map resourceNames) { + return SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + method, arguments, clientType, resourceNames)); + } + // ======================================== Helpers ==========================================// // TODO(summerji): Use writeSampleCode method in new class once PR#499 merged. private static String writeSampleCode(List exprs) { diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java index 6a5a4802f9..48191c8ca6 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java @@ -610,7 +610,7 @@ private static MethodDefinition createRpcTestMethod( VariableExpr.withVariable( Variable.builder().setType(methodArg.type()).setName(methodArgName).build()); argExprs.add(varExpr); - Expr valExpr = DefaultValueComposer.createDefaultValue(methodArg, resourceNames); + Expr valExpr = DefaultValueComposer.createDefaultValue(methodArg, resourceNames, false); methodExprs.add( AssignmentExpr.builder() .setVariableExpr(varExpr.toBuilder().setIsDecl(true).build()) @@ -1484,7 +1484,7 @@ private static List createRpcExceptionTestStatements( VariableExpr.withVariable( Variable.builder().setType(methodArg.type()).setName(methodArgName).build()); argVarExprs.add(varExpr); - Expr valExpr = DefaultValueComposer.createDefaultValue(methodArg, resourceNames); + Expr valExpr = DefaultValueComposer.createDefaultValue(methodArg, resourceNames, false); tryBodyExprs.add( AssignmentExpr.builder() .setVariableExpr(varExpr.toBuilder().setIsDecl(true).build()) diff --git a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel index 0e0e941a90..8456ee092f 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel @@ -22,6 +22,7 @@ TESTS = UPDATE_GOLDENS_TESTS + [ "DefaultValueComposerTest", "ResourceNameTokenizerTest", "RetrySettingsComposerTest", + "MethodSampleCodeHelperComposerTest", ] TEST_DEPS = [ @@ -38,6 +39,7 @@ TEST_DEPS = [ "//src/main/java/com/google/api/generator/gapic/protoparser", "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", "//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto", + "@com_google_api_api_common//jar", "@com_google_api_gax_java//gax", "@com_google_googleapis//google/logging/v2:logging_java_proto", "@com_google_googleapis//google/pubsub/v1:pubsub_java_proto", diff --git a/src/test/java/com/google/api/generator/gapic/composer/DefaultValueComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/DefaultValueComposerTest.java index 5893f2f17f..0b1d553c14 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/DefaultValueComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/DefaultValueComposerTest.java @@ -22,7 +22,9 @@ import com.google.api.generator.engine.writer.JavaWriterVisitor; import com.google.api.generator.gapic.model.Field; import com.google.api.generator.gapic.model.Message; +import com.google.api.generator.gapic.model.MethodArgument; import com.google.api.generator.gapic.model.ResourceName; +import com.google.api.generator.gapic.model.ResourceReference; import com.google.api.generator.gapic.protoparser.Parser; import com.google.protobuf.ByteString; import com.google.protobuf.Descriptors.FileDescriptor; @@ -298,4 +300,76 @@ public void createSimpleMessage_onlyOneofs() { expr.accept(writerVisitor); assertEquals("WaitRequest.newBuilder().build()", writerVisitor.write()); } + + @Test + public void createSampleCodeDefaultValue_stringReferenceResourceName() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map typeStringsToResourceNames = + Parser.parseResourceNames(echoFileDescriptor); + Field stringReferenceResourceField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("showcase.googleapis.com/Foobar")) + .build(); + MethodArgument methodArgument = + MethodArgument.builder() + .setName("name") + .setField(stringReferenceResourceField) + .setType(TypeNode.STRING) + .build(); + Expr expr = + DefaultValueComposer.createDefaultValue(methodArgument, typeStringsToResourceNames, true); + expr.accept(writerVisitor); + assertEquals( + "FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\")", writerVisitor.write()); + } + + @Test + public void createSampleCodeDefaultValue_parentReferenceResourceName() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map typeStringsToResourceNames = + Parser.parseResourceNames(echoFileDescriptor); + Field stringReferenceResourceField = + Field.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withChildType("showcase.googleapis.com/AnythingGoes")) + .build(); + MethodArgument methodArgument = + MethodArgument.builder() + .setName("parent") + .setField(stringReferenceResourceField) + .setType(TypeNode.STRING) + .build(); + Expr expr = + DefaultValueComposer.createDefaultValue(methodArgument, typeStringsToResourceNames, true); + expr.accept(writerVisitor); + assertEquals( + "FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\")", writerVisitor.write()); + } + + @Test + public void createSampleCodeDefaultValue_noExistReferenceResourceName() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map typeStringsToResourceNames = + Parser.parseResourceNames(echoFileDescriptor); + Field stringReferenceResourceField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("no.matched.resource.name/abc")) + .build(); + MethodArgument methodArgument = + MethodArgument.builder() + .setName("name") + .setField(stringReferenceResourceField) + .setType(TypeNode.STRING) + .build(); + Expr expr = + DefaultValueComposer.createDefaultValue(methodArgument, typeStringsToResourceNames, true); + expr.accept(writerVisitor); + assertEquals("\"name3373707\"", writerVisitor.write()); + } } diff --git a/src/test/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposerTest.java new file mode 100644 index 0000000000..cce3f8648e --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/MethodSampleCodeHelperComposerTest.java @@ -0,0 +1,494 @@ +// Copyright 2020 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; + +import static junit.framework.Assert.assertEquals; + +import com.google.api.generator.engine.ast.ConcreteReference; +import com.google.api.generator.engine.ast.Reference; +import com.google.api.generator.engine.ast.TypeNode; +import com.google.api.generator.engine.ast.VaporReference; +import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter; +import com.google.api.generator.gapic.model.Field; +import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; +import com.google.api.generator.gapic.model.ResourceReference; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class MethodSampleCodeHelperComposerTest { + private static final String PACKAGE_NAME = "com.google.showcase.v1beta1"; + private static final TypeNode clientType = + TypeNode.withReference( + VaporReference.builder().setName("EchoClient").setPakkage(PACKAGE_NAME).build()); + Map resourceNames = new HashMap<>(); + + @Before + public void setUp() { + ResourceName foobarResourceName = + ResourceName.builder() + .setVariableName("foobar") + .setPakkage(PACKAGE_NAME) + .setResourceTypeString("showcase.googleapis.com/Foobar") + .setPatterns( + Arrays.asList( + "projects/{project}/foobars/{foobar}", + "projects/{project}/chocolate/variants/{variant}/foobars/{foobar}", + "foobars/{foobar}", + "bar_foo/{bar_foo}/foobars/{foobar}")) + .setParentMessageName("Foobar") + .build(); + ResourceName anythingGoesResourceName = + ResourceName.createWildcard("showcase.googleapis.com/AnythingGoes", PACKAGE_NAME); + resourceNames.put("showcase.googleapis.com/Foobar", foobarResourceName); + resourceNames.put("showcase.googleapis.com/AnythingGoes", anythingGoesResourceName); + } + + @Test + public void composeUnaryRpcMethodSampleCode_resourceNameHelperMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + TypeNode resourceNameType = + TypeNode.withReference( + ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class)); + MethodArgument arg = + MethodArgument.builder() + .setName("parent") + .setType(resourceNameType) + .setField( + Field.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withType("showcase.googleapis.com/AnythingGoes")) + .build()) + .setIsResourceNameHelper(true) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " ResourceName parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n" + + " EchoResponse response = echoClient.echo(parent);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_isMessageMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + TypeNode methodArgType = + TypeNode.withReference( + VaporReference.builder().setName("Status").setPakkage("com.google.rpc").build()); + Field methodArgField = + Field.builder() + .setName("error") + .setType(methodArgType) + .setIsMessage(true) + .setIsContainedInOneof(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("error") + .setType(methodArgType) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " Status error = Status.newBuilder().build();\n" + + " EchoResponse response = echoClient.echo(error);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_superReferenceIsResourceNameMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + TypeNode methodArgType = + TypeNode.withReference( + VaporReference.builder() + .setName("FoobarName") + .setPakkage(PACKAGE_NAME) + .setSupertypeReference( + ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class)) + .build()); + Field methodArgField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("showcase.googleapis.com/Foobar")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("name") + .setType(methodArgType) + .setField(methodArgField) + .setIsResourceNameHelper(true) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " FoobarName name = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n" + + " EchoResponse response = echoClient.echo(name);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringIsContainedInOneOfMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + Field methodArgField = + Field.builder() + .setName("content") + .setType(TypeNode.STRING) + .setIsContainedInOneof(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("content") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String content = \"content951530617\";\n" + + " EchoResponse response = echoClient.echo(content);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_strinWithResourceReferenceMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + Field methodArgField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("showcase.googleapis.com/Foobar")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " FoobarName name = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n" + + " EchoResponse response = echoClient.echo(name.toString());\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringWithParentResourceReferenceMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + Field methodArgField = + Field.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withChildType("showcase.googleapis.com/AnythingGoes")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " ResourceName parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n" + + " EchoResponse response = echoClient.echo(parent.toString());\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_noMatchedResourceReferenceMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + Field methodArgField = + Field.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("no.matched.resource.name/abc")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String displayName = \"display_name1615086568\";\n" + + " EchoResponse response = echoClient.echo(displayName);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleWordNameMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + Field methodArgField = + Field.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withChildType("showcase.googleapis.com/AnythingGoes")) + .build(); + Reference userRef = VaporReference.builder().setName("User").setPakkage(PACKAGE_NAME).build(); + Field nestFiled = + Field.builder() + .setName("user") + .setType(TypeNode.withReference(userRef)) + .setIsMessage(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .setNestedFields(Arrays.asList(nestFiled)) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " ResourceName displayName = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n" + + " EchoResponse response = echoClient.echo(displayName.toString());\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleMethodArguments() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + MethodArgument arg1 = + MethodArgument.builder() + .setName("content") + .setType(TypeNode.STRING) + .setField(Field.builder().setName("content").setType(TypeNode.STRING).build()) + .build(); + TypeNode severityType = + TypeNode.withReference( + VaporReference.builder().setName("Severity").setPakkage(PACKAGE_NAME).build()); + MethodArgument arg2 = + MethodArgument.builder() + .setName("severity") + .setType(severityType) + .setField( + Field.builder().setName("severity").setType(severityType).setIsEnum(true).build()) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg1, arg2)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String content = \"content951530617\";\n" + + " Severity severity = Severity.forNumber(0);\n" + + " EchoResponse response = echoClient.echo(content, severity);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_methodReturnVoid() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("DeleteUserRequest") + .setPakkage("com.google.showcase.v1beta1") + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("Empty").setPakkage("com.google.protobuf").build()); + List> methodSignatures = + Arrays.asList( + Arrays.asList( + MethodArgument.builder() + .setName("name") + .setType(TypeNode.STRING) + .setField(Field.builder().setName("name").setType(TypeNode.STRING).build()) + .build())); + Method unaryMethod = + Method.builder() + .setName("delete") + .setMethodSignatures(methodSignatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + MethodSampleCodeHelperComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, methodSignatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String name = \"name3373707\";\n" + + " echoClient.delete(name);\n" + + "}"; + Assert.assertEquals(results, expected); + } +} diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java index 1a882a6a30..a45784aaa2 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java @@ -53,7 +53,8 @@ public void generateServiceClasses() { Service echoProtoService = services.get(0); GapicClass clazz = - ServiceClientClassComposer.instance().generate(echoProtoService, messageTypes); + ServiceClientClassComposer.instance() + .generate(echoProtoService, messageTypes, resourceNames); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); @@ -76,7 +77,8 @@ public void generateServiceClasses_methodSignatureHasNestedFields() { fileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); Service protoService = services.get(0); - GapicClass clazz = ServiceClientClassComposer.instance().generate(protoService, messageTypes); + GapicClass clazz = + ServiceClientClassComposer.instance().generate(protoService, messageTypes, resourceNames); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden index 2accd6e59d..3908bb0840 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden @@ -145,6 +145,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(parent);
+   * }
+   * }
+ * * @param parent * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -158,6 +167,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   Status error = Status.newBuilder().build();
+   *   EchoResponse response = echoClient.echo(error);
+   * }
+   * }
+ * * @param error * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -168,6 +186,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -179,6 +206,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String content = "content951530617";
+   *   EchoResponse response = echoClient.echo(content);
+   * }
+   * }
+ * * @param content * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -189,6 +225,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(name.toString());
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -199,6 +244,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(parent.toString());
+   * }
+   * }
+ * * @param parent * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -209,6 +263,16 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String content = "content951530617";
+   *   Severity severity = Severity.forNumber(0);
+   *   EchoResponse response = echoClient.echo(content, severity);
+   * }
+   * }
+ * * @param content * @param severity * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden index 091e335eee..c4a5f23048 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden @@ -125,6 +125,17 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ResourceName parent = UserName.of("[USER]");
+   *   String displayName = "display_name1615086568";
+   *   String email = "email96619420";
+   *   User response = identityClient.createUser(parent.toString(), displayName, email);
+   * }
+   * }
+ * * @param parent * @param display_name * @param email @@ -142,6 +153,29 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ResourceName parent = UserName.of("[USER]");
+   *   String displayName = "display_name1615086568";
+   *   String email = "email96619420";
+   *   int age = 96511;
+   *   String nickname = "nickname70690926";
+   *   boolean enableNotifications = true;
+   *   double heightFeet = -1032737338;
+   *   User response =
+   *       identityClient.createUser(
+   *           parent.toString(),
+   *           displayName,
+   *           email,
+   *           age,
+   *           nickname,
+   *           enableNotifications,
+   *           heightFeet);
+   * }
+   * }
+ * * @param parent * @param display_name * @param email @@ -189,6 +223,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   User response = identityClient.getUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -200,6 +243,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   User response = identityClient.getUser(name.toString());
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -240,6 +292,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   identityClient.deleteUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -253,6 +314,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   identityClient.deleteUser(name.toString());
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ diff --git a/test/integration/goldens/asset/AssetServiceClient.java b/test/integration/goldens/asset/AssetServiceClient.java index dad79b7391..a734e81a92 100644 --- a/test/integration/goldens/asset/AssetServiceClient.java +++ b/test/integration/goldens/asset/AssetServiceClient.java @@ -246,6 +246,15 @@ public final BatchGetAssetsHistoryResponse batchGetAssetsHistory( /** * Creates a feed in a parent project/folder/organization to listen to its asset updates. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String parent = "parent-995424086";
+   *   Feed response = assetServiceClient.createFeed(parent);
+   * }
+   * }
+ * * @param parent Required. The name of the project/folder/organization where this feed should be * created in. It can only be an organization number (such as "organizations/123"), a folder * number (such as "folders/123"), a project ID (such as "projects/my-project-id")", or a @@ -282,6 +291,15 @@ public final UnaryCallable createFeedCallable() { /** * Gets details about an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   Feed response = assetServiceClient.getFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the Feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -297,6 +315,15 @@ public final Feed getFeed(FeedName name) { /** * Gets details about an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   Feed response = assetServiceClient.getFeed(name.toString());
+   * }
+   * }
+ * * @param name Required. The name of the Feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -332,6 +359,15 @@ public final UnaryCallable getFeedCallable() { /** * Lists all asset feeds in a parent project/folder/organization. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String parent = "parent-995424086";
+   *   ListFeedsResponse response = assetServiceClient.listFeeds(parent);
+   * }
+   * }
+ * * @param parent Required. The parent project/folder/organization whose feeds are to be listed. It * can only be using project/folder/organization number (such as "folders/12345")", or a * project ID (such as "projects/my-project-id"). @@ -367,6 +403,15 @@ public final UnaryCallable listFeedsCallabl /** * Updates an asset feed configuration. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   Feed feed = Feed.newBuilder().build();
+   *   Feed response = assetServiceClient.updateFeed(feed);
+   * }
+   * }
+ * * @param feed Required. The new values of feed details. It must match an existing feed and the * field `name` must be in the format of: projects/project_number/feeds/feed_id or * folders/folder_number/feeds/feed_id or organizations/organization_number/feeds/feed_id. @@ -402,6 +447,15 @@ public final UnaryCallable updateFeedCallable() { /** * Deletes an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   assetServiceClient.deleteFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -419,6 +473,15 @@ public final void deleteFeed(FeedName name) { /** * Deletes an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   assetServiceClient.deleteFeed(name.toString());
+   * }
+   * }
+ * * @param name Required. The name of the feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id diff --git a/test/integration/goldens/library/LibraryServiceClient.java b/test/integration/goldens/library/LibraryServiceClient.java index e9d2780f0b..705d22a96a 100644 --- a/test/integration/goldens/library/LibraryServiceClient.java +++ b/test/integration/goldens/library/LibraryServiceClient.java @@ -171,6 +171,15 @@ public LibraryServiceStub getStub() { /** * Creates a shelf, and returns the new Shelf. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   Shelf shelf = Shelf.newBuilder().build();
+   *   Shelf response = libraryServiceClient.createShelf(shelf);
+   * }
+   * }
+ * * @param shelf The shelf to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -204,6 +213,15 @@ public final UnaryCallable createShelfCallable() { /** * Gets a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.getShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -217,6 +235,15 @@ public final Shelf getShelf(ShelfName name) { /** * Gets a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Shelf response = libraryServiceClient.getShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -285,6 +312,15 @@ public final UnaryCallable listShelvesC /** * Deletes a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   libraryServiceClient.deleteShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to delete. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -300,6 +336,15 @@ public final void deleteShelf(ShelfName name) { /** * Deletes a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   libraryServiceClient.deleteShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to delete. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -338,6 +383,16 @@ public final UnaryCallable deleteShelfCallable() { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -360,6 +415,16 @@ public final Shelf mergeShelves(ShelfName name, ShelfName otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   String otherShelfName = "other_shelf_name145746959";
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -382,6 +447,16 @@ public final Shelf mergeShelves(ShelfName name, String otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -404,6 +479,16 @@ public final Shelf mergeShelves(String name, ShelfName otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   String otherShelfName = "other_shelf_name145746959";
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -449,6 +534,16 @@ public final UnaryCallable mergeShelvesCallable() { /** * Creates a book, and returns the new Book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.createBook(name, book);
+   * }
+   * }
+ * * @param name The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -466,6 +561,16 @@ public final Book createBook(ShelfName name, Book book) { /** * Creates a book, and returns the new Book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.createBook(name, book);
+   * }
+   * }
+ * * @param name The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -500,6 +605,15 @@ public final UnaryCallable createBookCallable() { /** * Gets a book. Returns NOT_FOUND if the book does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   Book response = libraryServiceClient.getBook(name);
+   * }
+   * }
+ * * @param name The name of the book to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -513,6 +627,15 @@ public final Book getBook(BookName name) { /** * Gets a book. Returns NOT_FOUND if the book does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Book response = libraryServiceClient.getBook(name);
+   * }
+   * }
+ * * @param name The name of the book to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -636,6 +759,15 @@ public final UnaryCallable deleteBookCallable() { * Updates a book. Returns INVALID_ARGUMENT if the name of the book is non-empty and does not * equal the existing name. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.updateBook(book);
+   * }
+   * }
+ * * @param book The book to update with. The name must match or be empty. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -672,6 +804,16 @@ public final UnaryCallable updateBookCallable() { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -690,6 +832,16 @@ public final Book moveBook(BookName name, ShelfName otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   String otherShelfName = "other_shelf_name145746959";
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -708,6 +860,16 @@ public final Book moveBook(BookName name, String otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -726,6 +888,16 @@ public final Book moveBook(String name, ShelfName otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   String otherShelfName = "other_shelf_name145746959";
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/test/integration/goldens/logging/ConfigClient.java b/test/integration/goldens/logging/ConfigClient.java index 14f8749dc1..aab1689bb5 100644 --- a/test/integration/goldens/logging/ConfigClient.java +++ b/test/integration/goldens/logging/ConfigClient.java @@ -484,6 +484,15 @@ public final UnaryCallable listSinksCallabl /** * Gets a sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink response = configClient.getSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The resource name of the sink: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" @@ -504,6 +513,15 @@ public final LogSink getSink(LogSinkName sinkName) { /** * Gets a sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink response = configClient.getSink(sinkName.toString());
+   * }
+   * }
+ * * @param sink_name Required. The resource name of the sink: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" @@ -545,6 +563,16 @@ public final UnaryCallable getSinkCallable() { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -569,6 +597,16 @@ public final LogSink createSink(BillingAccountName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -593,6 +631,16 @@ public final LogSink createSink(FolderName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -617,6 +665,16 @@ public final LogSink createSink(OrganizationName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -641,6 +699,16 @@ public final LogSink createSink(ProjectName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ResourceName parent = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent.toString(), sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -690,6 +758,16 @@ public final UnaryCallable createSinkCallable() { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -718,6 +796,16 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink) { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName.toString(), sink);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -743,6 +831,17 @@ public final LogSink updateSink(String sinkName, LogSink sink) { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink, updateMask);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -781,6 +880,17 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink, FieldMask up *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName.toString(), sink, updateMask);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -845,6 +955,15 @@ public final UnaryCallable updateSinkCallable() { * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also * deleted. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   configClient.deleteSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to delete, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -867,6 +986,15 @@ public final void deleteSink(LogSinkName sinkName) { * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also * deleted. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   configClient.deleteSink(sinkName.toString());
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to delete, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -1023,6 +1151,15 @@ public final ListExclusionsPagedResponse listExclusions(ListExclusionsRequest re /** * Gets the description of an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion response = configClient.getExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1043,6 +1180,15 @@ public final LogExclusion getExclusion(LogExclusionName name) { /** * Gets the description of an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion response = configClient.getExclusion(name.toString());
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1082,6 +1228,16 @@ public final UnaryCallable getExclusionCallab * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1104,6 +1260,16 @@ public final LogExclusion createExclusion(BillingAccountName parent, LogExclusio * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1126,6 +1292,16 @@ public final LogExclusion createExclusion(FolderName parent, LogExclusion exclus * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1148,6 +1324,16 @@ public final LogExclusion createExclusion(OrganizationName parent, LogExclusion * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1170,6 +1356,16 @@ public final LogExclusion createExclusion(ProjectName parent, LogExclusion exclu * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ResourceName parent = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent.toString(), exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1211,6 +1407,17 @@ public final UnaryCallable createExclusion /** * Changes one or more properties of an existing exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configClient.updateExclusion(name, exclusion, updateMask);
+   * }
+   * }
+ * * @param name Required. The resource name of the exclusion to update: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1242,6 +1449,17 @@ public final LogExclusion updateExclusion( /** * Changes one or more properties of an existing exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configClient.updateExclusion(name.toString(), exclusion, updateMask);
+   * }
+   * }
+ * * @param name Required. The resource name of the exclusion to update: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1294,6 +1512,15 @@ public final UnaryCallable updateExclusion /** * Deletes an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   configClient.deleteExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion to delete: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1314,6 +1541,15 @@ public final void deleteExclusion(LogExclusionName name) { /** * Deletes an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   configClient.deleteExclusion(name.toString());
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion to delete: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" diff --git a/test/integration/goldens/logging/LoggingClient.java b/test/integration/goldens/logging/LoggingClient.java index 8b80772613..7a8c59ef32 100644 --- a/test/integration/goldens/logging/LoggingClient.java +++ b/test/integration/goldens/logging/LoggingClient.java @@ -164,6 +164,15 @@ public LoggingServiceV2Stub getStub() { * written shortly before the delete operation might not be deleted. Entries received after the * delete operation with a timestamp before the operation will be deleted. * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   loggingClient.deleteLog(logName);
+   * }
+   * }
+ * * @param log_name Required. The resource name of the log to delete: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]" @@ -186,6 +195,15 @@ public final void deleteLog(LogName logName) { * written shortly before the delete operation might not be deleted. Entries received after the * delete operation with a timestamp before the operation will be deleted. * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   loggingClient.deleteLog(logName.toString());
+   * }
+   * }
+ * * @param log_name Required. The resource name of the log to delete: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]" @@ -231,6 +249,19 @@ public final UnaryCallable deleteLogCallable() { * libraries configured to use Logging. A single request may contain log entries for a maximum of * 1000 different resources (projects, organizations, billing accounts or folders) * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingClient.writeLogEntries(logName, resource, labels, entries);
+   * }
+   * }
+ * * @param log_name Optional. A default log resource name that is assigned to all log entries in * `entries` that do not specify a value for `log_name`: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" @@ -293,6 +324,19 @@ public final WriteLogEntriesResponse writeLogEntries( * libraries configured to use Logging. A single request may contain log entries for a maximum of * 1000 different resources (projects, organizations, billing accounts or folders) * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingClient.writeLogEntries(logName.toString(), resource, labels, entries);
+   * }
+   * }
+ * * @param log_name Optional. A default log resource name that is assigned to all log entries in * `entries` that do not specify a value for `log_name`: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" diff --git a/test/integration/goldens/logging/MetricsClient.java b/test/integration/goldens/logging/MetricsClient.java index ab7d4fde63..2e7d2bc60f 100644 --- a/test/integration/goldens/logging/MetricsClient.java +++ b/test/integration/goldens/logging/MetricsClient.java @@ -215,6 +215,15 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re /** * Gets a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric response = metricsClient.getLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the desired metric: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -231,6 +240,15 @@ public final LogMetric getLogMetric(LogMetricName metricName) { /** * Gets a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric response = metricsClient.getLogMetric(metricName.toString());
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the desired metric: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -266,6 +284,16 @@ public final UnaryCallable getLogMetricCallable( /** * Creates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.createLogMetric(parent, metric);
+   * }
+   * }
+ * * @param parent Required. The resource name of the project in which to create the metric: *

"projects/[PROJECT_ID]" *

The new metric must be provided in the request. @@ -286,6 +314,16 @@ public final LogMetric createLogMetric(ProjectName parent, LogMetric metric) { /** * Creates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   ResourceName parent = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.createLogMetric(parent.toString(), metric);
+   * }
+   * }
+ * * @param parent Required. The resource name of the project in which to create the metric: *

"projects/[PROJECT_ID]" *

The new metric must be provided in the request. @@ -324,6 +362,16 @@ public final UnaryCallable createLogMetricCal /** * Creates or updates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.updateLogMetric(metricName, metric);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to update: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" *

The updated metric must be provided in the request and it's `name` field must be the @@ -345,6 +393,16 @@ public final LogMetric updateLogMetric(LogMetricName metricName, LogMetric metri /** * Creates or updates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.updateLogMetric(metricName.toString(), metric);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to update: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" *

The updated metric must be provided in the request and it's `name` field must be the @@ -384,6 +442,15 @@ public final UnaryCallable updateLogMetricCal /** * Deletes a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   metricsClient.deleteLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to delete: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -400,6 +467,15 @@ public final void deleteLogMetric(LogMetricName metricName) { /** * Deletes a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   metricsClient.deleteLogMetric(metricName.toString());
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to delete: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java index a65989a9f7..943c5559a3 100644 --- a/test/integration/goldens/redis/CloudRedisClient.java +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -291,6 +291,15 @@ public final UnaryCallable listInst /** * Gets the details of a specific Redis instance. * + *

Sample code: + * + *

{@code
+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name);
+   * }
+   * }
+ * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. @@ -308,6 +317,15 @@ public final Instance getInstance(InstanceName name) { /** * Gets the details of a specific Redis instance. * + *

Sample code: + * + *

{@code
+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name.toString());
+   * }
+   * }
+ * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region.