Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ServiceClientCommentComposer {
private static final String EXCEPTION_CONDITION = "if the remote call fails";

// Constants.
private static final String SERVICE_API_VERSION_STRING =
"This service client implements API version: %s.";
private static final String SERVICE_DESCRIPTION_INTRO_STRING =
"This class provides the ability to make remote calls to the backing service through method "
+ "calls that map to API methods. Sample code to get started:";
Expand Down Expand Up @@ -114,6 +116,11 @@ public static List<CommentStatement> createClassHeaderComments(
classHeaderJavadocBuilder = classHeaderJavadocBuilder.addUnescapedComment(descriptionComment);
}

if (service.hasApiVersion()) {
classHeaderJavadocBuilder.addParagraph(
String.format(SERVICE_API_VERSION_STRING, service.apiVersion()));
}

// Service introduction.
classHeaderJavadocBuilder.addParagraph(SERVICE_DESCRIPTION_INTRO_STRING);
classHeaderJavadocBuilder.addSampleCode(classMethodSampleCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public static Collection<Object[]> data() {
"localhost:7469",
"v1beta1"
},
{
"ApiVersionClient",
GrpcTestProtoLoader.instance().parseApiVersionTesting(),
"localhost:7469",
"v1"
},
});
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_EchoWithVersionMethod_async]
import com.google.api.core.ApiFuture;
import com.google.api.version.test.EchoRequest;
import com.google.api.version.test.EchoResponse;
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.Foobar;
import com.google.api.version.test.FoobarName;
import com.google.api.version.test.Severity;

public class AsyncEchoWithVersionMethod {

public static void main(String[] args) throws Exception {
asyncEchoWithVersionMethod();
}

public static void asyncEchoWithVersionMethod() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (EchoWithVersionClient echoWithVersionClient = EchoWithVersionClient.create()) {
EchoRequest request =
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
ApiFuture<EchoResponse> future =
echoWithVersionClient.echoWithVersionMethodCallable().futureCall(request);
// Do something.
EchoResponse response = future.get();
}
}
}
// [END goldensample_generated_EchoWithVersion_EchoWithVersionMethod_async]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_Create_SetCredentialsProvider_sync]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.EchoWithVersionSettings;
import com.google.api.version.test.myCredentials;

public class SyncCreateSetCredentialsProvider {

public static void main(String[] args) throws Exception {
syncCreateSetCredentialsProvider();
}

public static void syncCreateSetCredentialsProvider() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
EchoWithVersionSettings echoWithVersionSettings =
EchoWithVersionSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
EchoWithVersionClient echoWithVersionClient =
EchoWithVersionClient.create(echoWithVersionSettings);
}
}
// [END goldensample_generated_EchoWithVersion_Create_SetCredentialsProvider_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_Create_SetEndpoint_sync]
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.EchoWithVersionSettings;
import com.google.api.version.test.myEndpoint;

public class SyncCreateSetEndpoint {

public static void main(String[] args) throws Exception {
syncCreateSetEndpoint();
}

public static void syncCreateSetEndpoint() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
EchoWithVersionSettings echoWithVersionSettings =
EchoWithVersionSettings.newBuilder().setEndpoint(myEndpoint).build();
EchoWithVersionClient echoWithVersionClient =
EchoWithVersionClient.create(echoWithVersionSettings);
}
}
// [END goldensample_generated_EchoWithVersion_Create_SetEndpoint_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_EchoWithVersionMethod_sync]
import com.google.api.version.test.EchoRequest;
import com.google.api.version.test.EchoResponse;
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.Foobar;
import com.google.api.version.test.FoobarName;
import com.google.api.version.test.Severity;

public class SyncEchoWithVersionMethod {

public static void main(String[] args) throws Exception {
syncEchoWithVersionMethod();
}

public static void syncEchoWithVersionMethod() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (EchoWithVersionClient echoWithVersionClient = EchoWithVersionClient.create()) {
EchoRequest request =
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
EchoResponse response = echoWithVersionClient.echoWithVersionMethod(request);
}
}
}
// [END goldensample_generated_EchoWithVersion_EchoWithVersionMethod_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Foobarname_sync]
import com.google.api.version.test.EchoResponse;
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.FoobarName;

public class SyncEchoWithVersionMethodFoobarname {

public static void main(String[] args) throws Exception {
syncEchoWithVersionMethodFoobarname();
}

public static void syncEchoWithVersionMethodFoobarname() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (EchoWithVersionClient echoWithVersionClient = EchoWithVersionClient.create()) {
FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
EchoResponse response = echoWithVersionClient.echoWithVersionMethod(name);
}
}
}
// [END goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Foobarname_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Noargs_sync]
import com.google.api.version.test.EchoResponse;
import com.google.api.version.test.EchoWithVersionClient;

public class SyncEchoWithVersionMethodNoargs {

public static void main(String[] args) throws Exception {
syncEchoWithVersionMethodNoargs();
}

public static void syncEchoWithVersionMethodNoargs() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (EchoWithVersionClient echoWithVersionClient = EchoWithVersionClient.create()) {
EchoResponse response = echoWithVersionClient.echoWithVersionMethod();
}
}
}
// [END goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Noargs_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.api.version.test.samples;

// [START goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Resourcename_sync]
import com.google.api.resourcenames.ResourceName;
import com.google.api.version.test.EchoResponse;
import com.google.api.version.test.EchoWithVersionClient;
import com.google.api.version.test.FoobarName;

public class SyncEchoWithVersionMethodResourcename {

public static void main(String[] args) throws Exception {
syncEchoWithVersionMethodResourcename();
}

public static void syncEchoWithVersionMethodResourcename() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (EchoWithVersionClient echoWithVersionClient = EchoWithVersionClient.create()) {
ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
EchoResponse response = echoWithVersionClient.echoWithVersionMethod(parent);
}
}
}
// [END goldensample_generated_EchoWithVersion_EchoWithVersionMethod_Resourcename_sync]
Loading