diff --git a/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java index 53c4c97e4b..92fded9b7d 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java @@ -84,7 +84,6 @@ public Map> map(Operation operation) { ProxyMethod.Builder builder = createProxyMethodBuilder() .description(operation.getDescription()) .name(operationName) - .specialHeaders(operation.getSpecialHeaders()) .isResumable(false); String operationId = operation.getOperationId(); @@ -199,6 +198,11 @@ public Map> map(Operation operation) { } } List specialParameters = getSpecialParameters(operation); + if (!CoreUtils.isNullOrEmpty(specialParameters)) { + builder.specialHeaders(specialParameters.stream() + .map(ProxyMethodParameter::getRequestParameterName) + .collect(Collectors.toList())); + } if (!settings.isDataPlaneClient()) { parameters.addAll(specialParameters); } @@ -723,8 +727,7 @@ protected List getSpecialParameters(Operation operation) { List 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 commonBuilderSetting = builder -> { builder.rawType(ClassType.STRING) @@ -743,12 +746,14 @@ protected List 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()); + } } } } diff --git a/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java index e08ff49153..c00f96e6e1 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ClientMethodTemplate.java @@ -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 diff --git a/javagen/src/main/java/com/azure/autorest/util/MethodUtil.java b/javagen/src/main/java/com/azure/autorest/util/MethodUtil.java index 956f6edae9..c483f0b863 100644 --- a/javagen/src/main/java/com/azure/autorest/util/MethodUtil.java +++ b/javagen/src/main/java/com/azure/autorest/util/MethodUtil.java @@ -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 */ @@ -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) { diff --git a/package-lock.json b/package-lock.json index f02fe8885a..56623f26f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@autorest/java", - "version": "4.1.32", + "version": "4.1.33", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@autorest/java", - "version": "4.1.32", + "version": "4.1.33", "license": "MIT", "devDependencies": { "@microsoft.azure/autorest.testserver": "3.3.49", diff --git a/package.json b/package.json index 8baffffb55..6f6b711af4 100644 --- a/package.json +++ b/package.json @@ -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",