From c451bc905b4e17d1cc824565da8df19a6da2d1cf Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:23:41 +0800 Subject: [PATCH 1/6] allow pageable in unbranded --- packages/http-client-java/emitter/src/code-model-builder.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index cc1686e5ec..29a9d9eeaf 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -960,11 +960,6 @@ export class CodeModelBuilder { responses: SdkHttpResponse[], sdkMethod: SdkMethod, ) { - if (!this.isBranded()) { - // TODO: currently unbranded does not support paged operation - return; - } - if (sdkMethod.kind === "paging" || sdkMethod.kind === "lropaging") { for (const response of responses) { const bodyType = response.type; From 3159412f6363aa009bebd47ce218167ee9381186 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:31:27 +0800 Subject: [PATCH 2/6] use the new PagedResponse ctor --- .../generator/core/template/ClientMethodTemplate.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java index f2354b0efd..941b3e346a 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java @@ -819,13 +819,18 @@ private void generatePagedSinglePage(ClientMethod clientMethod, JavaType typeBlo function.line("res.getBody(),"); function.line("res.getValue().%s(),", CodeNamer.getModelNamer() .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); + // continuation token + function.line("null,"); + // next link if (clientMethod.getMethodPageDetails().nonNullNextLink()) { String nextLinkLine = nextLinkLine(clientMethod); nextLinkLine = nextLinkLine.substring(0, nextLinkLine.length() - 1); - function.line(nextLinkLine + ");"); + function.line(nextLinkLine + ","); } else { - function.line("null);"); + function.line("null,"); } + // previous link, first link, last link + function.line("null,null,null);"); } }); } From 84044533ae74a03d6b8b8bc6df613959ddfc3273 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:36:26 +0800 Subject: [PATCH 3/6] maxpagesize only for branded --- .../core/template/ClientMethodTemplate.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java index 941b3e346a..fc8b615680 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java @@ -1589,9 +1589,9 @@ protected void generateProtocolLongRunningBeginAsync(ClientMethod clientMethod, private String getPagingSinglePageExpression(ClientMethod clientMethod, String methodName, String argumentLine, JavaSettings settings) { if (settings.isDataPlaneClient() && settings.isPageSizeEnabled()) { - Optional serializedName + Optional maxPageSizeSerializedName = MethodUtil.serializedNameOfMaxPageSizeParameter(clientMethod.getProxyMethod()); - if (serializedName.isPresent()) { + if (maxPageSizeSerializedName.isPresent() && settings.isBranded()) { argumentLine = argumentLine.replace("requestOptions", "requestOptionsLocal"); StringBuilder expression = new StringBuilder(); expression.append("(pageSize) -> {"); @@ -1601,7 +1601,7 @@ private String getPagingSinglePageExpression(ClientMethod clientMethod, String m .append(" requestOptionsLocal.addRequestCallback(requestLocal -> {") .append(" UrlBuilder urlBuilder = UrlBuilder.parse(requestLocal.getUrl());") .append(" urlBuilder.setQueryParameter(\"") - .append(serializedName.get()) + .append(maxPageSizeSerializedName.get()) .append("\", String.valueOf(pageSize));") .append(" requestLocal.setUrl(urlBuilder.toString());") .append(" });") @@ -1618,9 +1618,9 @@ private String getPagingSinglePageExpression(ClientMethod clientMethod, String m private String getPagingNextPageExpression(ClientMethod clientMethod, String methodName, String argumentLine, JavaSettings settings) { if (settings.isDataPlaneClient() && settings.isPageSizeEnabled()) { - Optional serializedName + Optional maxPageSizeSerializedName = MethodUtil.serializedNameOfMaxPageSizeParameter(clientMethod.getProxyMethod()); - if (serializedName.isPresent()) { + if (maxPageSizeSerializedName.isPresent() && settings.isBranded()) { argumentLine = argumentLine.replace("requestOptions", "requestOptionsLocal"); StringBuilder expression = new StringBuilder(); expression.append("(nextLink, pageSize) -> {"); @@ -1630,7 +1630,7 @@ private String getPagingNextPageExpression(ClientMethod clientMethod, String met .append(" requestOptionsLocal.addRequestCallback(requestLocal -> {") .append(" UrlBuilder urlBuilder = UrlBuilder.parse(requestLocal.getUrl());") .append(" urlBuilder.setQueryParameter(\"") - .append(serializedName.get()) + .append(maxPageSizeSerializedName.get()) .append("\", String.valueOf(pageSize));") .append(" requestLocal.setUrl(urlBuilder.toString());") .append(" });") From 754408de283d3fe700da08b5a94df2f16b85f5ad Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:36:51 +0800 Subject: [PATCH 4/6] clientcore beta.2 --- .../http/client/generator/core/model/projectmodel/Project.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java index 34f3add260..65a874ff6b 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java @@ -63,8 +63,7 @@ public enum Dependency { AZURE_IDENTITY("com.azure", "azure-identity", "1.14.2"), AZURE_CORE_EXPERIMENTAL("com.azure", "azure-core-experimental", "1.0.0-beta.56"), - CLIENTCORE("io.clientcore", "core", "1.0.0-beta.1"), - CLIENTCORE_JSON("io.clientcore", "core-json", "1.0.0-beta.1"); + CLIENTCORE("io.clientcore", "core", "1.0.0-beta.2"); private final String groupId; private final String artifactId; From bf5c43aca5a25e9b24ec1eb52f6b954b8e11379f Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:45:31 +0800 Subject: [PATCH 5/6] paging lambda signature for unbranded --- .../core/template/ClientMethodTemplate.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java index fc8b615680..d1e977ac3f 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java @@ -1612,7 +1612,12 @@ private String getPagingSinglePageExpression(ClientMethod clientMethod, String m } } - return String.format("() -> %s(%s)", methodName, argumentLine); + String lambdaParameters = ""; + if (!settings.isBranded()) { + lambdaParameters = "pagingOptions"; + } + + return String.format("(%s) -> %s(%s)", lambdaParameters, methodName, argumentLine); } private String getPagingNextPageExpression(ClientMethod clientMethod, String methodName, String argumentLine, @@ -1641,10 +1646,16 @@ private String getPagingNextPageExpression(ClientMethod clientMethod, String met } } + String lambdaParameters = "nextLink"; + if (!settings.isBranded()) { + lambdaParameters = "(pagingOptions, nextLink)"; + } + if (settings.isDataPlaneClient()) { argumentLine = argumentLine.replace("requestOptions", "requestOptionsForNextPage"); } - return String.format("nextLink -> %s(%s)", methodName, argumentLine); + + return String.format("%s -> %s(%s)", lambdaParameters, methodName, argumentLine); } private String getPollingStrategy(ClientMethod clientMethod, String contextParam) { From 5deddd76eecd992144b23fa0f0bdbaab94d21a04 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 9 Jan 2025 14:48:20 +0800 Subject: [PATCH 6/6] bump to 0.1.6 --- .../generator/http-client-generator-test/package.json | 2 +- packages/http-client-java/package-lock.json | 4 ++-- packages/http-client-java/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-test/package.json b/packages/http-client-java/generator/http-client-generator-test/package.json index 22eca56169..f2fbb1b67a 100644 --- a/packages/http-client-java/generator/http-client-generator-test/package.json +++ b/packages/http-client-java/generator/http-client-generator-test/package.json @@ -14,7 +14,7 @@ "dependencies": { "@typespec/http-specs": "0.1.0-alpha.5", "@azure-tools/azure-http-specs": "0.1.0-alpha.4", - "@typespec/http-client-java": "file:../../typespec-http-client-java-0.1.5.tgz", + "@typespec/http-client-java": "file:../../typespec-http-client-java-0.1.6.tgz", "@typespec/http-client-java-tests": "file:" }, "overrides": { diff --git a/packages/http-client-java/package-lock.json b/packages/http-client-java/package-lock.json index 362a01be8f..ff69ff046c 100644 --- a/packages/http-client-java/package-lock.json +++ b/packages/http-client-java/package-lock.json @@ -1,12 +1,12 @@ { "name": "@typespec/http-client-java", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@typespec/http-client-java", - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "dependencies": { "@autorest/codemodel": "~4.20.0", diff --git a/packages/http-client-java/package.json b/packages/http-client-java/package.json index 65bee48722..5aeebf534b 100644 --- a/packages/http-client-java/package.json +++ b/packages/http-client-java/package.json @@ -1,6 +1,6 @@ { "name": "@typespec/http-client-java", - "version": "0.1.5", + "version": "0.1.6", "description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding", "keywords": [ "TypeSpec"