Skip to content

Commit 645f8a6

Browse files
authored
Don't generate duplicate client context params (#2182)
For S3, the client context params are duplicated on on its ServiceConfiguration. For these duplicates, just keep them in the ServiceConfiguration.
1 parent bdc025c commit 645f8a6

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public TypeSpec poetSpec() {
110110

111111
if (hasClientContextParams()) {
112112
model.getClientContextParams().forEach((n, m) -> {
113-
builder.addMethod(clientContextParamSetter(n, m));
113+
if (endpointRulesSpecUtils.shouldGenerateClientContextParamSetter(n)) {
114+
builder.addMethod(clientContextParamSetter(n, m));
115+
}
114116
});
115117
}
116118

@@ -486,6 +488,7 @@ private MethodSpec clientContextParamSetter(String name, ClientContextParam para
486488

487489
return MethodSpec.methodBuilder(setterName)
488490
.addModifiers(Modifier.PUBLIC)
491+
.addAnnotation(Override.class)
489492
.returns(TypeVariableName.get("B"))
490493
.addParameter(type, setterName)
491494
.addStatement("clientContextParams.put($T.$N, $N)", endpointRulesSpecUtils.clientContextParamsName(),

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderInterface.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public TypeSpec poetSpec() {
7272

7373
if (hasClientContextParams()) {
7474
model.getClientContextParams().forEach((n, m) -> {
75-
builder.addMethod(clientContextParamSetter(n, m));
75+
if (endpointRulesSpecUtils.shouldGenerateClientContextParamSetter(n)) {
76+
builder.addMethod(clientContextParamSetter(n, m));
77+
}
7678
});
7779
}
7880

codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointRulesSpecUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ public String clientContextParamName(String paramName) {
104104
return intermediateModel.getNamingStrategy().getEnumValueName(paramName);
105105
}
106106

107+
/**
108+
* S3 and S3 Control have ServiceConfiguration customizations that would duplicate some context params. Avoid
109+
* the duplication by not generating the client context param setters on the client for those parameters.
110+
*/
111+
public boolean shouldGenerateClientContextParamSetter(String paramName) {
112+
if (!isS3()) {
113+
return true;
114+
}
115+
116+
switch (paramName) {
117+
case "Accelerate":
118+
case "DisableMultiRegionAccessPoints":
119+
case "ForcePathStyle":
120+
case "UseArnRegion":
121+
return false;
122+
default:
123+
return true;
124+
}
125+
}
126+
107127
public TypeName toJavaType(String type) {
108128
switch (type.toLowerCase(Locale.ENGLISH)) {
109129
case "boolean":
@@ -162,6 +182,11 @@ public CodeBlock treeNodeToLiteral(TreeNode treeNode) {
162182
return b.build();
163183
}
164184

185+
186+
private boolean isS3() {
187+
return "S3".equals(intermediateModel.getMetadata().getServiceName());
188+
}
189+
165190
private static JrsString asString(TreeNode node) {
166191
if (node instanceof JrsString) {
167192
return (JrsString) node;

0 commit comments

Comments
 (0)