Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spring): Separate out client settings bean and client bean comment #1209

Merged
merged 2 commits into from
Jan 4, 2023
Merged
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 @@ -744,7 +744,7 @@ private static MethodDefinition createSettingsBeanMethod(

return MethodDefinition.builder()
.setHeaderCommentStatements(
SpringAutoconfigCommentComposer.createClientBeanComment(
SpringAutoconfigCommentComposer.createSettingsBeanComment(
service.name(),
Utils.getServicePropertiesClassName(service),
transportChannelProviderName))
Expand Down Expand Up @@ -847,6 +847,8 @@ private static MethodDefinition createClientBeanMethod(
String methodName =
CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, service.name()) + "Client";
return MethodDefinition.builder()
.setHeaderCommentStatements(
SpringAutoconfigCommentComposer.createClientBeanComment(service.name()))
.setName(methodName)
.setScope(ScopeNode.PUBLIC)
.setReturnType(types.get("ServiceClient"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ public class SpringAutoconfigCommentComposer {
public static final String TRANSPORT_CHANNEL_PROVIDER_GENERAL_DESCRIPTION =
"Returns the default channel provider. The default is gRPC and will default to it unless the "
+ "useRest option is provided to use HTTP transport instead";
public static final String CLIENT_BEAN_GENERAL_DESCRIPTION =
"Provides a %sClient bean configured to "
public static final String CLIENT_SETTINGS_BEAN_GENERAL_DESCRIPTION =
"Provides a %sSettings bean configured to "
+ "use the default credentials provider (obtained with %sCredentials()) and its default "
+ "transport channel provider (%s()). It also configures the quota project ID if provided. It "
+ "will configure an executor provider in case there is more than one thread configured "
+ "in the client ";

public static final String CLIENT_BEAN_RETRY_SETTINGS_DESCRIPTION =
public static final String CLIENT_SETTINGS_BEAN_RETRY_SETTINGS_DESCRIPTION =
"Retry settings are also configured from service-level and method-level properties specified in %s. "
+ "Method-level properties will take precedence over service-level properties if available, "
+ "and client library defaults will be used if neither are specified.";

public static final String CLIENT_BEAN_GENERAL_DESCRIPTION =
"Provides a %sClient bean configured with %sSettings.";

public SpringAutoconfigCommentComposer() {}

public static List<CommentStatement> createClassHeaderComments(
Expand Down Expand Up @@ -88,19 +91,26 @@ public static CommentStatement createTransportChannelProviderComment() {
.build());
}

public static CommentStatement createClientBeanComment(
public static CommentStatement createSettingsBeanComment(
String serviceName, String propertiesClazzName, String channelProviderName) {
String credentialsBaseName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, serviceName);
return CommentStatement.withComment(
JavaDocComment.builder()
.addParagraph(
String.format(
CLIENT_BEAN_GENERAL_DESCRIPTION,
CLIENT_SETTINGS_BEAN_GENERAL_DESCRIPTION,
serviceName,
credentialsBaseName,
channelProviderName))
.addParagraph(
String.format(CLIENT_BEAN_RETRY_SETTINGS_DESCRIPTION, propertiesClazzName))
String.format(CLIENT_SETTINGS_BEAN_RETRY_SETTINGS_DESCRIPTION, propertiesClazzName))
.build());
}

public static CommentStatement createClientBeanComment(String serviceName) {
return CommentStatement.withComment(
JavaDocComment.builder()
.addParagraph(String.format(CLIENT_BEAN_GENERAL_DESCRIPTION, serviceName, serviceName))
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class EchoSpringAutoConfiguration {
}

/**
* Provides a EchoClient bean configured to use the default credentials provider (obtained with
* Provides a EchoSettings bean configured to use the default credentials provider (obtained with
* echoCredentials()) and its default transport channel provider
* (defaultEchoTransportChannelProvider()). It also configures the quota project ID if provided.
* It will configure an executor provider in case there is more than one thread configured in the
Expand Down Expand Up @@ -299,6 +299,7 @@ public class EchoSpringAutoConfiguration {
return clientSettingsBuilder.build();
}

/** Provides a EchoClient bean configured with EchoSettings. */
@Bean
@ConditionalOnMissingBean
public EchoClient echoClient(EchoSettings echoSettings) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class EchoSpringAutoConfiguration {
}

/**
* Provides a EchoClient bean configured to use the default credentials provider (obtained with
* Provides a EchoSettings bean configured to use the default credentials provider (obtained with
* echoCredentials()) and its default transport channel provider
* (defaultEchoTransportChannelProvider()). It also configures the quota project ID if provided.
* It will configure an executor provider in case there is more than one thread configured in the
Expand Down Expand Up @@ -279,6 +279,7 @@ public class EchoSpringAutoConfiguration {
return clientSettingsBuilder.build();
}

/** Provides a EchoClient bean configured with EchoSettings. */
@Bean
@ConditionalOnMissingBean
public EchoClient echoClient(EchoSettings echoSettings) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class EchoSpringAutoConfiguration {
}

/**
* Provides a EchoClient bean configured to use the default credentials provider (obtained with
* Provides a EchoSettings bean configured to use the default credentials provider (obtained with
* echoCredentials()) and its default transport channel provider
* (defaultEchoTransportChannelProvider()). It also configures the quota project ID if provided.
* It will configure an executor provider in case there is more than one thread configured in the
Expand Down Expand Up @@ -287,6 +287,7 @@ public class EchoSpringAutoConfiguration {
return clientSettingsBuilder.build();
}

/** Provides a EchoClient bean configured with EchoSettings. */
@Bean
@ConditionalOnMissingBean
public EchoClient echoClient(EchoSettings echoSettings) throws IOException {
Expand Down