Skip to content

Commit

Permalink
client, handle single repeatability header (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Jul 3, 2024
1 parent 6342400 commit 3c5964a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public Map<Request, List<ProxyMethod>> map(Operation operation) {
ProxyMethod.Builder builder = createProxyMethodBuilder()
.description(operation.getDescription())
.name(operationName)
.specialHeaders(operation.getSpecialHeaders())
.isResumable(false);

String operationId = operation.getOperationId();
Expand Down Expand Up @@ -199,6 +198,11 @@ public Map<Request, List<ProxyMethod>> map(Operation operation) {
}
}
List<ProxyMethodParameter> specialParameters = getSpecialParameters(operation);
if (!CoreUtils.isNullOrEmpty(specialParameters)) {
builder.specialHeaders(specialParameters.stream()
.map(ProxyMethodParameter::getRequestParameterName)
.collect(Collectors.toList()));
}
if (!settings.isDataPlaneClient()) {
parameters.addAll(specialParameters);
}
Expand Down Expand Up @@ -723,8 +727,7 @@ protected List<ProxyMethodParameter> getSpecialParameters(Operation operation) {
List<String> specialHeaders = operation.getSpecialHeaders().stream()
.map(s -> s.toLowerCase(Locale.ROOT))
.collect(Collectors.toList());
boolean supportRepeatabilityRequest = specialHeaders.contains(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER)
&& specialHeaders.contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
boolean supportRepeatabilityRequest = specialHeaders.contains(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER);
if (supportRepeatabilityRequest) {
Function<ProxyMethodParameter.Builder, ProxyMethodParameter.Builder> commonBuilderSetting = builder -> {
builder.rawType(ClassType.STRING)
Expand All @@ -743,12 +746,14 @@ protected List<ProxyMethodParameter> getSpecialParameters(Operation operation) {
.requestParameterName(MethodUtil.REPEATABILITY_REQUEST_ID_HEADER)
.description("Repeatability request ID header"))
.build());
specialParameters.add(commonBuilderSetting.apply(new ProxyMethodParameter.Builder()
.name(MethodUtil.REPEATABILITY_FIRST_SENT_VARIABLE_NAME)
.parameterReference(MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION)
.requestParameterName(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)
.description("Repeatability first sent header as HTTP-date"))
.build());
if (specialHeaders.contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)) {
specialParameters.add(commonBuilderSetting.apply(new ProxyMethodParameter.Builder()
.name(MethodUtil.REPEATABILITY_FIRST_SENT_VARIABLE_NAME)
.parameterReference(MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION)
.requestParameterName(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)
.description("Repeatability first sent header as HTTP-date"))
.build());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ private static boolean addSpecialHeadersToRequestOptions(JavaBlock function, Cli
// repeatability headers
if (repeatabilityRequestHeaders) {
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_REQUEST_ID_EXPRESSION, MethodUtil.REPEATABILITY_REQUEST_ID_HEADER);
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION, MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
if (clientMethod.getProxyMethod().getSpecialHeaders().contains(MethodUtil.REPEATABILITY_FIRST_SENT_HEADER)) {
requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_FIRST_SENT_EXPRESSION, MethodUtil.REPEATABILITY_FIRST_SENT_HEADER);
}
}

// content-type headers for optional body parameter
Expand Down
13 changes: 3 additions & 10 deletions javagen/src/main/java/com/azure/autorest/util/MethodUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class MethodUtil {
= EnumSet.of(HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.POST);

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

// check 2 headers exists
for (String specialHeader : proxyMethod.getSpecialHeaders()) {
if (REPEATABILITY_REQUEST_ID_HEADER.equalsIgnoreCase(specialHeader)
|| REPEATABILITY_FIRST_SENT_HEADER.equalsIgnoreCase(specialHeader)) {
return true;
}
}

return false;
// check "repeatability-request-id" exists
return proxyMethod.getSpecialHeaders().contains(REPEATABILITY_REQUEST_ID_HEADER);
}

public static boolean isHttpMethodSupportRepeatableRequestHeaders(HttpMethod httpMethod) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorest/java",
"version": "4.1.32",
"version": "4.1.33",
"description": "The Java extension for classic generators in AutoRest.",
"scripts": {
"autorest": "autorest",
Expand Down

0 comments on commit 3c5964a

Please sign in to comment.