Skip to content

Commit 3c5964a

Browse files
client, handle single repeatability header (#2845)
1 parent 6342400 commit 3c5964a

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public Map<Request, List<ProxyMethod>> map(Operation operation) {
8484
ProxyMethod.Builder builder = createProxyMethodBuilder()
8585
.description(operation.getDescription())
8686
.name(operationName)
87-
.specialHeaders(operation.getSpecialHeaders())
8887
.isResumable(false);
8988

9089
String operationId = operation.getOperationId();
@@ -199,6 +198,11 @@ public Map<Request, List<ProxyMethod>> map(Operation operation) {
199198
}
200199
}
201200
List<ProxyMethodParameter> specialParameters = getSpecialParameters(operation);
201+
if (!CoreUtils.isNullOrEmpty(specialParameters)) {
202+
builder.specialHeaders(specialParameters.stream()
203+
.map(ProxyMethodParameter::getRequestParameterName)
204+
.collect(Collectors.toList()));
205+
}
202206
if (!settings.isDataPlaneClient()) {
203207
parameters.addAll(specialParameters);
204208
}
@@ -723,8 +727,7 @@ protected List<ProxyMethodParameter> getSpecialParameters(Operation operation) {
723727
List<String> specialHeaders = operation.getSpecialHeaders().stream()
724728
.map(s -> s.toLowerCase(Locale.ROOT))
725729
.collect(Collectors.toList());
726-
boolean supportRepeatabilityRequest = specialHeaders.contains(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER)
727-
&& specialHeaders.contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
730+
boolean supportRepeatabilityRequest = specialHeaders.contains(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER);
728731
if (supportRepeatabilityRequest) {
729732
Function<ProxyMethodParameter.Builder, ProxyMethodParameter.Builder> commonBuilderSetting = builder -> {
730733
builder.rawType(ClassType.STRING)
@@ -743,12 +746,14 @@ protected List<ProxyMethodParameter> getSpecialParameters(Operation operation) {
743746
.requestParameterName(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER)
744747
.description("Repeatability request ID header"))
745748
.build());
746-
specialParameters.add(commonBuilderSetting.apply(new ProxyMethodParameter.Builder()
747-
.name(MethodUtil.REPEATABILITY_FIRST_SENT_VARIABLE_NAME)
748-
.parameterReference(MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION)
749-
.requestParameterName(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)
750-
.description("Repeatability first sent header as HTTP-date"))
751-
.build());
749+
if (specialHeaders.contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)) {
750+
specialParameters.add(commonBuilderSetting.apply(new ProxyMethodParameter.Builder()
751+
.name(MethodUtil.REPEATABILITY_FIRST_SENT_VARIABLE_NAME)
752+
.parameterReference(MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION)
753+
.requestParameterName(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)
754+
.description("Repeatability first sent header as HTTP-date"))
755+
.build());
756+
}
752757
}
753758
}
754759
}

javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ private static boolean addSpecialHeadersToRequestOptions(JavaBlock function, Cli
504504
// repeatability headers
505505
if (repeatabilityRequestHeaders) {
506506
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_REQUEST_ID_EXPRESSION, MethodUtil.REPEATABILITY_REQUEST_ID_HEADER);
507-
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION, MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
507+
if (clientMethod.getProxyMethod().getSpecialHeaders().contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)) {
508+
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION, MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
509+
}
508510
}
509511

510512
// content-type headers for optional body parameter

javagen/src/main/java/com/azure/autorest/util/MethodUtil.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class MethodUtil {
5454
= EnumSet.of(HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.POST);
5555

5656
/**
57-
* Checks that method include special headers for Repeatable Requests Version 1.0
57+
* Checks that method include special headers for Repeatable Requests Version 1.0 ("repeatability-request-id")
5858
* @param proxyMethod the proxy method
5959
* @return whether method include special headers for Repeatable Requests Version 1.0
6060
*/
@@ -70,15 +70,8 @@ public static boolean isMethodIncludeRepeatableRequestHeaders(ProxyMethod proxyM
7070
return false;
7171
}
7272

73-
// check 2 headers exists
74-
for (String specialHeader : proxyMethod.getSpecialHeaders()) {
75-
if (REPEATABILITY_REQUEST_ID_HEADER.equalsIgnoreCase(specialHeader)
76-
|| REPEATABILITY_FIRST_SENT_HEADER.equalsIgnoreCase(specialHeader)) {
77-
return true;
78-
}
79-
}
80-
81-
return false;
73+
// check "repeatability-request-id" exists
74+
return proxyMethod.getSpecialHeaders().contains(REPEATABILITY_REQUEST_ID_HEADER);
8275
}
8376

8477
public static boolean isHttpMethodSupportRepeatableRequestHeaders(HttpMethod httpMethod) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@autorest/java",
3-
"version": "4.1.32",
3+
"version": "4.1.33",
44
"description": "The Java extension for classic generators in AutoRest.",
55
"scripts": {
66
"autorest": "autorest",

0 commit comments

Comments
 (0)