From 2c4491cb89d822f570c18170259461dbf460262b Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 11:48:58 +0800 Subject: [PATCH 1/7] fix(java): support nested pageable response paths Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../emitter/src/code-model-builder.ts | 16 ------ .../core/template/ClientMethodTemplate.java | 22 ++++++--- .../template/ClientMethodTemplateBase.java | 49 ++++++------------- .../generator/core/util/TemplateUtil.java | 18 ++++--- .../http-client-generator-test/Generate.ps1 | 10 ---- .../java/payload/pageable/PageableTests.java | 24 +++++++++ 6 files changed, 65 insertions(+), 74 deletions(-) create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java 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 206efcea876..401e9e76888 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -1205,22 +1205,6 @@ export class CodeModelBuilder { ? pageItemsResponseProperty[0].serializedName : undefined; - if ( - this.isAzureV1() && - (pageItemsResponseProperty === undefined || pageItemsResponseProperty.length > 1) - ) { - // TCGC should have verified that pageItems exists - - // Azure V1 does not support nested page items - reportDiagnostic(this.program, { - code: "nested-page-items-not-supported", - target: - sdkMethod.response.resultSegments?.[sdkMethod.response.resultSegments.length - 1] - ?.__raw ?? NoTarget, - }); - return; - } - // nextLink // TODO: nextLink can also be a response header, similar to "sdkMethod.pagingMetadata.continuationTokenResponseSegments" const nextLinkResponseProperty = findResponsePropertySegments( 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 01ad84e26b3..b31b92e007c 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 @@ -58,6 +58,12 @@ public class ClientMethodTemplate extends ClientMethodTemplateBase { protected ClientMethodTemplate() { } + private static String serializedPropertyPath(List propertyReference) { + return propertyReference.stream() + .map(segment -> ClassType.STRING.defaultValueExpression(segment.getProperty().getSerializedName())) + .collect(Collectors.joining(", ")); + } + public static ClientMethodTemplate getInstance() { return INSTANCE; } @@ -986,16 +992,16 @@ protected void pagedSinglePageResponseConversion(ProxyMethod restAPIMethod, Clie function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); if (settings.isDataPlaneClient()) { - function.line("getValues(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedItemName()); + function.line("getValues(res.getValue(), %s),", + serializedPropertyPath(clientMethod.getMethodPageDetails().getPageItemsPropertyReference())); } else { function.line("res.getValue().%s(),", CodeNamer.getModelNamer().modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { if (settings.isDataPlaneClient()) { - function.line("getNextLink(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedNextLinkName()); + function.line("getNextLink(res.getValue(), %s),", + serializedPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else { function.line(nextLinkLine(clientMethod)); } @@ -1449,16 +1455,16 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); if (settings.isDataPlaneClient() && settings.isAzureV1()) { - function.line("getValues(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedItemName()); + function.line("getValues(res.getValue(), %s),", serializedPropertyPath( + clientMethod.getMethodPageDetails().getPageItemsPropertyReference())); } else { function.line("res.getValue().%s(),", CodeNamer.getModelNamer() .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { if (settings.isDataPlaneClient() && settings.isAzureV1()) { - function.line("getNextLink(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedNextLinkName()); + function.line("getNextLink(res.getValue(), %s),", serializedPropertyPath( + clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else { function.line(nextLinkLine(clientMethod)); } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java index c473ee3639e..03fe16bf80d 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java @@ -14,6 +14,7 @@ import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IterableType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.MapType; +import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ModelPropertySegment; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ParameterSynthesizedOrigin; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.PrimitiveType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ProxyMethod; @@ -88,42 +89,22 @@ protected static void generateProtocolMethodJavadoc(ClientMethod clientMethod, J if (JavaSettings.getInstance().isDataPlaneClient() && JavaSettings.getInstance().isAzureV1()) { // special handling for paging method if (clientMethod.getType().isPaging()) { - String itemName = clientMethod.getMethodPageDetails().getItemName(); - // rawResponseType has properties: 'value' and 'nextLink' - IType rawResponseType = clientMethod.getProxyMethod().getRawResponseBodyType(); - if (!(rawResponseType instanceof ClassType)) { - throw new IllegalStateException(String.format( - "clientMethod.getProxyMethod().getRawResponseBodyType() should be ClassType for paging method. rawResponseType = %s", - rawResponseType.toString())); + List pageItemsPropertyReference + = clientMethod.getMethodPageDetails().getPageItemsPropertyReference(); + IType valueListType = pageItemsPropertyReference.get(pageItemsPropertyReference.size() - 1) + .getProperty() + .getClientType(); + if (!(valueListType instanceof IterableType)) { + throw new IllegalStateException( + "Page items property must be List or Iterable. ResponseType = " + valueListType); } - ClientModel model = ClientModelUtil.getClientModel(((ClassType) rawResponseType).getName()); - Map properties = new LinkedHashMap<>(); - traverseProperties(model, properties); - responseBodyType = properties.values() - .stream() - .filter(property -> property.getName().equals(itemName)) - .map(ClientModelProperty::getClientType) - .map(valueListType -> { - // value type is List, we need to get the typeArguments - if (!(valueListType instanceof IterableType)) { - throw new IllegalStateException( - "Type of 'value' property must be List or Iterable, for paging method. ResponseType = " - + rawResponseType); - } - IType[] listTypeArgs = ((IterableType) valueListType).getTypeArguments(); - if (listTypeArgs.length == 0) { - throw new IllegalStateException( - "List or Iterable type does not have template argument. ResponseType = " - + rawResponseType); - } - return listTypeArgs[0]; - }) - .findFirst() - .orElse(null); - if (responseBodyType == null) { - throw new IllegalStateException(itemName - + " not found in properties of rawResponseType. rawResponseType = " + rawResponseType); + IType[] listTypeArgs = ((IterableType) valueListType).getTypeArguments(); + if (listTypeArgs.length == 0) { + throw new IllegalStateException( + "Page items List or Iterable does not have a template argument. ResponseType = " + + valueListType); } + responseBodyType = listTypeArgs[0]; } else { responseBodyType = clientMethod.getProxyMethod().getRawResponseBodyType(); } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java index bd394a7e20d..bf3cbfd1987 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java @@ -246,17 +246,23 @@ public static void writeTypeReferenceStaticVariable(JavaClass classBlock, Generi * @param classBlock Java class block */ private static void writePagingHelperMethods(JavaClass classBlock) { - classBlock.privateMethod("List getValues(BinaryData binaryData, String path)", block -> { + classBlock.privateMethod("List getValues(BinaryData binaryData, String... path)", block -> { block.line("try {"); - block.line("Map obj = binaryData.toObject(Map.class);"); - block.line("List values = (List) obj.get(path);"); + block.line("Object value = binaryData.toObject(Map.class);"); + block.line("for (String segment : path) {"); + block.indent(() -> block.line("value = ((Map) value).get(segment);")); + block.line("}"); + block.line("List values = (List) value;"); block.line("return values.stream().map(BinaryData::fromObject).collect(Collectors.toList());"); block.line("} catch (RuntimeException e) { return null; }"); }); - classBlock.privateMethod("String getNextLink(BinaryData binaryData, String path)", block -> { + classBlock.privateMethod("String getNextLink(BinaryData binaryData, String... path)", block -> { block.line("try {"); - block.line("Map obj = binaryData.toObject(Map.class);"); - block.line("return (String) obj.get(path);"); + block.line("Object value = binaryData.toObject(Map.class);"); + block.line("for (String segment : path) {"); + block.indent(() -> block.line("value = ((Map) value).get(segment);")); + block.line("}"); + block.line("return (String) value;"); block.line("} catch (RuntimeException e) { return null; }"); }); } diff --git a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 index fcfd434dd35..0e66ca6c2c4 100644 --- a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 +++ b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 @@ -19,16 +19,6 @@ Write-Host "Parallelization: $Parallelization" $generateScript = { $tspFile = $_ - if ((($tspFile -match "payload[\\/]pageable[\\/]main\.tsp") -and (-not ($tspFile -match "azure[\\/]payload[\\/]pageable[\\/]main\.tsp")))) { - Write-Host " - SKIPPED - $tspFile - " - # xml is not supported - # nested pageItems/nextLink/continuationToken is not supported - return - } - $tspClientFile = $tspFile -replace 'main.tsp', 'client.tsp' if (($tspClientFile -match 'client.tsp$') -and (Test-Path $tspClientFile)) { $tspFile = $tspClientFile diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java new file mode 100644 index 00000000000..a4402478d6e --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package payload.pageable; + +import com.azure.core.http.rest.PagedIterable; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import payload.pageable.models.Pet; + +public class PageableTests { + + private final PageableClientBuilder builder = new PageableClientBuilder(); + + @Test + public void testNestedLink() { + PagedIterable pagedIterable = builder.buildServerDrivenPaginationClient().nestedLink(); + + Assertions.assertEquals(List.of("1", "2", "3", "4"), + pagedIterable.stream().map(Pet::getId).collect(Collectors.toList())); + } +} From d78a105ad9637848fe15fcd20da745a48275aaf4 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 11:58:00 +0800 Subject: [PATCH 2/7] test(java): cover supported pageable scenarios Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../java/payload/pageable/PageableTests.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java index a4402478d6e..f883a8752aa 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java @@ -9,16 +9,56 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import payload.pageable.models.Pet; +import payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter; public class PageableTests { private final PageableClientBuilder builder = new PageableClientBuilder(); + @Test + public void testLink() { + assertPetIds(builder.buildServerDrivenPaginationClient().link()); + } + + @Test + public void testLinkString() { + assertPetIds(builder.buildServerDrivenPaginationClient().linkString()); + } + @Test public void testNestedLink() { - PagedIterable pagedIterable = builder.buildServerDrivenPaginationClient().nestedLink(); + assertPetIds(builder.buildServerDrivenPaginationClient().nestedLink()); + } + + @Test + public void testListWithoutContinuation() { + assertPetIds(builder.buildPageSizeClient().listWithoutContinuation()); + } + + @Test + public void testListWithPageSize() { + assertPetIds(builder.buildPageSizeClient().listWithPageSize(2), "1", "2"); + } + + @Test + public void testPost() { + assertPetIds(builder.buildServerDrivenPaginationAlternateInitialVerbClient().post(new Filter("foo eq bar"))); + } + + /* + * Continuation-token scenarios are intentionally not covered here. Azure V1 currently emits a single-page + * PagedIterable for them because it does not propagate a response continuation token into the next request. + * + * XML paging is also intentionally not covered. Azure V1 extracts page data from BinaryData as JSON, so XML + * pageable responses cannot be read. + */ + + private static void assertPetIds(PagedIterable pagedIterable) { + assertPetIds(pagedIterable, "1", "2", "3", "4"); + } - Assertions.assertEquals(List.of("1", "2", "3", "4"), + private static void assertPetIds(PagedIterable pagedIterable, String... expectedIds) { + Assertions.assertEquals(List.of(expectedIds), pagedIterable.stream().map(Pet::getId).collect(Collectors.toList())); } } From ae57ae9e61a480a8a8a0ae9044175d3d00ed8384 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 12:00:45 +0800 Subject: [PATCH 3/7] chore(java): add nested pageable changelog Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../weidongxu-nested-pageable-2026-07-31-11-59-00.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/weidongxu-nested-pageable-2026-07-31-11-59-00.md diff --git a/.chronus/changes/weidongxu-nested-pageable-2026-07-31-11-59-00.md b/.chronus/changes/weidongxu-nested-pageable-2026-07-31-11-59-00.md new file mode 100644 index 00000000000..d42a7510ba9 --- /dev/null +++ b/.chronus/changes/weidongxu-nested-pageable-2026-07-31-11-59-00.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-java" +--- + +Support nested property paths in Azure pageable responses. From e22a02625631afa73e6453afae4329af776eedb0 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 12:04:38 +0800 Subject: [PATCH 4/7] chore(java): remove obsolete pageable diagnostic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- packages/http-client-java/emitter/src/lib.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/http-client-java/emitter/src/lib.ts b/packages/http-client-java/emitter/src/lib.ts index 681d51ca6d8..9074269eda4 100644 --- a/packages/http-client-java/emitter/src/lib.ts +++ b/packages/http-client-java/emitter/src/lib.ts @@ -109,12 +109,6 @@ export const $lib = createTypeSpecLibrary({ default: paramMessage`Namespace '${"namespace"}' contains reserved Java keywords, replaced it with '${"processedNamespace"}'.`, }, }, - "nested-page-items-not-supported": { - severity: "warning", - messages: { - default: "Nested pageItems is not supported in Azure V1.", - }, - }, "constant-header-in-response-removed": { severity: "warning", messages: { From de512203717f99ea2ba59280f81d804a3428dabf Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 12:26:26 +0800 Subject: [PATCH 5/7] test(java): add generated pageable test sources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../NextLinkVerbClientImpl.java | 18 +- .../basic/implementation/BasicClientImpl.java | 18 +- .../page/implementation/PageClientImpl.java | 18 +- .../TwoModelsAsPageItemsImpl.java | 18 +- .../implementation/PageableClientImpl.java | 18 +- .../payload/pageable/PageSizeAsyncClient.java | 196 +++ .../java/payload/pageable/PageSizeClient.java | 159 +++ .../pageable/PageableClientBuilder.java | 384 ++++++ ...nationAlternateInitialVerbAsyncClient.java | 113 ++ ...nPaginationAlternateInitialVerbClient.java | 97 ++ .../ServerDrivenPaginationAsyncClient.java | 210 +++ .../ServerDrivenPaginationClient.java | 170 +++ ...aginationContinuationTokenAsyncClient.java | 727 ++++++++++ ...ivenPaginationContinuationTokenClient.java | 591 ++++++++ .../pageable/XmlPaginationAsyncClient.java | 201 +++ .../payload/pageable/XmlPaginationClient.java | 164 +++ .../implementation/PageSizesImpl.java | 374 +++++ .../implementation/PageableClientImpl.java | 167 +++ ...enPaginationAlternateInitialVerbsImpl.java | 355 +++++ ...rivenPaginationContinuationTokensImpl.java | 1213 +++++++++++++++++ .../ServerDrivenPaginationsImpl.java | 740 ++++++++++ .../implementation/XmlPaginationsImpl.java | 468 +++++++ .../implementation/XmlSerializer.java | 78 ++ .../XmlSerializerProviders.java | 29 + .../pageable/implementation/package-info.java | 11 + .../java/payload/pageable/models/Pet.java | 105 ++ .../java/payload/pageable/models/XmlPet.java | 126 ++ .../payload/pageable/models/package-info.java | 11 + .../java/payload/pageable/package-info.java | 11 + .../alternateinitialverb/models/Filter.java | 83 ++ .../models/package-info.java | 11 + ...NestedResponseBodyResponseNestedItems.java | 87 ++ ...rNestedResponseBodyResponseNestedNext.java | 82 ++ ...NestedResponseBodyResponseNestedItems.java | 86 ++ ...yNestedResponseBodyResponseNestedNext.java | 82 ++ .../models/package-info.java | 11 + .../models/NestedLinkResponseNestedItems.java | 85 ++ .../models/NestedLinkResponseNestedNext.java | 80 ++ .../models/package-info.java | 11 + .../ProtocolAndConvenienceOpsImpl.java | 18 +- .../implementation/ResponseClientImpl.java | 18 +- .../implementation/EtagHeadersImpl.java | 18 +- .../implementation/VersioningOpsImpl.java | 18 +- .../META-INF/payload-pageable_metadata.json | 1 + .../tsptest-responseheaders_metadata.json | 2 +- .../tsptest-xmlbytesverify_metadata.json | 2 +- .../resources/payload-pageable.properties | 2 + .../generated/PageableClientTestBase.java | 84 ++ 48 files changed, 7515 insertions(+), 56 deletions(-) create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageableClientBuilder.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageSizesImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageableClientImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationAlternateInitialVerbsImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationContinuationTokensImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializer.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializerProviders.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/Pet.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/XmlPet.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/Filter.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedItems.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedNext.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedItems.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedNext.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedItems.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedNext.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/payload-pageable_metadata.json create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/resources/payload-pageable.properties create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/generated/PageableClientTestBase.java diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/clientgenerator/core/nextlinkverb/implementation/NextLinkVerbClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/clientgenerator/core/nextlinkverb/implementation/NextLinkVerbClientImpl.java index 86da457c2c6..d65d6461bb2 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/clientgenerator/core/nextlinkverb/implementation/NextLinkVerbClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/clientgenerator/core/nextlinkverb/implementation/NextLinkVerbClientImpl.java @@ -341,20 +341,26 @@ private PagedResponse listItemsNextSinglePage(String nextLink, Reque getValues(res.getValue(), "items"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/basic/implementation/BasicClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/basic/implementation/BasicClientImpl.java index 0d851f4d0ce..5bbedb637d8 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/basic/implementation/BasicClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/basic/implementation/BasicClientImpl.java @@ -1183,20 +1183,26 @@ private PagedResponse listNextSinglePage(String nextLink, RequestOpt getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/PageClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/PageClientImpl.java index acf44981467..14b65cd0166 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/PageClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/PageClientImpl.java @@ -1632,20 +1632,26 @@ private PagedResponse withRelativeNextLinkNextSinglePage(String next getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/TwoModelsAsPageItemsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/TwoModelsAsPageItemsImpl.java index 177aee41257..0e1df90ebd0 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/TwoModelsAsPageItemsImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/core/page/implementation/TwoModelsAsPageItemsImpl.java @@ -513,20 +513,26 @@ private PagedResponse listSecondItemNextSinglePage(String nextLink, getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/payload/pageable/implementation/PageableClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/payload/pageable/implementation/PageableClientImpl.java index 70002c4a3ee..80b3b831e7a 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/payload/pageable/implementation/PageableClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/payload/pageable/implementation/PageableClientImpl.java @@ -406,20 +406,26 @@ private PagedResponse listNextSinglePage(String nextLink, RequestOpt getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeAsyncClient.java new file mode 100644 index 00000000000..7747db081e9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeAsyncClient.java @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import java.util.stream.Collectors; +import payload.pageable.implementation.PageSizesImpl; +import payload.pageable.models.Pet; +import reactor.core.publisher.Flux; + +/** + * Initializes a new instance of the asynchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class, isAsync = true) +public final class PageSizeAsyncClient { + @Generated + private final PageSizesImpl serviceClient; + + /** + * Initializes an instance of PageSizeAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + PageSizeAsyncClient(PageSizesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithoutContinuation(RequestOptions requestOptions) { + return this.serviceClient.listWithoutContinuationAsync(requestOptions); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithPageSize(RequestOptions requestOptions) { + return this.serviceClient.listWithPageSizeAsync(requestOptions); + } + + /** + * The listWithoutContinuation operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithoutContinuation() { + // Generated convenience method for listWithoutContinuation + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listWithoutContinuation(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The listWithPageSize operation. + * + * @param pageSize The pageSize parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithPageSize(Integer pageSize) { + // Generated convenience method for listWithPageSize + RequestOptions requestOptions = new RequestOptions(); + if (pageSize != null) { + requestOptions.addQueryParam("pageSize", String.valueOf(pageSize), false); + } + PagedFlux pagedFluxResponse = listWithPageSize(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The listWithPageSize operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithPageSize() { + // Generated convenience method for listWithPageSize + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listWithPageSize(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeClient.java new file mode 100644 index 00000000000..a8bd6756150 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageSizeClient.java @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import payload.pageable.implementation.PageSizesImpl; +import payload.pageable.models.Pet; + +/** + * Initializes a new instance of the synchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class) +public final class PageSizeClient { + @Generated + private final PageSizesImpl serviceClient; + + /** + * Initializes an instance of PageSizeClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + PageSizeClient(PageSizesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithoutContinuation(RequestOptions requestOptions) { + return this.serviceClient.listWithoutContinuation(requestOptions); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithPageSize(RequestOptions requestOptions) { + return this.serviceClient.listWithPageSize(requestOptions); + } + + /** + * The listWithoutContinuation operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithoutContinuation() { + // Generated convenience method for listWithoutContinuation + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listWithoutContinuation(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The listWithPageSize operation. + * + * @param pageSize The pageSize parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithPageSize(Integer pageSize) { + // Generated convenience method for listWithPageSize + RequestOptions requestOptions = new RequestOptions(); + if (pageSize != null) { + requestOptions.addQueryParam("pageSize", String.valueOf(pageSize), false); + } + return serviceClient.listWithPageSize(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The listWithPageSize operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithPageSize() { + // Generated convenience method for listWithPageSize + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listWithPageSize(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageableClientBuilder.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageableClientBuilder.java new file mode 100644 index 00000000000..2ec19bb1c43 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/PageableClientBuilder.java @@ -0,0 +1,384 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import payload.pageable.implementation.PageableClientImpl; + +/** + * A builder for creating a new instance of the PageableClient type. + */ +@ServiceClientBuilder( + serviceClients = { + ServerDrivenPaginationClient.class, + ServerDrivenPaginationAlternateInitialVerbClient.class, + ServerDrivenPaginationContinuationTokenClient.class, + PageSizeClient.class, + XmlPaginationClient.class, + ServerDrivenPaginationAsyncClient.class, + ServerDrivenPaginationAlternateInitialVerbAsyncClient.class, + ServerDrivenPaginationContinuationTokenAsyncClient.class, + PageSizeAsyncClient.class, + XmlPaginationAsyncClient.class }) +public final class PageableClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES = CoreUtils.getProperties("payload-pageable.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the PageableClientBuilder. + */ + @Generated + public PageableClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public PageableClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the PageableClientBuilder. + */ + @Generated + public PageableClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of PageableClientImpl with the provided parameters. + * + * @return an instance of PageableClientImpl. + */ + @Generated + private PageableClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localEndpoint = (endpoint != null) ? endpoint : "http://localhost:3000"; + PageableClientImpl client + = new PageableClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), localEndpoint); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of ServerDrivenPaginationAsyncClient class. + * + * @return an instance of ServerDrivenPaginationAsyncClient. + */ + @Generated + public ServerDrivenPaginationAsyncClient buildServerDrivenPaginationAsyncClient() { + return new ServerDrivenPaginationAsyncClient(buildInnerClient().getServerDrivenPaginations()); + } + + /** + * Builds an instance of ServerDrivenPaginationAlternateInitialVerbAsyncClient class. + * + * @return an instance of ServerDrivenPaginationAlternateInitialVerbAsyncClient. + */ + @Generated + public ServerDrivenPaginationAlternateInitialVerbAsyncClient + buildServerDrivenPaginationAlternateInitialVerbAsyncClient() { + return new ServerDrivenPaginationAlternateInitialVerbAsyncClient( + buildInnerClient().getServerDrivenPaginationAlternateInitialVerbs()); + } + + /** + * Builds an instance of ServerDrivenPaginationContinuationTokenAsyncClient class. + * + * @return an instance of ServerDrivenPaginationContinuationTokenAsyncClient. + */ + @Generated + public ServerDrivenPaginationContinuationTokenAsyncClient + buildServerDrivenPaginationContinuationTokenAsyncClient() { + return new ServerDrivenPaginationContinuationTokenAsyncClient( + buildInnerClient().getServerDrivenPaginationContinuationTokens()); + } + + /** + * Builds an instance of PageSizeAsyncClient class. + * + * @return an instance of PageSizeAsyncClient. + */ + @Generated + public PageSizeAsyncClient buildPageSizeAsyncClient() { + return new PageSizeAsyncClient(buildInnerClient().getPageSizes()); + } + + /** + * Builds an instance of XmlPaginationAsyncClient class. + * + * @return an instance of XmlPaginationAsyncClient. + */ + @Generated + public XmlPaginationAsyncClient buildXmlPaginationAsyncClient() { + return new XmlPaginationAsyncClient(buildInnerClient().getXmlPaginations()); + } + + /** + * Builds an instance of ServerDrivenPaginationClient class. + * + * @return an instance of ServerDrivenPaginationClient. + */ + @Generated + public ServerDrivenPaginationClient buildServerDrivenPaginationClient() { + return new ServerDrivenPaginationClient(buildInnerClient().getServerDrivenPaginations()); + } + + /** + * Builds an instance of ServerDrivenPaginationAlternateInitialVerbClient class. + * + * @return an instance of ServerDrivenPaginationAlternateInitialVerbClient. + */ + @Generated + public ServerDrivenPaginationAlternateInitialVerbClient buildServerDrivenPaginationAlternateInitialVerbClient() { + return new ServerDrivenPaginationAlternateInitialVerbClient( + buildInnerClient().getServerDrivenPaginationAlternateInitialVerbs()); + } + + /** + * Builds an instance of ServerDrivenPaginationContinuationTokenClient class. + * + * @return an instance of ServerDrivenPaginationContinuationTokenClient. + */ + @Generated + public ServerDrivenPaginationContinuationTokenClient buildServerDrivenPaginationContinuationTokenClient() { + return new ServerDrivenPaginationContinuationTokenClient( + buildInnerClient().getServerDrivenPaginationContinuationTokens()); + } + + /** + * Builds an instance of PageSizeClient class. + * + * @return an instance of PageSizeClient. + */ + @Generated + public PageSizeClient buildPageSizeClient() { + return new PageSizeClient(buildInnerClient().getPageSizes()); + } + + /** + * Builds an instance of XmlPaginationClient class. + * + * @return an instance of XmlPaginationClient. + */ + @Generated + public XmlPaginationClient buildXmlPaginationClient() { + return new XmlPaginationClient(buildInnerClient().getXmlPaginations()); + } + + private static final ClientLogger LOGGER = new ClientLogger(PageableClientBuilder.class); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbAsyncClient.java new file mode 100644 index 00000000000..b9479350f9b --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbAsyncClient.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import java.util.stream.Collectors; +import payload.pageable.implementation.ServerDrivenPaginationAlternateInitialVerbsImpl; +import payload.pageable.models.Pet; +import payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter; +import reactor.core.publisher.Flux; + +/** + * Initializes a new instance of the asynchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class, isAsync = true) +public final class ServerDrivenPaginationAlternateInitialVerbAsyncClient { + @Generated + private final ServerDrivenPaginationAlternateInitialVerbsImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationAlternateInitialVerbAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationAlternateInitialVerbAsyncClient( + ServerDrivenPaginationAlternateInitialVerbsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux post(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.postAsync(body, requestOptions); + } + + /** + * The post operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux post(Filter body) { + // Generated convenience method for post + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = post(BinaryData.fromObject(body), requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbClient.java new file mode 100644 index 00000000000..abb9613f7dd --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbClient.java @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import payload.pageable.implementation.ServerDrivenPaginationAlternateInitialVerbsImpl; +import payload.pageable.models.Pet; +import payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter; + +/** + * Initializes a new instance of the synchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class) +public final class ServerDrivenPaginationAlternateInitialVerbClient { + @Generated + private final ServerDrivenPaginationAlternateInitialVerbsImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationAlternateInitialVerbClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationAlternateInitialVerbClient(ServerDrivenPaginationAlternateInitialVerbsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable post(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.post(body, requestOptions); + } + + /** + * The post operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable post(Filter body) { + // Generated convenience method for post + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.post(BinaryData.fromObject(body), requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAsyncClient.java new file mode 100644 index 00000000000..9a09fca9053 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationAsyncClient.java @@ -0,0 +1,210 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import java.util.stream.Collectors; +import payload.pageable.implementation.ServerDrivenPaginationsImpl; +import payload.pageable.models.Pet; +import reactor.core.publisher.Flux; + +/** + * Initializes a new instance of the asynchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class, isAsync = true) +public final class ServerDrivenPaginationAsyncClient { + @Generated + private final ServerDrivenPaginationsImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationAsyncClient(ServerDrivenPaginationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux link(RequestOptions requestOptions) { + return this.serviceClient.linkAsync(requestOptions); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux linkString(RequestOptions requestOptions) { + return this.serviceClient.linkStringAsync(requestOptions); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux nestedLink(RequestOptions requestOptions) { + return this.serviceClient.nestedLinkAsync(requestOptions); + } + + /** + * The link operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux link() { + // Generated convenience method for link + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = link(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The linkString operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux linkString() { + // Generated convenience method for linkString + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = linkString(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The nestedLink operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux nestedLink() { + // Generated convenience method for nestedLink + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = nestedLink(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationClient.java new file mode 100644 index 00000000000..329043a905a --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationClient.java @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import payload.pageable.implementation.ServerDrivenPaginationsImpl; +import payload.pageable.models.Pet; + +/** + * Initializes a new instance of the synchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class) +public final class ServerDrivenPaginationClient { + @Generated + private final ServerDrivenPaginationsImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationClient(ServerDrivenPaginationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link(RequestOptions requestOptions) { + return this.serviceClient.link(requestOptions); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable linkString(RequestOptions requestOptions) { + return this.serviceClient.linkString(requestOptions); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable nestedLink(RequestOptions requestOptions) { + return this.serviceClient.nestedLink(requestOptions); + } + + /** + * The link operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link() { + // Generated convenience method for link + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.link(requestOptions).mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The linkString operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable linkString() { + // Generated convenience method for linkString + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.linkString(requestOptions).mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The nestedLink operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable nestedLink() { + // Generated convenience method for nestedLink + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.nestedLink(requestOptions).mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenAsyncClient.java new file mode 100644 index 00000000000..ff4ef0ad14c --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenAsyncClient.java @@ -0,0 +1,727 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import java.util.stream.Collectors; +import payload.pageable.implementation.ServerDrivenPaginationContinuationTokensImpl; +import payload.pageable.models.Pet; +import reactor.core.publisher.Flux; + +/** + * Initializes a new instance of the asynchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class, isAsync = true) +public final class ServerDrivenPaginationContinuationTokenAsyncClient { + @Generated + private final ServerDrivenPaginationContinuationTokensImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationContinuationTokenAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationContinuationTokenAsyncClient(ServerDrivenPaginationContinuationTokensImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestQueryResponseBodyAsync(requestOptions); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderResponseBodyAsync(requestOptions); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseHeader(RequestOptions requestOptions) { + return this.serviceClient.requestQueryResponseHeaderAsync(requestOptions); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseHeader(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderResponseHeaderAsync(requestOptions); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryNestedResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestQueryNestedResponseBodyAsync(requestOptions); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderNestedResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderNestedResponseBodyAsync(requestOptions); + } + + /** + * The requestQueryResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestQueryResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestQueryResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestQueryResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseBody() { + // Generated convenience method for requestQueryResponseBody + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestQueryResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestHeaderResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestHeaderResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseBody() { + // Generated convenience method for requestHeaderResponseBody + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestHeaderResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestQueryResponseHeader operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseHeader(String token, String foo, String bar) { + // Generated convenience method for requestQueryResponseHeader + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestQueryResponseHeader(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestQueryResponseHeader operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseHeader() { + // Generated convenience method for requestQueryResponseHeader + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestQueryResponseHeader(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderResponseHeader operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseHeader(String token, String foo, String bar) { + // Generated convenience method for requestHeaderResponseHeader + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestHeaderResponseHeader(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderResponseHeader operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseHeader() { + // Generated convenience method for requestHeaderResponseHeader + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestHeaderResponseHeader(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestQueryNestedResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryNestedResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestQueryNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestQueryNestedResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestQueryNestedResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryNestedResponseBody() { + // Generated convenience method for requestQueryNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestQueryNestedResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderNestedResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderNestedResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestHeaderNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + PagedFlux pagedFluxResponse = requestHeaderNestedResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The requestHeaderNestedResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderNestedResponseBody() { + // Generated convenience method for requestHeaderNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = requestHeaderNestedResponseBody(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenClient.java new file mode 100644 index 00000000000..545b4d29e28 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenClient.java @@ -0,0 +1,591 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import payload.pageable.implementation.ServerDrivenPaginationContinuationTokensImpl; +import payload.pageable.models.Pet; + +/** + * Initializes a new instance of the synchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class) +public final class ServerDrivenPaginationContinuationTokenClient { + @Generated + private final ServerDrivenPaginationContinuationTokensImpl serviceClient; + + /** + * Initializes an instance of ServerDrivenPaginationContinuationTokenClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ServerDrivenPaginationContinuationTokenClient(ServerDrivenPaginationContinuationTokensImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestQueryResponseBody(requestOptions); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderResponseBody(requestOptions); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseHeader(RequestOptions requestOptions) { + return this.serviceClient.requestQueryResponseHeader(requestOptions); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseHeader(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderResponseHeader(requestOptions); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryNestedResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestQueryNestedResponseBody(requestOptions); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderNestedResponseBody(RequestOptions requestOptions) { + return this.serviceClient.requestHeaderNestedResponseBody(requestOptions); + } + + /** + * The requestQueryResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestQueryResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestQueryResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestQueryResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseBody() { + // Generated convenience method for requestQueryResponseBody + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestQueryResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestHeaderResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestHeaderResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseBody() { + // Generated convenience method for requestHeaderResponseBody + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestHeaderResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestQueryResponseHeader operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseHeader(String token, String foo, String bar) { + // Generated convenience method for requestQueryResponseHeader + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestQueryResponseHeader(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestQueryResponseHeader operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseHeader() { + // Generated convenience method for requestQueryResponseHeader + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestQueryResponseHeader(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderResponseHeader operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseHeader(String token, String foo, String bar) { + // Generated convenience method for requestHeaderResponseHeader + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestHeaderResponseHeader(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderResponseHeader operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseHeader() { + // Generated convenience method for requestHeaderResponseHeader + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestHeaderResponseHeader(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestQueryNestedResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryNestedResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestQueryNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.addQueryParam("token", token, false); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestQueryNestedResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestQueryNestedResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryNestedResponseBody() { + // Generated convenience method for requestQueryNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestQueryNestedResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderNestedResponseBody operation. + * + * @param token The token parameter. + * @param foo The foo parameter. + * @param bar The bar parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderNestedResponseBody(String token, String foo, String bar) { + // Generated convenience method for requestHeaderNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + if (token != null) { + requestOptions.setHeader(HttpHeaderName.fromString("token"), token); + } + if (foo != null) { + requestOptions.setHeader(HttpHeaderName.fromString("foo"), foo); + } + if (bar != null) { + requestOptions.addQueryParam("bar", bar, false); + } + return serviceClient.requestHeaderNestedResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } + + /** + * The requestHeaderNestedResponseBody operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderNestedResponseBody() { + // Generated convenience method for requestHeaderNestedResponseBody + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.requestHeaderNestedResponseBody(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationAsyncClient.java new file mode 100644 index 00000000000..817d8cdf127 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationAsyncClient.java @@ -0,0 +1,201 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import com.azure.core.util.serializer.ObjectSerializer; +import java.util.stream.Collectors; +import payload.pageable.implementation.XmlPaginationsImpl; +import payload.pageable.implementation.XmlSerializerProviders; +import payload.pageable.models.XmlPet; +import reactor.core.publisher.Flux; + +/** + * Initializes a new instance of the asynchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class, isAsync = true) +public final class XmlPaginationAsyncClient { + @Generated + private static final ObjectSerializer XML_SERIALIZER = XmlSerializerProviders.createInstance(); + + @Generated + private final XmlPaginationsImpl serviceClient; + + /** + * Initializes an instance of XmlPaginationAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + XmlPaginationAsyncClient(XmlPaginationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithContinuation(RequestOptions requestOptions) { + return this.serviceClient.listWithContinuationAsync(requestOptions); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithNextLink(RequestOptions requestOptions) { + return this.serviceClient.listWithNextLinkAsync(requestOptions); + } + + /** + * The listWithContinuation operation. + * + * @param marker The marker parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithContinuation(String marker) { + // Generated convenience method for listWithContinuation + RequestOptions requestOptions = new RequestOptions(); + if (marker != null) { + requestOptions.addQueryParam("marker", marker, false); + } + PagedFlux pagedFluxResponse = listWithContinuation(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(XmlPet.class, XML_SERIALIZER)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The listWithContinuation operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithContinuation() { + // Generated convenience method for listWithContinuation + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listWithContinuation(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(XmlPet.class, XML_SERIALIZER)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * The listWithNextLink operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets with next link as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithNextLink() { + // Generated convenience method for listWithNextLink + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listWithNextLink(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(XmlPet.class, XML_SERIALIZER)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationClient.java new file mode 100644 index 00000000000..c1d5f6fd3d5 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/XmlPaginationClient.java @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.util.BinaryData; +import com.azure.core.util.serializer.ObjectSerializer; +import payload.pageable.implementation.XmlPaginationsImpl; +import payload.pageable.implementation.XmlSerializerProviders; +import payload.pageable.models.XmlPet; + +/** + * Initializes a new instance of the synchronous PageableClient type. + */ +@ServiceClient(builder = PageableClientBuilder.class) +public final class XmlPaginationClient { + @Generated + private static final ObjectSerializer XML_SERIALIZER = XmlSerializerProviders.createInstance(); + + @Generated + private final XmlPaginationsImpl serviceClient; + + /** + * Initializes an instance of XmlPaginationClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + XmlPaginationClient(XmlPaginationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithContinuation(RequestOptions requestOptions) { + return this.serviceClient.listWithContinuation(requestOptions); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithNextLink(RequestOptions requestOptions) { + return this.serviceClient.listWithNextLink(requestOptions); + } + + /** + * The listWithContinuation operation. + * + * @param marker The marker parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithContinuation(String marker) { + // Generated convenience method for listWithContinuation + RequestOptions requestOptions = new RequestOptions(); + if (marker != null) { + requestOptions.addQueryParam("marker", marker, false); + } + return serviceClient.listWithContinuation(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(XmlPet.class, XML_SERIALIZER)); + } + + /** + * The listWithContinuation operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithContinuation() { + // Generated convenience method for listWithContinuation + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listWithContinuation(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(XmlPet.class, XML_SERIALIZER)); + } + + /** + * The listWithNextLink operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the XML response for listing pets with next link as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithNextLink() { + // Generated convenience method for listWithNextLink + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listWithNextLink(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(XmlPet.class, XML_SERIALIZER)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageSizesImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageSizesImpl.java new file mode 100644 index 00000000000..fc09d13caa9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageSizesImpl.java @@ -0,0 +1,374 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in PageSizes. + */ +public final class PageSizesImpl { + /** + * The proxy service used to perform REST calls. + */ + private final PageSizesService service; + + /** + * The service client containing this operation class. + */ + private final PageableClientImpl client; + + /** + * Initializes an instance of PageSizesImpl. + * + * @param client the instance of the service client containing this operation class. + */ + PageSizesImpl(PageableClientImpl client) { + this.service + = RestProxy.create(PageSizesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for PageableClientPageSizes to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "PageableClientPageSizes") + public interface PageSizesService { + @Get("/payload/pageable/pagesize/without-continuation") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWithoutContinuation(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/pagesize/without-continuation") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWithoutContinuationSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/pagesize/list") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWithPageSize(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/pagesize/list") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWithPageSizeSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWithoutContinuationSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listWithoutContinuation(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithoutContinuationAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> listWithoutContinuationSinglePageAsync(requestOptions)); + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWithoutContinuationSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.listWithoutContinuationSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The listWithoutContinuation operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithoutContinuation(RequestOptions requestOptions) { + return new PagedIterable<>(() -> listWithoutContinuationSinglePage(requestOptions)); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWithPageSizeSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listWithPageSize(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithPageSizeAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> listWithPageSizeSinglePageAsync(requestOptions)); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWithPageSizeSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.listWithPageSizeSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The listWithPageSize operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
pageSizeIntegerNoThe pageSize parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithPageSize(RequestOptions requestOptions) { + return new PagedIterable<>(() -> listWithPageSizeSinglePage(requestOptions)); + } + + private List getValues(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageableClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageableClientImpl.java new file mode 100644 index 00000000000..3ccad78c32b --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/PageableClientImpl.java @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** + * Initializes a new instance of the PageableClient type. + */ +public final class PageableClientImpl { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The ServerDrivenPaginationsImpl object to access its operations. + */ + private final ServerDrivenPaginationsImpl serverDrivenPaginations; + + /** + * Gets the ServerDrivenPaginationsImpl object to access its operations. + * + * @return the ServerDrivenPaginationsImpl object. + */ + public ServerDrivenPaginationsImpl getServerDrivenPaginations() { + return this.serverDrivenPaginations; + } + + /** + * The ServerDrivenPaginationAlternateInitialVerbsImpl object to access its operations. + */ + private final ServerDrivenPaginationAlternateInitialVerbsImpl serverDrivenPaginationAlternateInitialVerbs; + + /** + * Gets the ServerDrivenPaginationAlternateInitialVerbsImpl object to access its operations. + * + * @return the ServerDrivenPaginationAlternateInitialVerbsImpl object. + */ + public ServerDrivenPaginationAlternateInitialVerbsImpl getServerDrivenPaginationAlternateInitialVerbs() { + return this.serverDrivenPaginationAlternateInitialVerbs; + } + + /** + * The ServerDrivenPaginationContinuationTokensImpl object to access its operations. + */ + private final ServerDrivenPaginationContinuationTokensImpl serverDrivenPaginationContinuationTokens; + + /** + * Gets the ServerDrivenPaginationContinuationTokensImpl object to access its operations. + * + * @return the ServerDrivenPaginationContinuationTokensImpl object. + */ + public ServerDrivenPaginationContinuationTokensImpl getServerDrivenPaginationContinuationTokens() { + return this.serverDrivenPaginationContinuationTokens; + } + + /** + * The PageSizesImpl object to access its operations. + */ + private final PageSizesImpl pageSizes; + + /** + * Gets the PageSizesImpl object to access its operations. + * + * @return the PageSizesImpl object. + */ + public PageSizesImpl getPageSizes() { + return this.pageSizes; + } + + /** + * The XmlPaginationsImpl object to access its operations. + */ + private final XmlPaginationsImpl xmlPaginations; + + /** + * Gets the XmlPaginationsImpl object to access its operations. + * + * @return the XmlPaginationsImpl object. + */ + public XmlPaginationsImpl getXmlPaginations() { + return this.xmlPaginations; + } + + /** + * Initializes an instance of PageableClient client. + * + * @param endpoint Service host. + */ + public PageableClientImpl(String endpoint) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of PageableClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + */ + public PageableClientImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of PageableClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint Service host. + */ + public PageableClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serverDrivenPaginations = new ServerDrivenPaginationsImpl(this); + this.serverDrivenPaginationAlternateInitialVerbs = new ServerDrivenPaginationAlternateInitialVerbsImpl(this); + this.serverDrivenPaginationContinuationTokens = new ServerDrivenPaginationContinuationTokensImpl(this); + this.pageSizes = new PageSizesImpl(this); + this.xmlPaginations = new XmlPaginationsImpl(this); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationAlternateInitialVerbsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationAlternateInitialVerbsImpl.java new file mode 100644 index 00000000000..91e69804914 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationAlternateInitialVerbsImpl.java @@ -0,0 +1,355 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in + * ServerDrivenPaginationAlternateInitialVerbs. + */ +public final class ServerDrivenPaginationAlternateInitialVerbsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ServerDrivenPaginationAlternateInitialVerbsService service; + + /** + * The service client containing this operation class. + */ + private final PageableClientImpl client; + + /** + * Initializes an instance of ServerDrivenPaginationAlternateInitialVerbsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + ServerDrivenPaginationAlternateInitialVerbsImpl(PageableClientImpl client) { + this.service = RestProxy.create(ServerDrivenPaginationAlternateInitialVerbsService.class, + client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for PageableClientServerDrivenPaginationAlternateInitialVerbs to be used + * by the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "PageableClientServerDrivenPaginationAlternateInitialVerbs") + public interface ServerDrivenPaginationAlternateInitialVerbsService { + @Post("/payload/pageable/server-driven-pagination/link/initial-post") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> post(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + + @Post("/payload/pageable/server-driven-pagination/link/initial-post") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response postSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> postNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response postNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> postSinglePageAsync(BinaryData body, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.post(this.client.getEndpoint(), accept, body, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux postAsync(BinaryData body, RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> postSinglePageAsync(body, requestOptions), + nextLink -> postNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse postSinglePage(BinaryData body, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.postSync(this.client.getEndpoint(), accept, body, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + /** + * The post operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     filter: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable post(BinaryData body, RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> postSinglePage(body, requestOptions), + nextLink -> postNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> postNextSinglePageAsync(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.postNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse postNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.postNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + private List getValues(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationContinuationTokensImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationContinuationTokensImpl.java new file mode 100644 index 00000000000..3594168cfdd --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationContinuationTokensImpl.java @@ -0,0 +1,1213 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in ServerDrivenPaginationContinuationTokens. + */ +public final class ServerDrivenPaginationContinuationTokensImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ServerDrivenPaginationContinuationTokensService service; + + /** + * The service client containing this operation class. + */ + private final PageableClientImpl client; + + /** + * Initializes an instance of ServerDrivenPaginationContinuationTokensImpl. + * + * @param client the instance of the service client containing this operation class. + */ + ServerDrivenPaginationContinuationTokensImpl(PageableClientImpl client) { + this.service = RestProxy.create(ServerDrivenPaginationContinuationTokensService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for PageableClientServerDrivenPaginationContinuationTokens to be used by + * the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "PageableClientServerDrivenPaginationContinuationTokens") + public interface ServerDrivenPaginationContinuationTokensService { + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestQueryResponseBody(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestQueryResponseBodySync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestHeaderResponseBody(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestHeaderResponseBodySync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestQueryResponseHeader(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestQueryResponseHeaderSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestHeaderResponseHeader(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestHeaderResponseHeaderSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-nested-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestQueryNestedResponseBody(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-query-nested-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestQueryNestedResponseBodySync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-nested-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> requestHeaderNestedResponseBody(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/continuationtoken/request-header-nested-response-body") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response requestHeaderNestedResponseBodySync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> requestQueryResponseBodySinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.requestQueryResponseBody(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseBodyAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestQueryResponseBodySinglePageAsync(requestOptions)); + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestQueryResponseBodySinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.requestQueryResponseBodySync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The requestQueryResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseBody(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestQueryResponseBodySinglePage(requestOptions)); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> requestHeaderResponseBodySinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.requestHeaderResponseBody(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseBodyAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestHeaderResponseBodySinglePageAsync(requestOptions)); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestHeaderResponseBodySinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.requestHeaderResponseBodySync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The requestHeaderResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseBody(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestHeaderResponseBodySinglePage(requestOptions)); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> requestQueryResponseHeaderSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.requestQueryResponseHeader(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryResponseHeaderAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestQueryResponseHeaderSinglePageAsync(requestOptions)); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestQueryResponseHeaderSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.requestQueryResponseHeaderSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The requestQueryResponseHeader operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryResponseHeader(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestQueryResponseHeaderSinglePage(requestOptions)); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> requestHeaderResponseHeaderSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.requestHeaderResponseHeader(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null)); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderResponseHeaderAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestHeaderResponseHeaderSinglePageAsync(requestOptions)); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestHeaderResponseHeaderSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.requestHeaderResponseHeaderSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), null, null); + } + + /** + * The requestHeaderResponseHeader operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderResponseHeader(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestHeaderResponseHeaderSinglePage(requestOptions)); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> + requestQueryNestedResponseBodySinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.requestQueryNestedResponseBody(this.client.getEndpoint(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), null, null)); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestQueryNestedResponseBodyAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestQueryNestedResponseBodySinglePageAsync(requestOptions)); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestQueryNestedResponseBodySinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.requestQueryNestedResponseBodySync(this.client.getEndpoint(), accept, + requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), null, null); + } + + /** + * The requestQueryNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestQueryNestedResponseBody(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestQueryNestedResponseBodySinglePage(requestOptions)); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> + requestHeaderNestedResponseBodySinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.requestHeaderNestedResponseBody(this.client.getEndpoint(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), null, null)); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux requestHeaderNestedResponseBodyAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> requestHeaderNestedResponseBodySinglePageAsync(requestOptions)); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse requestHeaderNestedResponseBodySinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.requestHeaderNestedResponseBodySync(this.client.getEndpoint(), accept, + requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), null, null); + } + + /** + * The requestHeaderNestedResponseBody operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
barStringNoThe bar parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
tokenStringNoThe token parameter
fooStringNoThe foo parameter
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable requestHeaderNestedResponseBody(RequestOptions requestOptions) { + return new PagedIterable<>(() -> requestHeaderNestedResponseBodySinglePage(requestOptions)); + } + + private List getValues(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java new file mode 100644 index 00000000000..7555bae0133 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java @@ -0,0 +1,740 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in ServerDrivenPaginations. + */ +public final class ServerDrivenPaginationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ServerDrivenPaginationsService service; + + /** + * The service client containing this operation class. + */ + private final PageableClientImpl client; + + /** + * Initializes an instance of ServerDrivenPaginationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + ServerDrivenPaginationsImpl(PageableClientImpl client) { + this.service = RestProxy.create(ServerDrivenPaginationsService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for PageableClientServerDrivenPaginations to be used by the proxy service + * to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "PageableClientServerDrivenPaginations") + public interface ServerDrivenPaginationsService { + @Get("/payload/pageable/server-driven-pagination/link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> link(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response linkSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/link-string") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> linkString(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/link-string") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response linkStringSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/nested-link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> nestedLink(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/server-driven-pagination/nested-link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response nestedLinkSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> linkNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response linkNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> linkStringNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response linkStringNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> nestedLinkNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response nestedLinkNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> linkSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.link(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux linkAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> linkSinglePageAsync(requestOptions), + nextLink -> linkNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse linkSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.linkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> linkSinglePage(requestOptions), + nextLink -> linkNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> linkStringSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.linkString(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux linkStringAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> linkStringSinglePageAsync(requestOptions), + nextLink -> linkStringNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse linkStringSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.linkStringSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + /** + * The linkString operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable linkString(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> linkStringSinglePage(requestOptions), + nextLink -> linkStringNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> nestedLinkSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.nestedLink(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), getNextLink(res.getValue(), "nestedNext", "next"), + null)); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux nestedLinkAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> nestedLinkSinglePageAsync(requestOptions), + nextLink -> nestedLinkNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse nestedLinkSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.nestedLinkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), getNextLink(res.getValue(), "nestedNext", "next"), null); + } + + /** + * The nestedLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable nestedLink(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> nestedLinkSinglePage(requestOptions), + nextLink -> nestedLinkNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> linkNextSinglePageAsync(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.linkNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse linkNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.linkNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> linkStringNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.linkStringNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse linkStringNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.linkStringNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> nestedLinkNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.nestedLinkNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), getNextLink(res.getValue(), "nestedNext", "next"), + null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse nestedLinkNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.nestedLinkNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "nestedItems", "pets"), getNextLink(res.getValue(), "nestedNext", "next"), null); + } + + private List getValues(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java new file mode 100644 index 00000000000..93f55e06270 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java @@ -0,0 +1,468 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in XmlPaginations. + */ +public final class XmlPaginationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final XmlPaginationsService service; + + /** + * The service client containing this operation class. + */ + private final PageableClientImpl client; + + /** + * Initializes an instance of XmlPaginationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + XmlPaginationsImpl(PageableClientImpl client) { + this.service + = RestProxy.create(XmlPaginationsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for PageableClientXmlPaginations to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "PageableClientXmlPaginations") + public interface XmlPaginationsService { + @Get("/payload/pageable/xml/list-with-continuation") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWithContinuation(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/xml/list-with-continuation") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWithContinuationSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/xml/list-with-next-link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWithNextLink(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/payload/pageable/xml/list-with-next-link") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWithNextLinkSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWithNextLinkNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWithNextLinkNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWithContinuationSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/xml"; + return FluxUtil + .withContext( + context -> service.listWithContinuation(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), null, null)); + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithContinuationAsync(RequestOptions requestOptions) { + return new PagedFlux<>(() -> listWithContinuationSinglePageAsync(requestOptions)); + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWithContinuationSinglePage(RequestOptions requestOptions) { + final String accept = "application/xml"; + Response res + = service.listWithContinuationSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), null, null); + } + + /** + * The listWithContinuation operation. + *

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
markerStringNoThe marker parameter
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithContinuation(RequestOptions requestOptions) { + return new PagedIterable<>(() -> listWithContinuationSinglePage(requestOptions)); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWithNextLinkSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/xml"; + return FluxUtil + .withContext( + context -> service.listWithNextLink(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWithNextLinkAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> listWithNextLinkSinglePageAsync(requestOptions), + nextLink -> listWithNextLinkNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWithNextLinkSinglePage(RequestOptions requestOptions) { + final String accept = "application/xml"; + Response res + = service.listWithNextLinkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null); + } + + /** + * The listWithNextLink operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWithNextLink(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> listWithNextLinkSinglePage(requestOptions), + nextLink -> listWithNextLinkNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWithNextLinkNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/xml"; + return FluxUtil + .withContext(context -> service.listWithNextLinkNext(nextLink, this.client.getEndpoint(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     Id: String (Required)
+     *     Name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the XML response for listing pets with next link along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWithNextLinkNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/xml"; + Response res = service.listWithNextLinkNextSync(nextLink, this.client.getEndpoint(), accept, + requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null); + } + + private List getValues(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String... path) { + try { + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializer.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializer.java new file mode 100644 index 00000000000..52f2fac57d9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializer.java @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import com.azure.xml.XmlReader; +import com.azure.xml.XmlSerializable; +import com.azure.xml.XmlWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UncheckedIOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.concurrent.ConcurrentHashMap; +import javax.xml.stream.XMLStreamException; +import reactor.core.publisher.Mono; + +// DO NOT modify this helper class + +/** + * An {@link ObjectSerializer} implementation that serializes and deserializes {@link XmlSerializable} types using + * {@code azure-xml}. Deserialization relies on the generated static {@code fromXml(XmlReader)} factory method on the + * target type. + */ +public final class XmlSerializer implements ObjectSerializer { + + private static final ConcurrentHashMap, Method> FROM_XML_CACHE = new ConcurrentHashMap<>(); + + @Override + @SuppressWarnings("unchecked") + public T deserialize(InputStream stream, TypeReference typeReference) { + Class clazz = (Class) typeReference.getJavaClass(); + Method fromXml = FROM_XML_CACHE.computeIfAbsent(clazz, c -> { + try { + return c.getDeclaredMethod("fromXml", XmlReader.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException( + "Type " + c.getName() + " does not have a static fromXml(XmlReader) method.", e); + } + }); + try (XmlReader xmlReader = XmlReader.fromStream(stream)) { + return (T) fromXml.invoke(null, xmlReader); + } catch (XMLStreamException | IllegalAccessException e) { + throw new IllegalStateException(e); + } catch (InvocationTargetException e) { + throw new IllegalStateException(e.getCause() == null ? e : e.getCause()); + } + } + + @Override + public Mono deserializeAsync(InputStream stream, TypeReference typeReference) { + return Mono.fromCallable(() -> deserialize(stream, typeReference)); + } + + @Override + public void serialize(OutputStream stream, Object value) { + if (!(value instanceof XmlSerializable)) { + throw new IllegalArgumentException("Value must implement XmlSerializable to be serialized as XML, but was: " + + (value == null ? "null" : value.getClass().getName())); + } + try (XmlWriter xmlWriter = XmlWriter.toStream(stream)) { + xmlWriter.writeStartDocument(); + xmlWriter.writeXml((XmlSerializable) value); + xmlWriter.flush(); + } catch (XMLStreamException e) { + throw new UncheckedIOException(new IOException(e)); + } + } + + @Override + public Mono serializeAsync(OutputStream stream, Object value) { + return Mono.fromRunnable(() -> serialize(stream, value)); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializerProviders.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializerProviders.java new file mode 100644 index 00000000000..e9e903adc2b --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlSerializerProviders.java @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.implementation; + +import com.azure.core.util.serializer.ObjectSerializer; + +// DO NOT modify this helper class + +/** + * This class is a proxy for creating an {@link ObjectSerializer} that serializes and deserializes XML payloads using + * {@code azure-xml}. It mirrors the pattern of {@code JsonSerializerProviders} in {@code azure-core}, but for XML. + */ +public final class XmlSerializerProviders { + + /** + * Creates an instance of an XML {@link ObjectSerializer}. + * + * @return A new instance of an XML {@link ObjectSerializer}. + */ + public static ObjectSerializer createInstance() { + return new XmlSerializer(); + } + + private XmlSerializerProviders() { + // no-op + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/package-info.java new file mode 100644 index 00000000000..21fdeab777b --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the implementations for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable.implementation; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/Pet.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/Pet.java new file mode 100644 index 00000000000..eb1cd346b75 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/Pet.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The Pet model. + */ +@Immutable +public final class Pet implements JsonSerializable { + /* + * The id property. + */ + @Generated + private final String id; + + /* + * The name property. + */ + @Generated + private final String name; + + /** + * Creates an instance of Pet class. + * + * @param id the id value to set. + * @param name the name value to set. + */ + @Generated + private Pet(String id, String name) { + this.id = id; + this.name = name; + } + + /** + * Get the id property: The id property. + * + * @return the id value. + */ + @Generated + public String getId() { + return this.id; + } + + /** + * Get the name property: The name property. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("name", this.name); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of Pet from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of Pet if the JsonReader was pointing to an instance of it, or null if it was pointing to + * JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the Pet. + */ + @Generated + public static Pet fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + String name = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("name".equals(fieldName)) { + name = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new Pet(id, name); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/XmlPet.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/XmlPet.java new file mode 100644 index 00000000000..2bee5369f21 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/XmlPet.java @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.xml.XmlReader; +import com.azure.xml.XmlSerializable; +import com.azure.xml.XmlToken; +import com.azure.xml.XmlWriter; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; + +/** + * An XML pet item. + */ +@Immutable +public final class XmlPet implements XmlSerializable { + /* + * The Id property. + */ + @Generated + private final String id; + + /* + * The Name property. + */ + @Generated + private final String name; + + /** + * Creates an instance of XmlPet class. + * + * @param id the id value to set. + * @param name the name value to set. + */ + @Generated + private XmlPet(String id, String name) { + this.id = id; + this.name = name; + } + + /** + * Get the id property: The Id property. + * + * @return the id value. + */ + @Generated + public String getId() { + return this.id; + } + + /** + * Get the name property: The Name property. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + @Generated + @Override + public XmlWriter toXml(XmlWriter xmlWriter) throws XMLStreamException { + return toXml(xmlWriter, null); + } + + @Generated + @Override + public XmlWriter toXml(XmlWriter xmlWriter, String rootElementName) throws XMLStreamException { + rootElementName = rootElementName == null || rootElementName.isEmpty() ? "Pet" : rootElementName; + xmlWriter.writeStartElement(rootElementName); + xmlWriter.writeStringElement("Id", this.id); + xmlWriter.writeStringElement("Name", this.name); + return xmlWriter.writeEndElement(); + } + + /** + * Reads an instance of XmlPet from the XmlReader. + * + * @param xmlReader The XmlReader being read. + * @return An instance of XmlPet if the XmlReader was pointing to an instance of it, or null if it was pointing to + * XML null. + * @throws IllegalStateException If the deserialized XML object was missing any required properties. + * @throws XMLStreamException If an error occurs while reading the XmlPet. + */ + @Generated + public static XmlPet fromXml(XmlReader xmlReader) throws XMLStreamException { + return fromXml(xmlReader, null); + } + + /** + * Reads an instance of XmlPet from the XmlReader. + * + * @param xmlReader The XmlReader being read. + * @param rootElementName Optional root element name to override the default defined by the model. Used to support + * cases where the model can deserialize from different root element names. + * @return An instance of XmlPet if the XmlReader was pointing to an instance of it, or null if it was pointing to + * XML null. + * @throws IllegalStateException If the deserialized XML object was missing any required properties. + * @throws XMLStreamException If an error occurs while reading the XmlPet. + */ + @Generated + public static XmlPet fromXml(XmlReader xmlReader, String rootElementName) throws XMLStreamException { + String finalRootElementName = rootElementName == null || rootElementName.isEmpty() ? "Pet" : rootElementName; + return xmlReader.readObject(finalRootElementName, reader -> { + String id = null; + String name = null; + while (reader.nextElement() != XmlToken.END_ELEMENT) { + QName elementName = reader.getElementName(); + + if ("Id".equals(elementName.getLocalPart())) { + id = reader.getStringElement(); + } else if ("Name".equals(elementName.getLocalPart())) { + name = reader.getStringElement(); + } else { + reader.skipElement(); + } + } + return new XmlPet(id, name); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/package-info.java new file mode 100644 index 00000000000..c8d9bde6ec5 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/models/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/package-info.java new file mode 100644 index 00000000000..7ca09486544 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the classes for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/Filter.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/Filter.java new file mode 100644 index 00000000000..ff255f5408a --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/Filter.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.alternateinitialverb.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The Filter model. + */ +@Immutable +public final class Filter implements JsonSerializable { + /* + * The filter property. + */ + @Generated + private final String filter; + + /** + * Creates an instance of Filter class. + * + * @param filter the filter value to set. + */ + @Generated + public Filter(String filter) { + this.filter = filter; + } + + /** + * Get the filter property: The filter property. + * + * @return the filter value. + */ + @Generated + public String getFilter() { + return this.filter; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("filter", this.filter); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of Filter from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of Filter if the JsonReader was pointing to an instance of it, or null if it was pointing to + * JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the Filter. + */ + @Generated + public static Filter fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String filter = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("filter".equals(fieldName)) { + filter = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new Filter(filter); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/package-info.java new file mode 100644 index 00000000000..e5f8f79d2fe --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable.serverdrivenpagination.alternateinitialverb.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedItems.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedItems.java new file mode 100644 index 00000000000..aeb1dc35bf7 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedItems.java @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.continuationtoken.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; +import payload.pageable.models.Pet; + +/** + * The RequestHeaderNestedResponseBodyResponseNestedItems model. + */ +@Immutable +public final class RequestHeaderNestedResponseBodyResponseNestedItems + implements JsonSerializable { + /* + * The pets property. + */ + @Generated + private final List pets; + + /** + * Creates an instance of RequestHeaderNestedResponseBodyResponseNestedItems class. + * + * @param pets the pets value to set. + */ + @Generated + private RequestHeaderNestedResponseBodyResponseNestedItems(List pets) { + this.pets = pets; + } + + /** + * Get the pets property: The pets property. + * + * @return the pets value. + */ + @Generated + public List getPets() { + return this.pets; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("pets", this.pets, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of RequestHeaderNestedResponseBodyResponseNestedItems from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of RequestHeaderNestedResponseBodyResponseNestedItems if the JsonReader was pointing to an + * instance of it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the RequestHeaderNestedResponseBodyResponseNestedItems. + */ + @Generated + public static RequestHeaderNestedResponseBodyResponseNestedItems fromJson(JsonReader jsonReader) + throws IOException { + return jsonReader.readObject(reader -> { + List pets = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("pets".equals(fieldName)) { + pets = reader.readArray(reader1 -> Pet.fromJson(reader1)); + } else { + reader.skipChildren(); + } + } + return new RequestHeaderNestedResponseBodyResponseNestedItems(pets); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedNext.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedNext.java new file mode 100644 index 00000000000..92f0972ff12 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedNext.java @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.continuationtoken.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The RequestHeaderNestedResponseBodyResponseNestedNext model. + */ +@Immutable +public final class RequestHeaderNestedResponseBodyResponseNestedNext + implements JsonSerializable { + /* + * The nextToken property. + */ + @Generated + private String nextToken; + + /** + * Creates an instance of RequestHeaderNestedResponseBodyResponseNestedNext class. + */ + @Generated + private RequestHeaderNestedResponseBodyResponseNestedNext() { + } + + /** + * Get the nextToken property: The nextToken property. + * + * @return the nextToken value. + */ + @Generated + public String getNextToken() { + return this.nextToken; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("nextToken", this.nextToken); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of RequestHeaderNestedResponseBodyResponseNestedNext from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of RequestHeaderNestedResponseBodyResponseNestedNext if the JsonReader was pointing to an + * instance of it, or null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the RequestHeaderNestedResponseBodyResponseNestedNext. + */ + @Generated + public static RequestHeaderNestedResponseBodyResponseNestedNext fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + RequestHeaderNestedResponseBodyResponseNestedNext deserializedRequestHeaderNestedResponseBodyResponseNestedNext + = new RequestHeaderNestedResponseBodyResponseNestedNext(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("nextToken".equals(fieldName)) { + deserializedRequestHeaderNestedResponseBodyResponseNestedNext.nextToken = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedRequestHeaderNestedResponseBodyResponseNestedNext; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedItems.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedItems.java new file mode 100644 index 00000000000..312812e2227 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedItems.java @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.continuationtoken.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; +import payload.pageable.models.Pet; + +/** + * The RequestQueryNestedResponseBodyResponseNestedItems model. + */ +@Immutable +public final class RequestQueryNestedResponseBodyResponseNestedItems + implements JsonSerializable { + /* + * The pets property. + */ + @Generated + private final List pets; + + /** + * Creates an instance of RequestQueryNestedResponseBodyResponseNestedItems class. + * + * @param pets the pets value to set. + */ + @Generated + private RequestQueryNestedResponseBodyResponseNestedItems(List pets) { + this.pets = pets; + } + + /** + * Get the pets property: The pets property. + * + * @return the pets value. + */ + @Generated + public List getPets() { + return this.pets; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("pets", this.pets, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of RequestQueryNestedResponseBodyResponseNestedItems from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of RequestQueryNestedResponseBodyResponseNestedItems if the JsonReader was pointing to an + * instance of it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the RequestQueryNestedResponseBodyResponseNestedItems. + */ + @Generated + public static RequestQueryNestedResponseBodyResponseNestedItems fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + List pets = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("pets".equals(fieldName)) { + pets = reader.readArray(reader1 -> Pet.fromJson(reader1)); + } else { + reader.skipChildren(); + } + } + return new RequestQueryNestedResponseBodyResponseNestedItems(pets); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedNext.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedNext.java new file mode 100644 index 00000000000..2172b07f7c6 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedNext.java @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.continuationtoken.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The RequestQueryNestedResponseBodyResponseNestedNext model. + */ +@Immutable +public final class RequestQueryNestedResponseBodyResponseNestedNext + implements JsonSerializable { + /* + * The nextToken property. + */ + @Generated + private String nextToken; + + /** + * Creates an instance of RequestQueryNestedResponseBodyResponseNestedNext class. + */ + @Generated + private RequestQueryNestedResponseBodyResponseNestedNext() { + } + + /** + * Get the nextToken property: The nextToken property. + * + * @return the nextToken value. + */ + @Generated + public String getNextToken() { + return this.nextToken; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("nextToken", this.nextToken); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of RequestQueryNestedResponseBodyResponseNestedNext from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of RequestQueryNestedResponseBodyResponseNestedNext if the JsonReader was pointing to an + * instance of it, or null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the RequestQueryNestedResponseBodyResponseNestedNext. + */ + @Generated + public static RequestQueryNestedResponseBodyResponseNestedNext fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + RequestQueryNestedResponseBodyResponseNestedNext deserializedRequestQueryNestedResponseBodyResponseNestedNext + = new RequestQueryNestedResponseBodyResponseNestedNext(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("nextToken".equals(fieldName)) { + deserializedRequestQueryNestedResponseBodyResponseNestedNext.nextToken = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedRequestQueryNestedResponseBodyResponseNestedNext; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/package-info.java new file mode 100644 index 00000000000..1cb5affecb5 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable.serverdrivenpagination.continuationtoken.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedItems.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedItems.java new file mode 100644 index 00000000000..82f469a6c0f --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedItems.java @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; +import payload.pageable.models.Pet; + +/** + * The NestedLinkResponseNestedItems model. + */ +@Immutable +public final class NestedLinkResponseNestedItems implements JsonSerializable { + /* + * The pets property. + */ + @Generated + private final List pets; + + /** + * Creates an instance of NestedLinkResponseNestedItems class. + * + * @param pets the pets value to set. + */ + @Generated + private NestedLinkResponseNestedItems(List pets) { + this.pets = pets; + } + + /** + * Get the pets property: The pets property. + * + * @return the pets value. + */ + @Generated + public List getPets() { + return this.pets; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("pets", this.pets, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of NestedLinkResponseNestedItems from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of NestedLinkResponseNestedItems if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the NestedLinkResponseNestedItems. + */ + @Generated + public static NestedLinkResponseNestedItems fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + List pets = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("pets".equals(fieldName)) { + pets = reader.readArray(reader1 -> Pet.fromJson(reader1)); + } else { + reader.skipChildren(); + } + } + return new NestedLinkResponseNestedItems(pets); + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedNext.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedNext.java new file mode 100644 index 00000000000..4b15044b92f --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedNext.java @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.serverdrivenpagination.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The NestedLinkResponseNestedNext model. + */ +@Immutable +public final class NestedLinkResponseNestedNext implements JsonSerializable { + /* + * The next property. + */ + @Generated + private String next; + + /** + * Creates an instance of NestedLinkResponseNestedNext class. + */ + @Generated + private NestedLinkResponseNestedNext() { + } + + /** + * Get the next property: The next property. + * + * @return the next value. + */ + @Generated + public String getNext() { + return this.next; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("next", this.next); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of NestedLinkResponseNestedNext from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of NestedLinkResponseNestedNext if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the NestedLinkResponseNestedNext. + */ + @Generated + public static NestedLinkResponseNestedNext fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + NestedLinkResponseNestedNext deserializedNestedLinkResponseNestedNext = new NestedLinkResponseNestedNext(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("next".equals(fieldName)) { + deserializedNestedLinkResponseNestedNext.next = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedNestedLinkResponseNestedNext; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java new file mode 100644 index 00000000000..c88442bcae9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Pageable. + * Test for pageable payload. + * + */ +package payload.pageable.serverdrivenpagination.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/protocolandconvenient/implementation/ProtocolAndConvenienceOpsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/protocolandconvenient/implementation/ProtocolAndConvenienceOpsImpl.java index 419ba51f13c..9f876376b20 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/protocolandconvenient/implementation/ProtocolAndConvenienceOpsImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/protocolandconvenient/implementation/ProtocolAndConvenienceOpsImpl.java @@ -1096,20 +1096,26 @@ private PagedResponse listNextSinglePage(String nextLink, RequestOpt getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/response/implementation/ResponseClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/response/implementation/ResponseClientImpl.java index c29a9b3f8c1..59671de7556 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/response/implementation/ResponseClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/response/implementation/ResponseClientImpl.java @@ -2021,20 +2021,26 @@ private PagedResponse listStringsNextSinglePage(String nextLink, Req getValues(res.getValue(), "items_value"), getNextLink(res.getValue(), "next_link"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/EtagHeadersImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/EtagHeadersImpl.java index 813a1223c10..226695d637e 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/EtagHeadersImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/EtagHeadersImpl.java @@ -594,20 +594,26 @@ private PagedResponse listWithEtagNextSinglePage(String nextLink, Re getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/versioning/implementation/VersioningOpsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/versioning/implementation/VersioningOpsImpl.java index b58cb5ea82b..872525725b9 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/versioning/implementation/VersioningOpsImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/versioning/implementation/VersioningOpsImpl.java @@ -1020,20 +1020,26 @@ private PagedResponse listNextSinglePage(String nextLink, RequestOpt getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); } - private List getValues(BinaryData binaryData, String path) { + private List getValues(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - List values = (List) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + List values = (List) value; return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); } catch (RuntimeException e) { return null; } } - private String getNextLink(BinaryData binaryData, String path) { + private String getNextLink(BinaryData binaryData, String... path) { try { - Map obj = binaryData.toObject(Map.class); - return (String) obj.get(path); + Object value = binaryData.toObject(Map.class); + for (String segment : path) { + value = ((Map) value).get(segment); + } + return (String) value; } catch (RuntimeException e) { return null; } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/payload-pageable_metadata.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/payload-pageable_metadata.json new file mode 100644 index 00000000000..c64171444f2 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/payload-pageable_metadata.json @@ -0,0 +1 @@ +{"flavor":"Azure","apiVersions":{},"crossLanguagePackageId":"Payload.Pageable","crossLanguageVersion":"5bc41881d9e9","crossLanguageDefinitions":{"payload.pageable.PageSizeAsyncClient":"Payload.Pageable.PageSize","payload.pageable.PageSizeAsyncClient.listWithPageSize":"Payload.Pageable.PageSize.listWithPageSize","payload.pageable.PageSizeAsyncClient.listWithoutContinuation":"Payload.Pageable.PageSize.listWithoutContinuation","payload.pageable.PageSizeClient":"Payload.Pageable.PageSize","payload.pageable.PageSizeClient.listWithPageSize":"Payload.Pageable.PageSize.listWithPageSize","payload.pageable.PageSizeClient.listWithoutContinuation":"Payload.Pageable.PageSize.listWithoutContinuation","payload.pageable.PageableClientBuilder":"Payload.Pageable","payload.pageable.ServerDrivenPaginationAlternateInitialVerbAsyncClient":"Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb","payload.pageable.ServerDrivenPaginationAlternateInitialVerbAsyncClient.post":"Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb.post","payload.pageable.ServerDrivenPaginationAlternateInitialVerbClient":"Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb","payload.pageable.ServerDrivenPaginationAlternateInitialVerbClient.post":"Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb.post","payload.pageable.ServerDrivenPaginationAsyncClient":"Payload.Pageable.ServerDrivenPagination","payload.pageable.ServerDrivenPaginationAsyncClient.link":"Payload.Pageable.ServerDrivenPagination.link","payload.pageable.ServerDrivenPaginationAsyncClient.linkString":"Payload.Pageable.ServerDrivenPagination.linkString","payload.pageable.ServerDrivenPaginationAsyncClient.nestedLink":"Payload.Pageable.ServerDrivenPagination.nestedLink","payload.pageable.ServerDrivenPaginationClient":"Payload.Pageable.ServerDrivenPagination","payload.pageable.ServerDrivenPaginationClient.link":"Payload.Pageable.ServerDrivenPagination.link","payload.pageable.ServerDrivenPaginationClient.linkString":"Payload.Pageable.ServerDrivenPagination.linkString","payload.pageable.ServerDrivenPaginationClient.nestedLink":"Payload.Pageable.ServerDrivenPagination.nestedLink","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient":"Payload.Pageable.ServerDrivenPagination.ContinuationToken","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestHeaderNestedResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderNestedResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestHeaderResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestHeaderResponseHeader":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderResponseHeader","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestQueryNestedResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryNestedResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestQueryResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenAsyncClient.requestQueryResponseHeader":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryResponseHeader","payload.pageable.ServerDrivenPaginationContinuationTokenClient":"Payload.Pageable.ServerDrivenPagination.ContinuationToken","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestHeaderNestedResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderNestedResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestHeaderResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestHeaderResponseHeader":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderResponseHeader","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestQueryNestedResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryNestedResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestQueryResponseBody":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryResponseBody","payload.pageable.ServerDrivenPaginationContinuationTokenClient.requestQueryResponseHeader":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryResponseHeader","payload.pageable.XmlPaginationAsyncClient":"Payload.Pageable.XmlPagination","payload.pageable.XmlPaginationAsyncClient.listWithContinuation":"Payload.Pageable.XmlPagination.listWithContinuation","payload.pageable.XmlPaginationAsyncClient.listWithNextLink":"Payload.Pageable.XmlPagination.listWithNextLink","payload.pageable.XmlPaginationClient":"Payload.Pageable.XmlPagination","payload.pageable.XmlPaginationClient.listWithContinuation":"Payload.Pageable.XmlPagination.listWithContinuation","payload.pageable.XmlPaginationClient.listWithNextLink":"Payload.Pageable.XmlPagination.listWithNextLink","payload.pageable.models.Pet":"Payload.Pageable.Pet","payload.pageable.models.XmlPet":"Payload.Pageable.XmlPet","payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter":"Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb.Filter","payload.pageable.serverdrivenpagination.continuationtoken.models.RequestHeaderNestedResponseBodyResponseNestedItems":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderNestedResponseBody.Response.nestedItems.anonymous","payload.pageable.serverdrivenpagination.continuationtoken.models.RequestHeaderNestedResponseBodyResponseNestedNext":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestHeaderNestedResponseBody.Response.nestedNext.anonymous","payload.pageable.serverdrivenpagination.continuationtoken.models.RequestQueryNestedResponseBodyResponseNestedItems":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryNestedResponseBody.Response.nestedItems.anonymous","payload.pageable.serverdrivenpagination.continuationtoken.models.RequestQueryNestedResponseBodyResponseNestedNext":"Payload.Pageable.ServerDrivenPagination.ContinuationToken.requestQueryNestedResponseBody.Response.nestedNext.anonymous","payload.pageable.serverdrivenpagination.models.NestedLinkResponseNestedItems":"Payload.Pageable.ServerDrivenPagination.nestedLink.Response.nestedItems.anonymous","payload.pageable.serverdrivenpagination.models.NestedLinkResponseNestedNext":"Payload.Pageable.ServerDrivenPagination.nestedLink.Response.nestedNext.anonymous"},"generatedFiles":["src/main/java/module-info.java","src/main/java/payload/pageable/PageSizeAsyncClient.java","src/main/java/payload/pageable/PageSizeClient.java","src/main/java/payload/pageable/PageableClientBuilder.java","src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbAsyncClient.java","src/main/java/payload/pageable/ServerDrivenPaginationAlternateInitialVerbClient.java","src/main/java/payload/pageable/ServerDrivenPaginationAsyncClient.java","src/main/java/payload/pageable/ServerDrivenPaginationClient.java","src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenAsyncClient.java","src/main/java/payload/pageable/ServerDrivenPaginationContinuationTokenClient.java","src/main/java/payload/pageable/XmlPaginationAsyncClient.java","src/main/java/payload/pageable/XmlPaginationClient.java","src/main/java/payload/pageable/implementation/PageSizesImpl.java","src/main/java/payload/pageable/implementation/PageableClientImpl.java","src/main/java/payload/pageable/implementation/ServerDrivenPaginationAlternateInitialVerbsImpl.java","src/main/java/payload/pageable/implementation/ServerDrivenPaginationContinuationTokensImpl.java","src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java","src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java","src/main/java/payload/pageable/implementation/XmlSerializer.java","src/main/java/payload/pageable/implementation/XmlSerializerProviders.java","src/main/java/payload/pageable/implementation/package-info.java","src/main/java/payload/pageable/models/Pet.java","src/main/java/payload/pageable/models/XmlPet.java","src/main/java/payload/pageable/models/package-info.java","src/main/java/payload/pageable/package-info.java","src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/Filter.java","src/main/java/payload/pageable/serverdrivenpagination/alternateinitialverb/models/package-info.java","src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedItems.java","src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestHeaderNestedResponseBodyResponseNestedNext.java","src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedItems.java","src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/RequestQueryNestedResponseBodyResponseNestedNext.java","src/main/java/payload/pageable/serverdrivenpagination/continuationtoken/models/package-info.java","src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedItems.java","src/main/java/payload/pageable/serverdrivenpagination/models/NestedLinkResponseNestedNext.java","src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java"]} \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-responseheaders_metadata.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-responseheaders_metadata.json index 73eba439a91..29df0fc1029 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-responseheaders_metadata.json +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-responseheaders_metadata.json @@ -1 +1 @@ -{"flavor":"Azure","apiVersions":{},"crossLanguagePackageId":"TspTest.ResponseHeaders","crossLanguageVersion":"6bf244cf0c6b","crossLanguageDefinitions":{"tsptest.responseheaders.ResponseHeadersAsyncClient":"TspTest.ResponseHeaders.ResponseHeaderOp","tsptest.responseheaders.ResponseHeadersAsyncClient.getResourceMetadata":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersAsyncClient.getResourceMetadataWithResponse":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClient":"TspTest.ResponseHeaders.ResponseHeaderOp","tsptest.responseheaders.ResponseHeadersClient.getResourceMetadata":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClient.getResourceMetadataWithResponse":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClientBuilder":"TspTest.ResponseHeaders","tsptest.responseheaders.models.ResponseHeaderOpsGetResourceMetadataHeaders":null},"generatedFiles":["src/main/java/module-info.java","src/main/java/tsptest/responseheaders/ResponseHeadersAsyncClient.java","src/main/java/tsptest/responseheaders/ResponseHeadersClient.java","src/main/java/tsptest/responseheaders/ResponseHeadersClientBuilder.java","src/main/java/tsptest/responseheaders/implementation/ResponseHeaderOpsImpl.java","src/main/java/tsptest/responseheaders/implementation/ResponseHeadersClientImpl.java","src/main/java/tsptest/responseheaders/implementation/package-info.java","src/main/java/tsptest/responseheaders/models/ResponseHeaderOpsGetResourceMetadataHeaders.java","src/main/java/tsptest/responseheaders/models/package-info.java","src/main/java/tsptest/responseheaders/package-info.java"]} \ No newline at end of file +{"flavor":"Azure","apiVersions":{},"crossLanguagePackageId":"TspTest.ResponseHeaders","crossLanguageVersion":"ceced49cc835","crossLanguageDefinitions":{"tsptest.responseheaders.ResponseHeadersAsyncClient":"TspTest.ResponseHeaders.ResponseHeaderOp","tsptest.responseheaders.ResponseHeadersAsyncClient.getResourceMetadata":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersAsyncClient.getResourceMetadataWithResponse":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClient":"TspTest.ResponseHeaders.ResponseHeaderOp","tsptest.responseheaders.ResponseHeadersClient.getResourceMetadata":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClient.getResourceMetadataWithResponse":"TspTest.ResponseHeaders.ResponseHeaderOp.getResourceMetadata","tsptest.responseheaders.ResponseHeadersClientBuilder":"TspTest.ResponseHeaders","tsptest.responseheaders.models.ResponseHeaderOpsGetResourceMetadataHeaders":null},"generatedFiles":["src/main/java/module-info.java","src/main/java/tsptest/responseheaders/ResponseHeadersAsyncClient.java","src/main/java/tsptest/responseheaders/ResponseHeadersClient.java","src/main/java/tsptest/responseheaders/ResponseHeadersClientBuilder.java","src/main/java/tsptest/responseheaders/implementation/ResponseHeaderOpsImpl.java","src/main/java/tsptest/responseheaders/implementation/ResponseHeadersClientImpl.java","src/main/java/tsptest/responseheaders/implementation/package-info.java","src/main/java/tsptest/responseheaders/models/ResponseHeaderOpsGetResourceMetadataHeaders.java","src/main/java/tsptest/responseheaders/models/package-info.java","src/main/java/tsptest/responseheaders/package-info.java"]} \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-xmlbytesverify_metadata.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-xmlbytesverify_metadata.json index 4f28e86a159..d0d81784425 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-xmlbytesverify_metadata.json +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/tsptest-xmlbytesverify_metadata.json @@ -1 +1 @@ -{"flavor":"Azure","apiVersions":{},"crossLanguagePackageId":"TspTest.XmlBytesVerify","crossLanguageVersion":"cac435f1a85f","crossLanguageDefinitions":{"tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient":"TspTest.XmlBytesVerify","tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient.getWmtsCapabilities":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient.getWmtsCapabilitiesWithResponse":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClient":"TspTest.XmlBytesVerify","tsptest.xmlbytesverify.XmlBytesVerifyClient.getWmtsCapabilities":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClient.getWmtsCapabilitiesWithResponse":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClientBuilder":"TspTest.XmlBytesVerify"},"generatedFiles":["src/main/java/module-info.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyAsyncClient.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyClient.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyClientBuilder.java","src/main/java/tsptest/xmlbytesverify/implementation/XmlBytesVerifyClientImpl.java","src/main/java/tsptest/xmlbytesverify/implementation/package-info.java","src/main/java/tsptest/xmlbytesverify/package-info.java"]} \ No newline at end of file +{"flavor":"Azure","apiVersions":{},"crossLanguagePackageId":"TspTest.XmlBytesVerify","crossLanguageVersion":"4b7802441e11","crossLanguageDefinitions":{"tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient":"TspTest.XmlBytesVerify","tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient.getWmtsCapabilities":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyAsyncClient.getWmtsCapabilitiesWithResponse":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClient":"TspTest.XmlBytesVerify","tsptest.xmlbytesverify.XmlBytesVerifyClient.getWmtsCapabilities":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClient.getWmtsCapabilitiesWithResponse":"TspTest.XmlBytesVerify.getWmtsCapabilities","tsptest.xmlbytesverify.XmlBytesVerifyClientBuilder":"TspTest.XmlBytesVerify"},"generatedFiles":["src/main/java/module-info.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyAsyncClient.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyClient.java","src/main/java/tsptest/xmlbytesverify/XmlBytesVerifyClientBuilder.java","src/main/java/tsptest/xmlbytesverify/implementation/XmlBytesVerifyClientImpl.java","src/main/java/tsptest/xmlbytesverify/implementation/package-info.java","src/main/java/tsptest/xmlbytesverify/package-info.java"]} \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/payload-pageable.properties b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/payload-pageable.properties new file mode 100644 index 00000000000..ca812989b4f --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/payload-pageable.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/generated/PageableClientTestBase.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/generated/PageableClientTestBase.java new file mode 100644 index 00000000000..6d0c8867d5c --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/generated/PageableClientTestBase.java @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package payload.pageable.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.util.Configuration; +import payload.pageable.PageSizeClient; +import payload.pageable.PageableClientBuilder; +import payload.pageable.ServerDrivenPaginationAlternateInitialVerbClient; +import payload.pageable.ServerDrivenPaginationClient; +import payload.pageable.ServerDrivenPaginationContinuationTokenClient; +import payload.pageable.XmlPaginationClient; + +class PageableClientTestBase extends TestProxyTestBase { + protected ServerDrivenPaginationClient serverDrivenPaginationClient; + + protected ServerDrivenPaginationAlternateInitialVerbClient serverDrivenPaginationAlternateInitialVerbClient; + + protected ServerDrivenPaginationContinuationTokenClient serverDrivenPaginationContinuationTokenClient; + + protected PageSizeClient pageSizeClient; + + protected XmlPaginationClient xmlPaginationClient; + + @Override + protected void beforeTest() { + PageableClientBuilder serverDrivenPaginationClientbuilder = new PageableClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + serverDrivenPaginationClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + serverDrivenPaginationClient = serverDrivenPaginationClientbuilder.buildServerDrivenPaginationClient(); + + PageableClientBuilder serverDrivenPaginationAlternateInitialVerbClientbuilder = new PageableClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + serverDrivenPaginationAlternateInitialVerbClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + serverDrivenPaginationAlternateInitialVerbClient = serverDrivenPaginationAlternateInitialVerbClientbuilder + .buildServerDrivenPaginationAlternateInitialVerbClient(); + + PageableClientBuilder serverDrivenPaginationContinuationTokenClientbuilder = new PageableClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + serverDrivenPaginationContinuationTokenClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + serverDrivenPaginationContinuationTokenClient + = serverDrivenPaginationContinuationTokenClientbuilder.buildServerDrivenPaginationContinuationTokenClient(); + + PageableClientBuilder pageSizeClientbuilder = new PageableClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + pageSizeClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + pageSizeClient = pageSizeClientbuilder.buildPageSizeClient(); + + PageableClientBuilder xmlPaginationClientbuilder = new PageableClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + xmlPaginationClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + xmlPaginationClient = xmlPaginationClientbuilder.buildXmlPaginationClient(); + + } +} From 6fb0662af0e35b79aa5a02a2d473eca9f9697b31 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 13:26:32 +0800 Subject: [PATCH 6/7] fix(java): support XML pageable responses Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../http-client-java.instructions.md | 1 + .../core/template/ClientMethodTemplate.java | 58 +++++++++- .../generator/core/util/TemplateUtil.java | 73 +++++++++++++ .../implementation/XmlPaginationsImpl.java | 103 +++++++++++++++++- .../java/payload/pageable/PageableTests.java | 13 ++- 5 files changed, 236 insertions(+), 12 deletions(-) diff --git a/.github/instructions/http-client-java.instructions.md b/.github/instructions/http-client-java.instructions.md index b0c2ea10d4d..98d1338a792 100644 --- a/.github/instructions/http-client-java.instructions.md +++ b/.github/instructions/http-client-java.instructions.md @@ -79,6 +79,7 @@ After a compile, inspect `tsp-output/**/code-model.yaml` in the test module to s 6. Regenerate by compiling a spec. Do NOT hardcode the TypeSpec file name — it varies per feature, and sometimes you must author a new `/main.tsp` first. The test module's `tspconfig.yaml` already configures the emitter and its output dir, so a plain compile is enough; output goes to `tsp-output/`: `npx tsp compile ` (Optionally add `--option "@typespec/http-client-java.emitter-output-dir=$PWD/tsp-output/"` to isolate output into a subfolder for an easier diff.) + Do NOT run `Generate.ps1` to test one spec. It regenerates every test client, deletes and rebuilds generated source directories, and is reserved for intentional full regeneration (such as a test-spec dependency update). 7. Verify the generated code under `tsp-output/**/src` is as expected. When the spec corresponds to sources tracked in `src/main/java`, compare against them and, if correct, copy the generated files into `src` (replacing existing files) but EXCLUDE `module-info.java`. Some specs do not map to `src` — in that case just verify the output, without comparing or copying. 8. When the spec maps to `src` and you copied the generated code in, run the tests (`mvn test`, or a targeted `--define "test=."`). Restart the Spector server if needed (`npm run spector-stop` then `npm run spector-start`). If the spec does not map to `src`, verifying the generated output (step 7) is sufficient. 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 b31b92e007c..495ed89b948 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 @@ -58,6 +58,46 @@ public class ClientMethodTemplate extends ClientMethodTemplateBase { protected ClientMethodTemplate() { } + private static boolean isXmlPagingResponse(ClientMethod clientMethod) { + return clientMethod.getProxyMethod().getRawResponseBodyType().isUsedInXml(); + } + + private static String xmlPageItemsExpression(ClientMethod clientMethod) { + ModelPropertySegment pageItemsSegment = clientMethod.getMethodPageDetails() + .getPageItemsPropertyReference() + .get(clientMethod.getMethodPageDetails().getPageItemsPropertyReference().size() - 1); + IType pageItemsType = pageItemsSegment.getProperty().getClientType(); + if (!(pageItemsType instanceof GenericType)) { + throw new IllegalStateException("XML pageable items must be a list of generated models."); + } + IType[] typeArguments = ((GenericType) pageItemsType).getTypeArguments(); + if (typeArguments.length != 1 || !(typeArguments[0] instanceof ClassType)) { + throw new IllegalStateException("XML pageable items must be a list of generated models."); + } + + ClassType itemType = (ClassType) typeArguments[0]; + String itemElementName = pageItemsSegment.getProperty().getXmlListElementName(); + if (itemElementName == null || itemElementName.isEmpty()) { + throw new IllegalStateException("XML pageable item element name is required."); + } + + return "getXmlValues(res.getValue(), reader -> { try { return BinaryData.fromObject(" + itemType.getFullName() + + ".fromXml(reader, " + ClassType.STRING.defaultValueExpression(itemElementName) + + "), XML_SERIALIZER); } catch (javax.xml.stream.XMLStreamException e) { throw new IllegalStateException(e); } }, " + + xmlPropertyPath(clientMethod.getMethodPageDetails().getPageItemsPropertyReference(), itemElementName) + + ")"; + } + + private static String xmlPropertyPath(List propertyReference) { + return propertyReference.stream() + .map(segment -> ClassType.STRING.defaultValueExpression(segment.getProperty().getXmlName())) + .collect(Collectors.joining(", ")); + } + + private static String xmlPropertyPath(List propertyReference, String itemElementName) { + return xmlPropertyPath(propertyReference) + ", " + ClassType.STRING.defaultValueExpression(itemElementName); + } + private static String serializedPropertyPath(List propertyReference) { return propertyReference.stream() .map(segment -> ClassType.STRING.defaultValueExpression(segment.getProperty().getSerializedName())) @@ -991,7 +1031,9 @@ protected void pagedSinglePageResponseConversion(ProxyMethod restAPIMethod, Clie function.line("res.getRequest(),"); function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); - if (settings.isDataPlaneClient()) { + if (isXmlPagingResponse(clientMethod)) { + function.line("%s,", xmlPageItemsExpression(clientMethod)); + } else if (settings.isDataPlaneClient()) { function.line("getValues(res.getValue(), %s),", serializedPropertyPath(clientMethod.getMethodPageDetails().getPageItemsPropertyReference())); } else { @@ -999,7 +1041,10 @@ protected void pagedSinglePageResponseConversion(ProxyMethod restAPIMethod, Clie CodeNamer.getModelNamer().modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { - if (settings.isDataPlaneClient()) { + if (isXmlPagingResponse(clientMethod)) { + function.line("getXmlNextLink(res.getValue(), %s),", + xmlPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); + } else if (settings.isDataPlaneClient()) { function.line("getNextLink(res.getValue(), %s),", serializedPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else { @@ -1454,7 +1499,9 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType function.line("res.getRequest(),"); function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); - if (settings.isDataPlaneClient() && settings.isAzureV1()) { + if (isXmlPagingResponse(clientMethod)) { + function.line("%s,", xmlPageItemsExpression(clientMethod)); + } else if (settings.isDataPlaneClient() && settings.isAzureV1()) { function.line("getValues(res.getValue(), %s),", serializedPropertyPath( clientMethod.getMethodPageDetails().getPageItemsPropertyReference())); } else { @@ -1462,7 +1509,10 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { - if (settings.isDataPlaneClient() && settings.isAzureV1()) { + if (isXmlPagingResponse(clientMethod)) { + function.line("getXmlNextLink(res.getValue(), %s),", + xmlPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); + } else if (settings.isDataPlaneClient() && settings.isAzureV1()) { function.line("getNextLink(res.getValue(), %s),", serializedPropertyPath( clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else { diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java index bf3cbfd1987..93d77a9479f 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java @@ -165,6 +165,9 @@ public static void writeClientMethodsAndHelpers(JavaClass classBlock, List m.getMethodPageDetails() != null)) { writePagingHelperMethods(classBlock); + if (clientMethods.stream().anyMatch(TemplateUtil::isXmlPagingMethod)) { + writeXmlPagingHelperMethods(classBlock); + } } } @@ -267,6 +270,76 @@ private static void writePagingHelperMethods(JavaClass classBlock) { }); } + private static boolean isXmlPagingMethod(ClientMethod clientMethod) { + return clientMethod.getMethodPageDetails() != null + && clientMethod.getProxyMethod().getRawResponseBodyType().isUsedInXml(); + } + + private static void writeXmlPagingHelperMethods(JavaClass classBlock) { + classBlock.privateStaticFinalVariable( + "com.azure.core.util.serializer.ObjectSerializer XML_SERIALIZER = XmlSerializerProviders.createInstance()"); + classBlock.privateMethod( + "List getXmlValues(BinaryData binaryData, " + + "java.util.function.Function valueReader, String... path)", + block -> { + block.line( + "try (com.azure.xml.XmlReader reader = com.azure.xml.XmlReader.fromStream(binaryData.toStream())) {"); + block.indent(() -> { + block.line("reader.nextElement();"); + block.line("return getXmlValues(reader, valueReader, path, 0);"); + }); + block.line("} catch (javax.xml.stream.XMLStreamException e) {"); + block.indent( + () -> block.line("throw new IllegalStateException(\"Failed to read XML pageable response.\", e);")); + block.line("}"); + }); + classBlock.privateMethod("List getXmlValues(com.azure.xml.XmlReader reader, " + + "java.util.function.Function valueReader, String[] path, " + + "int pathIndex) throws javax.xml.stream.XMLStreamException", block -> { + block.line("List values = new java.util.ArrayList<>();"); + block.line("while (reader.nextElement() != com.azure.xml.XmlToken.END_ELEMENT) {"); + block.indent(() -> { + block.line("if (!reader.elementNameMatches(path[pathIndex])) {"); + block.indent(() -> block.line("reader.skipElement();")); + block.line("} else if (pathIndex == path.length - 1) {"); + block.indent(() -> block.line("values.add(valueReader.apply(reader));")); + block.line("} else {"); + block.indent( + () -> block.line("values.addAll(getXmlValues(reader, valueReader, path, pathIndex + 1));")); + block.line("}"); + }); + block.line("}"); + block.line("return values;"); + }); + classBlock.privateMethod("String getXmlNextLink(BinaryData binaryData, String... path)", block -> { + block.line( + "try (com.azure.xml.XmlReader reader = com.azure.xml.XmlReader.fromStream(binaryData.toStream())) {"); + block.indent(() -> { + block.line("reader.nextElement();"); + block.line("return getXmlNextLink(reader, path, 0);"); + }); + block.line("} catch (javax.xml.stream.XMLStreamException e) {"); + block.indent( + () -> block.line("throw new IllegalStateException(\"Failed to read XML pageable response.\", e);")); + block.line("}"); + }); + classBlock.privateMethod("String getXmlNextLink(com.azure.xml.XmlReader reader, String[] path, int pathIndex) " + + "throws javax.xml.stream.XMLStreamException", block -> { + block.line("while (reader.nextElement() != com.azure.xml.XmlToken.END_ELEMENT) {"); + block.indent(() -> { + block.line("if (!reader.elementNameMatches(path[pathIndex])) {"); + block.indent(() -> block.line("reader.skipElement();")); + block.line("} else if (pathIndex == path.length - 1) {"); + block.indent(() -> block.line("return reader.getStringElement();")); + block.line("} else {"); + block.indent(() -> block.line("return getXmlNextLink(reader, path, pathIndex + 1);")); + block.line("}"); + }); + block.line("}"); + block.line("return null;"); + }); + } + /** * Writes corresponding "ServiceMethod" annotation for client method. * diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java index 93f55e06270..8986bca9518 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/payload/pageable/implementation/XmlPaginationsImpl.java @@ -157,7 +157,14 @@ private Mono> listWithContinuationSinglePageAsync(Requ .withContext( context -> service.listWithContinuation(this.client.getEndpoint(), accept, requestOptions, context)) .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), null, null)); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), + XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), null, null)); } /** @@ -225,7 +232,13 @@ private PagedResponse listWithContinuationSinglePage(RequestOptions Response res = service.listWithContinuationSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), null, null); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), null, null); } /** @@ -288,7 +301,14 @@ private Mono> listWithNextLinkSinglePageAsync(RequestO .withContext( context -> service.listWithNextLink(this.client.getEndpoint(), accept, requestOptions, context)) .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null)); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), + XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), getXmlNextLink(res.getValue(), "NextLink"), null)); } /** @@ -346,7 +366,13 @@ private PagedResponse listWithNextLinkSinglePage(RequestOptions requ Response res = service.listWithNextLinkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), getXmlNextLink(res.getValue(), "NextLink"), null); } /** @@ -408,7 +434,14 @@ private Mono> listWithNextLinkNextSinglePageAsync(Stri .withContext(context -> service.listWithNextLinkNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null)); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), + XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), getXmlNextLink(res.getValue(), "NextLink"), null)); } /** @@ -438,7 +471,13 @@ private PagedResponse listWithNextLinkNextSinglePage(String nextLink Response res = service.listWithNextLinkNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "Pets"), getNextLink(res.getValue(), "NextLink"), null); + getXmlValues(res.getValue(), reader -> { + try { + return BinaryData.fromObject(payload.pageable.models.XmlPet.fromXml(reader, "Pet"), XML_SERIALIZER); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException(e); + } + }, "Pets", "Pet"), getXmlNextLink(res.getValue(), "NextLink"), null); } private List getValues(BinaryData binaryData, String... path) { @@ -465,4 +504,56 @@ private String getNextLink(BinaryData binaryData, String... path) { return null; } } + + private static final com.azure.core.util.serializer.ObjectSerializer XML_SERIALIZER + = XmlSerializerProviders.createInstance(); + + private List getXmlValues(BinaryData binaryData, + java.util.function.Function valueReader, String... path) { + try (com.azure.xml.XmlReader reader = com.azure.xml.XmlReader.fromStream(binaryData.toStream())) { + reader.nextElement(); + return getXmlValues(reader, valueReader, path, 0); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException("Failed to read XML pageable response.", e); + } + } + + private List getXmlValues(com.azure.xml.XmlReader reader, + java.util.function.Function valueReader, String[] path, int pathIndex) + throws javax.xml.stream.XMLStreamException { + List values = new java.util.ArrayList<>(); + while (reader.nextElement() != com.azure.xml.XmlToken.END_ELEMENT) { + if (!reader.elementNameMatches(path[pathIndex])) { + reader.skipElement(); + } else if (pathIndex == path.length - 1) { + values.add(valueReader.apply(reader)); + } else { + values.addAll(getXmlValues(reader, valueReader, path, pathIndex + 1)); + } + } + return values; + } + + private String getXmlNextLink(BinaryData binaryData, String... path) { + try (com.azure.xml.XmlReader reader = com.azure.xml.XmlReader.fromStream(binaryData.toStream())) { + reader.nextElement(); + return getXmlNextLink(reader, path, 0); + } catch (javax.xml.stream.XMLStreamException e) { + throw new IllegalStateException("Failed to read XML pageable response.", e); + } + } + + private String getXmlNextLink(com.azure.xml.XmlReader reader, String[] path, int pathIndex) + throws javax.xml.stream.XMLStreamException { + while (reader.nextElement() != com.azure.xml.XmlToken.END_ELEMENT) { + if (!reader.elementNameMatches(path[pathIndex])) { + reader.skipElement(); + } else if (pathIndex == path.length - 1) { + return reader.getStringElement(); + } else { + return getXmlNextLink(reader, path, pathIndex + 1); + } + } + return null; + } } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java index f883a8752aa..10fa38a72db 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/payload/pageable/PageableTests.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import payload.pageable.models.Pet; +import payload.pageable.models.XmlPet; import payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter; public class PageableTests { @@ -45,12 +46,20 @@ public void testPost() { assertPetIds(builder.buildServerDrivenPaginationAlternateInitialVerbClient().post(new Filter("foo eq bar"))); } + @Test + public void testXmlListWithNextLink() { + PagedIterable pagedIterable = builder.buildXmlPaginationClient().listWithNextLink(); + + Assertions.assertEquals(List.of("1", "2", "3", "4"), + pagedIterable.stream().map(XmlPet::getId).collect(Collectors.toList())); + } + /* * Continuation-token scenarios are intentionally not covered here. Azure V1 currently emits a single-page * PagedIterable for them because it does not propagate a response continuation token into the next request. * - * XML paging is also intentionally not covered. Azure V1 extracts page data from BinaryData as JSON, so XML - * pageable responses cannot be read. + * XML continuation-token paging is also intentionally not covered because it has the same token propagation + * limitation. */ private static void assertPetIds(PagedIterable pagedIterable) { From 4e7300671232fa8c05d0586639fb8cfb234744a2 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 31 Jul 2026 13:30:04 +0800 Subject: [PATCH 7/7] fix(java): scope XML paging to data-plane Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec1bc35f-8c6e-40bc-8824-a04c25a42530 --- .../core/template/ClientMethodTemplate.java | 14 ++++++++------ 1 file changed, 8 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 495ed89b948..b4358d23a71 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 @@ -58,8 +58,10 @@ public class ClientMethodTemplate extends ClientMethodTemplateBase { protected ClientMethodTemplate() { } - private static boolean isXmlPagingResponse(ClientMethod clientMethod) { - return clientMethod.getProxyMethod().getRawResponseBodyType().isUsedInXml(); + private static boolean isXmlPagingResponse(ClientMethod clientMethod, JavaSettings settings) { + return settings.isDataPlaneClient() + && settings.isAzureV1() + && clientMethod.getProxyMethod().getRawResponseBodyType().isUsedInXml(); } private static String xmlPageItemsExpression(ClientMethod clientMethod) { @@ -1031,7 +1033,7 @@ protected void pagedSinglePageResponseConversion(ProxyMethod restAPIMethod, Clie function.line("res.getRequest(),"); function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); - if (isXmlPagingResponse(clientMethod)) { + if (isXmlPagingResponse(clientMethod, settings)) { function.line("%s,", xmlPageItemsExpression(clientMethod)); } else if (settings.isDataPlaneClient()) { function.line("getValues(res.getValue(), %s),", @@ -1041,7 +1043,7 @@ protected void pagedSinglePageResponseConversion(ProxyMethod restAPIMethod, Clie CodeNamer.getModelNamer().modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { - if (isXmlPagingResponse(clientMethod)) { + if (isXmlPagingResponse(clientMethod, settings)) { function.line("getXmlNextLink(res.getValue(), %s),", xmlPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else if (settings.isDataPlaneClient()) { @@ -1499,7 +1501,7 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType function.line("res.getRequest(),"); function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); - if (isXmlPagingResponse(clientMethod)) { + if (isXmlPagingResponse(clientMethod, settings)) { function.line("%s,", xmlPageItemsExpression(clientMethod)); } else if (settings.isDataPlaneClient() && settings.isAzureV1()) { function.line("getValues(res.getValue(), %s),", serializedPropertyPath( @@ -1509,7 +1511,7 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { - if (isXmlPagingResponse(clientMethod)) { + if (isXmlPagingResponse(clientMethod, settings)) { function.line("getXmlNextLink(res.getValue(), %s),", xmlPropertyPath(clientMethod.getMethodPageDetails().getNextLinkPropertyReference())); } else if (settings.isDataPlaneClient() && settings.isAzureV1()) {