From f7b8bfa5a2ffb1dab8549629539b7fdddc9fcb6e Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 1 Jul 2024 15:31:09 +0800 Subject: [PATCH 1/3] still fill the UUID, if only 1 header available --- .../autorest/mapper/ProxyMethodMapper.java | 17 +++++++++-------- .../autorest/template/ClientMethodTemplate.java | 4 +++- .../com/azure/autorest/util/MethodUtil.java | 13 +++---------- 3 files changed, 15 insertions(+), 19 deletions(-) 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..452d2594c1 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/ProxyMethodMapper.java @@ -723,8 +723,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 +742,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..77ba9278f4 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 (!CoreUtils.isNullOrEmpty(clientMethod.getProxyMethod().getSpecialHeaders()) && 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) { From 3606af89d5dd59d9c9895c5dc7fa2fd8fe7225db Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 1 Jul 2024 15:31:14 +0800 Subject: [PATCH 2/3] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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", From 3194434acaca969447650802f068b55faa488b2a Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 1 Jul 2024 16:00:05 +0800 Subject: [PATCH 3/3] fix --- .../java/com/azure/autorest/mapper/ProxyMethodMapper.java | 6 +++++- .../com/azure/autorest/template/ClientMethodTemplate.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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 452d2594c1..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); } 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 77ba9278f4..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,7 @@ private static boolean addSpecialHeadersToRequestOptions(JavaBlock function, Cli // repeatability headers if (repeatabilityRequestHeaders) { requestOptionsSetHeaderIfAbsent(function, MethodUtil.REPEATABILITY_REQUEST_ID_EXPRESSION, MethodUtil.REPEATABILITY_REQUEST_ID_HEADER); - if (!CoreUtils.isNullOrEmpty(clientMethod.getProxyMethod().getSpecialHeaders()) && clientMethod.getProxyMethod().getSpecialHeaders().contains(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); } }