Azure / autorest.java

Extension for AutoRest (https://github.com/Azure/autorest) that generates Java code
MIT License
33 stars 82 forks source link

Client, support PagedFlux.byPage(pageSize) for maxpagesize #1616

Open weidongxu-microsoft opened 2 years ago

weidongxu-microsoft commented 2 years ago

pageable API would need to generate like this, if maxpagesize parameter in REST API.

    public PagedFlux<Foo> listAsync() {
        return new PagedFlux<>(
                (pageSize) -> listSinglePageAsync(pageSize),
                (nextLink, pageSize) -> listNextSinglePageAsync(nextLink));

user would call pagedResponse.iterableByPage(pageSize) to query with pageSize (instead of list(pageSize).

weidongxu-microsoft commented 1 year ago

I will add a enable-page-size option, to avoid affect older libs.

I would also include query parameter of client name maxPageSize as candidate (not only for serializedName = maxpagesize; as Batch does not use this name, so we'd expect them do a projectedName("maxPageSize")).

Also will do this for DPG first.

weidongxu-microsoft commented 1 year ago

Code may look like this (in impl)

    public PagedIterable<BinaryData> list(RequestOptions requestOptions) {
        return new PagedIterable<>(
                (size) -> {
                    RequestOptions requestOptionsForSinglePage = 
                            requestOptions == null ? new RequestOptions() : requestOptions;
                    if (size != null) {
                        requestOptionsForSinglePage.addQueryParam("maxpagesize", String.valueOf(size));
                    }
                    return listSinglePage(requestOptionsForSinglePage);
                },
                (nextLink, size) -> {
                    RequestOptions requestOptionsForNextPage = new RequestOptions();
                    requestOptionsForNextPage.setContext(
                            requestOptions != null && requestOptions.getContext() != null
                                    ? requestOptions.getContext()
                                    : Context.NONE);
                    if (size != null) {
                        requestOptionsForNextPage.addQueryParam("maxpagesize", String.valueOf(size));
                    }
                    return listNextSinglePage(nextLink, requestOptionsForNextPage);
                });
    }