Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http-client-java, pageable for unbranded #5551

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,6 @@ export class CodeModelBuilder {
responses: SdkHttpResponse[],
sdkMethod: SdkMethod<SdkHttpOperation>,
) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
}
});
}
Expand Down Expand Up @@ -1584,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<String> serializedName
Optional<String> 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) -> {");
Expand All @@ -1596,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(" });")
Expand All @@ -1607,15 +1612,20 @@ 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,
JavaSettings settings) {
if (settings.isDataPlaneClient() && settings.isPageSizeEnabled()) {
Optional<String> serializedName
Optional<String> 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) -> {");
Expand All @@ -1625,7 +1635,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(" });")
Expand All @@ -1636,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-java/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 packages/http-client-java/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading