Skip to content

http-client-java, support nested pageItems, nextLink, continuationToken #7706

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

weidongxu-microsoft
Copy link
Contributor

@weidongxu-microsoft weidongxu-microsoft commented Jun 23, 2025

test would be in #6477
(PS: we may need to skip this tsp in Azure)

impl code looks like this

    @ServiceMethod(returns = ReturnType.SINGLE)
    public PagedResponse<Pet> nestedLinkNextSinglePage(String nextLink) {
        final String accept = "application/json";
        Response<NestedLinkResponse> res
            = service.nestedLinkNext(nextLink, this.client.getEndpoint(), accept, RequestContext.none());
        return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
            res.getValue().getNestedItems().getPets(), null,
            res.getValue().getNestedNext() != null && res.getValue().getNestedNext().getNext() != null
                ? res.getValue().getNestedNext().getNext()
                : null,
            null, null, null);
    }

pageItems should always be there so there is no null check <- this could be wrong but worry about it later

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Jun 23, 2025
Copy link
Contributor

No changes needing a change description found.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the pagination support in the HTTP client Java package to enable nested pageItems, nextLink, and continuationToken handling. Key changes include:

  • Refactoring ClientCoreClientMethodTemplate to use helper methods for nested property extraction with null checks.
  • Updating MethodPageDetails and PagingMetadata to use lists (instead of single values) for pageItems and nextLink.
  • Adjusting test implementations and code model builder to align with the new nested paging model.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ClientCoreClientMethodTemplate.java Refactored pagination logic to use helper methods (valueLine, nextLinkLine, nestedReferenceLineWithNullCheck) for nested paging properties.
MethodPageDetails.java Changed to use List for pageItems and nextLink, accessing the first element for property names.
PagingMetadata.java Updated to support list-based extraction of page items and next link properties.
ClientMethodsReturnDescription.java Adjusted element type mapping to integrate the new paging properties.
XmsPageable.java Added getters/setters for nested pageItems and nextLink properties.
ServerDrivenPaginationsImpl.java and ServerDrivenPaginationContinuationTokensImpl.java Updated PagedResponse construction to include redundant null checks for next tokens using the new paging fields.
operation-utils.ts and code-model-builder.ts Incorporated new logic for handling nested paging properties in response schemas.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@weidongxu-microsoft weidongxu-microsoft marked this pull request as ready for review June 23, 2025 09:12
sdkMethod.pagingMetadata.nextLinkSegments,
);
// "nextLinkSerializedName" take 1st property for backward compatibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please show what does output code-model.yaml look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:client:java Issue for the Java client emitter: @typespec/http-client-java
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants