Skip to content

Commit ab9b3b5

Browse files
committed
feat(generator): emit callable getter and convenience method for resumable upload RPCs
- In AbstractServiceClientClassComposer: emit public ResumableUploadCallable<RequestT, ResponseT> [method]Callable() delegating to stub - In AbstractServiceClientClassComposer: emit synchronous convenience method [method](RequestT request, InputStream payload) calling ApiExceptions.callAndTranslateApiException - Suppress method variants (flattened methods) for resumable upload RPCs - In ServiceClientCommentComposer: emit Javadoc call context override warning on both callable method and synchronous convenience method - Cover the generated client and its samples with ResumableUploadServiceClient.golden and the resumableuploadserviceclient sample goldens
1 parent cc4b980 commit ab9b3b5

9 files changed

Lines changed: 537 additions & 73 deletions

File tree

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@
3333
import java.util.Optional;
3434
import java.util.stream.Collectors;
3535
import org.jspecify.annotations.NullMarked;
36+
import org.jspecify.annotations.Nullable;
3637

3738
@NullMarked
3839
public class ServiceClientCommentComposer {
3940
// Tokens.
4041
private static final String EMPTY_STRING = "";
4142
private static final String API_EXCEPTION_TYPE_NAME = "com.google.api.gax.rpc.ApiException";
4243
private static final String EXCEPTION_CONDITION = "if the remote call fails";
44+
private static final String REQUEST_PARAM_NAME = "request";
45+
private static final String REQUEST_PARAM_DESCRIPTION =
46+
"The request object containing all of the parameters for the API call.";
47+
private static final String PAYLOAD_PARAM_NAME = "payload";
48+
private static final String PAYLOAD_PARAM_DESCRIPTION = "The payload data stream to upload.";
49+
private static final String CALL_SETTINGS_PARAM_NAME = "callSettings";
50+
private static final String CALL_SETTINGS_PARAM_DESCRIPTION =
51+
"The call settings to apply to this upload, or null to use defaults.";
4352

4453
// Constants.
4554
private static final String SERVICE_DESCRIPTION_INTRO_STRING =
@@ -105,9 +114,9 @@ public static List<CommentStatement> createClassHeaderComments(
105114
String classMethodSampleCode,
106115
String credentialsSampleCode,
107116
String endpointSampleCode,
108-
String transportSampleCode,
109-
String primaryTransport,
110-
String secondaryTransport) {
117+
@Nullable String transportSampleCode,
118+
@Nullable String primaryTransport,
119+
@Nullable String secondaryTransport) {
111120
JavaDocComment.Builder classHeaderJavadocBuilder = JavaDocComment.builder();
112121
if (service.hasDescription()) {
113122
String descriptionComment =
@@ -187,14 +196,13 @@ public static List<CommentStatement> createRpcMethodHeaderComment(
187196
methodJavadocBuilder = methodJavadocBuilder.addUnescapedComment(descriptionComment);
188197
}
189198

190-
if (sampleCodeOpt.isPresent()) {
199+
if (sampleCodeOpt.isPresent() && !method.isResumableUpload()) {
191200
methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING);
192201
methodJavadocBuilder.addSampleCode(sampleCodeOpt.get());
193202
}
194203

195204
if (methodArguments.isEmpty()) {
196-
methodJavadocBuilder.addParam(
197-
"request", "The request object containing all of the parameters for the API call.");
205+
methodJavadocBuilder.addParam(REQUEST_PARAM_NAME, REQUEST_PARAM_DESCRIPTION);
198206
} else {
199207
for (MethodArgument argument : methodArguments) {
200208
// TODO(miraleung): Remove the newline replacement when we support CommonMark.
@@ -204,6 +212,11 @@ public static List<CommentStatement> createRpcMethodHeaderComment(
204212
}
205213
}
206214

215+
if (method.isResumableUpload()) {
216+
methodJavadocBuilder.addParam(PAYLOAD_PARAM_NAME, PAYLOAD_PARAM_DESCRIPTION);
217+
methodJavadocBuilder.addParam(CALL_SETTINGS_PARAM_NAME, CALL_SETTINGS_PARAM_DESCRIPTION);
218+
}
219+
207220
methodJavadocBuilder.setThrows(API_EXCEPTION_TYPE_NAME, EXCEPTION_CONDITION);
208221

209222
if (method.isDeprecated()) {
@@ -233,13 +246,17 @@ private static MethodAndVariants createMethodAndVariants(
233246

234247
private static String createTableOfMethods(List<MethodAndVariants> methodAndVariantsList) {
235248
String FLATTENED_METHODS =
236-
"<p>\"Flattened\" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.</p>\n";
249+
"<p>\"Flattened\" method variants have converted the fields of the request object into"
250+
+ " function parameters to enable multiple ways to call the same method.</p>\n";
237251
String REQUEST_OBJECT_METHODS =
238-
"<p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>\n";
252+
"<p>Request object method variants only take one parameter, a request object, which must be"
253+
+ " constructed before the call.</p>\n";
239254
String CALLABLE_METHODS =
240-
"<p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>\n";
255+
"<p>Callable method variants take no parameters and return an immutable API callable"
256+
+ " object, which can be used to initiate calls to the service.</p>\n";
241257
String ASYNC_METHODS =
242-
"<p>Methods that return long-running operations have \"Async\" method variants that return `OperationFuture`, which is used to track polling of the service.</p>\n";
258+
"<p>Methods that return long-running operations have \"Async\" method variants that return"
259+
+ " `OperationFuture`, which is used to track polling of the service.</p>\n";
243260

244261
StringBuilder tableBuilder = new StringBuilder();
245262
tableBuilder
@@ -348,8 +365,8 @@ public static List<CommentStatement> createRpcCallableMethodHeaderComment(
348365
methodJavadocBuilder = methodJavadocBuilder.addUnescapedComment(descriptionComment);
349366
}
350367

351-
methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING);
352-
if (sampleCodeOpt.isPresent()) {
368+
if (sampleCodeOpt.isPresent() && !method.isResumableUpload()) {
369+
methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING);
353370
methodJavadocBuilder.addSampleCode(sampleCodeOpt.get());
354371
}
355372

0 commit comments

Comments
 (0)