Skip to content

Commit b03ac25

Browse files
committed
feat(generator): emit ResumableUploadCallSettings on stub and service settings
1 parent dbc1403 commit b03ac25

10 files changed

Lines changed: 923 additions & 27 deletions

File tree

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ public class SettingsCommentComposer {
4141
private static final String CLASS_HEADER_DEFAULT_ADDRESS_PORT_PATTERN =
4242
"The default service address (%s) and default port (%d) are used.";
4343
private static final String CLASS_HEADER_SAMPLE_CODE_PATTERN =
44-
"For example, to set the [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings) of %s:";
44+
"For example, to set the"
45+
+ " [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)"
46+
+ " of %s:";
4547

4648
private static final String CLASS_HEADER_LRO_SAMPLE_CODE_PATTERN =
47-
"To configure the RetrySettings of a Long Running Operation method, create an OperationTimedPollAlgorithm object and update the RPC's polling algorithm. For example, to configure the RetrySettings for %s:";
49+
"To configure the RetrySettings of a Long Running Operation method, create an"
50+
+ " OperationTimedPollAlgorithm object and update the RPC's polling algorithm. For"
51+
+ " example, to configure the RetrySettings for %s:";
4852

4953
private static final String CLASS_HEADER_SAMPLE_CODE_SUFFIX =
50-
"Please refer to the [Client Side Retry Guide](https://docs.cloud.google.com/java/docs/client-retries) for additional support in setting retries.";
54+
"Please refer to the [Client Side Retry"
55+
+ " Guide](https://docs.cloud.google.com/java/docs/client-retries) for additional support"
56+
+ " in setting retries.";
5157

5258
private static final String CLASS_HEADER_BUILDER_DESCRIPTION =
5359
"The builder of this class is recursive, so contained classes are themselves builders. When"
@@ -130,6 +136,23 @@ public static CommentStatement createCallSettingsGetterComment(
130136
isMethodInternal);
131137
}
132138

139+
public static CommentStatement createResumableUploadCallSettingsGetterComment(
140+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
141+
JavaDocComment.Builder docBuilder =
142+
JavaDocComment.builder()
143+
.addComment(String.format(CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName))
144+
.addParagraph(
145+
"Note that custom retry settings and headers configured via ApiCallContext"
146+
+ " apply strictly to the initial session initiation request.");
147+
if (isMethodDeprecated) {
148+
docBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
149+
}
150+
if (isMethodInternal) {
151+
docBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
152+
}
153+
return CommentStatement.withComment(docBuilder.build());
154+
}
155+
133156
public static CommentStatement createBuilderClassComment(String outerClassName) {
134157
return toCommentStatement(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName));
135158
}
@@ -140,6 +163,23 @@ public static CommentStatement createCallSettingsBuilderGetterComment(
140163
return toCommentStatement(methodComment, isMethodDeprecated, isMethodInternal);
141164
}
142165

