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 bc8546e5c5..c7bdd73059 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 @@ -149,7 +149,8 @@ static List createClassHeaderComments( clientName, clientType, settingsName, settingsType)); classHeaderJavadocBuilder.addParagraph(SERVICE_DESCRIPTION_ENDPOINT_SUMMARY_STRING); classHeaderJavadocBuilder.addSampleCode( - ServiceClientSampleCodeComposer.composeClassHeaderEndpointSampleCode(service, types)); + ServiceClientSampleCodeComposer.composeClassHeaderEndpointSampleCode( + clientName, clientType, settingsName, settingsType)); return Arrays.asList( CommentComposer.AUTO_GENERATED_CLASS_COMMENT, 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 b848a0c0fa..126fe4efc4 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 @@ -33,7 +33,7 @@ import java.util.stream.Collectors; public class ServiceClientSampleCodeComposer { - //TODO(summerji): Add unit tests for ServiceClientSampleCodeComposer. + // TODO(summerji): Add unit tests for ServiceClientSampleCodeComposer. public static String composeClassHeaderCredentialsSampleCode( String clientName, TypeNode clientType, String settingsName, TypeNode settingsType) { @@ -92,13 +92,13 @@ public static String composeClassHeaderCredentialsSampleCode( } public static String composeClassHeaderEndpointSampleCode( - Service service, Map types) { - String settingsVarName = JavaStyle.toLowerCamelCase(getSettingsName(service.name())); - TypeNode settingsVarType = types.get(getSettingsName(service.name())); - VariableExpr settingsVarExpr = createVariableExpr(settingsVarName, settingsVarType); + String clientName, TypeNode clientType, String settingsName, TypeNode settingsType) { + // Initialize client settings with builder() method. + // e.g. EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build(); + VariableExpr settingsVarExpr = createVariableExpr(settingsName, settingsType); MethodInvocationExpr newBuilderMethodExpr = MethodInvocationExpr.builder() - .setStaticReferenceType(settingsVarType) + .setStaticReferenceType(settingsType) .setMethodName("newBuilder") .build(); MethodInvocationExpr credentialsMethodExpr = @@ -110,7 +110,7 @@ public static String composeClassHeaderEndpointSampleCode( MethodInvocationExpr buildMethodExpr = MethodInvocationExpr.builder() .setExprReferenceExpr(credentialsMethodExpr) - .setReturnType(settingsVarType) + .setReturnType(settingsType) .setMethodName("build") .build(); @@ -120,8 +120,8 @@ public static String composeClassHeaderEndpointSampleCode( .setValueExpr(buildMethodExpr) .build(); - String clientName = JavaStyle.toLowerCamelCase(getClientClassName(service.name())); - TypeNode clientType = types.get(getClientClassName(service.name())); + // Initialize client with create() method. + // e.g. EchoClient echoClient = EchoClient.create(echoSettings); VariableExpr clientVarExpr = createVariableExpr(clientName, clientType); MethodInvocationExpr createMethodExpr = MethodInvocationExpr.builder()