166+
public static CommentStatement createResumableUploadCallSettingsBuilderGetterComment(
167+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
168+
JavaDocComment.Builder docBuilder =
169+
JavaDocComment.builder()
170+
.addComment(String.format(CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN, javaMethodName))
171+
.addParagraph(
172+
"Note that custom retry settings and headers configured via ApiCallContext"
173+
+ " apply strictly to the initial session initiation request.");
174+
if (isMethodDeprecated) {
175+
docBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
176+
}
177+
if (isMethodInternal) {
178+
docBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
179+
}
180+
return CommentStatement.withComment(docBuilder.build());
181+
}
182+
143183
public static List<CommentStatement> createClassHeaderComments(
144184
String configuredClassName,
145185
String defaultHost,

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.gax.rpc.ClientSettings;
2626
import com.google.api.gax.rpc.OperationCallSettings;
2727
import com.google.api.gax.rpc.PagedCallSettings;
28+
import com.google.api.gax.rpc.ResumableUploadCallSettings;
2829
import com.google.api.gax.rpc.ServerStreamingCallSettings;
2930
import com.google.api.gax.rpc.StreamingCallSettings;
3031
import com.google.api.gax.rpc.StubSettings;
@@ -311,12 +312,18 @@ private static List<MethodDefinition> createSettingsGetterMethods(
311312
// Add method header comment statements and annotations.
312313
private static MethodDefinition methodBuilderHelper(
313314
Method protoMethod, MethodDefinition.Builder methodBuilder, String javaMethodName) {
314-
return methodBuilder
315-
.setHeaderCommentStatements(
316-
SettingsCommentComposer.createCallSettingsGetterComment(
315+
CommentStatement commentStatement =
316+
protoMethod.isResumableUpload()
317+
? SettingsCommentComposer.createResumableUploadCallSettingsGetterComment(
318+
getMethodNameFromSettingsVarName(javaMethodName),
319+
protoMethod.isDeprecated(),
320+
protoMethod.isInternalApi())
321+
: SettingsCommentComposer.createCallSettingsGetterComment(
317322
getMethodNameFromSettingsVarName(javaMethodName),
318323
protoMethod.isDeprecated(),
319-
protoMethod.isInternalApi()))
324+
protoMethod.isInternalApi());
325+
return methodBuilder
326+
.setHeaderCommentStatements(commentStatement)
320327
.setAnnotations(createMethodAnnotations(protoMethod))
321328
.build();
322329
}
@@ -794,13 +801,19 @@ private static List<MethodDefinition> createNestedBuilderSettingsGetterMethods(
794801
String javaMethodName = String.format("%sSettings", javaStyleName);
795802
MethodDefinition.Builder methodBuilder =
796803
methodMakerFn.apply(getCallSettingsBuilderType(protoMethod, typeStore), javaMethodName);
804+
CommentStatement commentStatement =
805+
protoMethod.isResumableUpload()
806+
? SettingsCommentComposer.createResumableUploadCallSettingsBuilderGetterComment(
807+
getMethodNameFromSettingsVarName(javaMethodName),
808+
protoMethod.isDeprecated(),
809+
protoMethod.isInternalApi())
810+
: SettingsCommentComposer.createCallSettingsBuilderGetterComment(
811+
getMethodNameFromSettingsVarName(javaMethodName),
812+
protoMethod.isDeprecated(),
813+
protoMethod.isInternalApi());
797814
javaMethods.add(
798815
methodBuilder
799-
.setHeaderCommentStatements(
800-
SettingsCommentComposer.createCallSettingsBuilderGetterComment(
801-
getMethodNameFromSettingsVarName(javaMethodName),
802-
protoMethod.isDeprecated(),
803-
protoMethod.isInternalApi()))
816+
.setHeaderCommentStatements(commentStatement)
804817
.setAnnotations(createMethodAnnotations(protoMethod))
805818
.build());
806819

@@ -856,6 +869,7 @@ private static TypeStore createStaticTypes() {
856869
Operation.class,
857870
OperationCallSettings.class,
858871
PagedCallSettings.class,
872+
ResumableUploadCallSettings.class,
859873
ServerStreamingCallSettings.class,
860874
StreamingCallSettings.class,
861875
StubSettings.class,
@@ -933,7 +947,13 @@ private static TypeNode getCallSettingsTypeHelper(
933947
Method protoMethod, TypeStore typeStore, boolean isBuilder) {
934948
Class<?> callSettingsClazz =
935949
isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class;
936-
if (protoMethod.isPaged()) {
950+
if (protoMethod.isResumableUpload()) {
951+
return TypeNode.withReference(
952+
ConcreteReference.withClazz(
953+
isBuilder
954+
? ResumableUploadCallSettings.Builder.class
955+
: ResumableUploadCallSettings.class));
956+
} else if (protoMethod.isPaged()) {
937957
callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class;
938958
} else if (protoMethod.isBatching()) {
939959
callSettingsClazz =

0 commit comments

Comments
 (0)