diff --git a/package-lock.json b/package-lock.json index 2bbdb313d6ac..9f029cd5232f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,6 +85,11 @@ "tslib": "^1.9.3" } }, + "@azure/core-asynciterator-polyfill": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.0.tgz", + "integrity": "sha512-kmv8CGrPfN9SwMwrkiBK9VTQYxdFQEGe0BmQk+M8io56P9KNzpAxcWE/1fxJj7uouwN4kXF0BHW8DNlgx+wtCg==" + }, "@azure/core-auth": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.0.2.tgz", @@ -140,6 +145,14 @@ } } }, + "@azure/core-paging": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@azure/core-paging/-/core-paging-1.0.0.tgz", + "integrity": "sha512-CzaT7LwxU97PZ+/Pn7uAbNGXY2mJ/3b56kmLsZzbR9stfrNfzlILxR94WHG/D1jZEQOk4lUNiaqJ2zP7nSGJhA==", + "requires": { + "@azure/core-asynciterator-polyfill": "^1.0.0" + } + }, "@azure/core-tracing": { "version": "1.0.0-preview.7", "resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.0.0-preview.7.tgz", diff --git a/package.json b/package.json index 5132a40c558d..8318207d2591 100755 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ "unit-test": "mocha -r ts-node/register './test/unit/**/*spec.ts'", "integration-test": "start-server-and-test start-test-server:v1 http://localhost:3000 generate-and-test", "integration-test:new": "npm-run-all start-test-server generate-and-test integration-test:alone stop-test-server", - "generate-and-test": "npm-run-all -s build -p generate-bodystring generate-bodycomplex generate-url generate-customurl generate-xmlservice generate-header -s integration-test:alone", + "generate-and-test": "npm-run-all -s build -p generate-bodystring generate-bodycomplex generate-url generate-customurl generate-xmlservice generate-header generate-paging -s integration-test:alone", "integration-test:alone": "mocha -r ts-node/register './test/integration/**/*spec.ts'", "start-test-server": "ts-node test/utils/start-server.ts", - "start-test-server:v1": "ts-node test/integration/testserver-v1/index.ts", + "start-test-server:v1": "start-autorest-express node", "stop-test-server": "stop-autorest-testserver", "debug": "node --inspect-brk ./dist/src/main.js", "generate-bodystring": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/bodyString --use=. --title=BodyStringClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/body-string.json --package-name=bodyString --package-version=1.0.0-preview1", @@ -20,7 +20,8 @@ "generate-url": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/url --use=. --title=UrlClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/url.json --package-name=url --package-version=1.0.0-preview1", "generate-customurl": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/customUrl --use=. --title=CustomUrlClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/custom-baseUrl.json --package-name=custom-url --package-version=1.0.0-preview1", "generate-header": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/header --use=. --title=HeaderClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/header.json --package-name=header --package-version=1.0.0-preview1", - "generate-xmlservice": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/xmlservice --use=. --title=XmlServiceClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/xml-service.json --package-name=xmlservice --package-version=1.0.0-preview1" + "generate-xmlservice": "autorest-beta --add-credentials=false --typescript --output-folder=./test/integration/generated/xmlservice --use=. --title=XmlServiceClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/xml-service.json --package-name=xmlservice --package-version=1.0.0-preview1", + "generate-paging": "autorest-beta --typescript --add-credentials=false --output-folder=./test/integration/generated/paging --use=. --title=PagingClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/paging.json --package-name=pagingservice --package-version=1.0.0-preview1" }, "files": [ "dist/**", @@ -36,6 +37,7 @@ "@azure-tools/linq": "3.1.206", "@azure-tools/openapi": "3.0.209", "@azure/core-http": "^1.0.0", + "@azure/core-paging": "^1.0.0", "@azure/logger": "^1.0.0", "@types/lodash": "^4.14.149", "lodash": "^4.17.15", diff --git a/src/models/operationDetails.ts b/src/models/operationDetails.ts index 0bf8476b1b1d..8c2d3f98c1df 100644 --- a/src/models/operationDetails.ts +++ b/src/models/operationDetails.ts @@ -59,6 +59,7 @@ export interface OperationDetails { responses: OperationResponseDetails[]; typeDetails: TypeDetails; mediaTypes: Set; + pagination?: PaginationDetails; } /** @@ -92,3 +93,38 @@ export interface OperationSpecResponse { export type OperationSpecResponses = { [responseCode: string]: OperationResponseMappers; }; + +/** + * Operation pagination metadata. + */ +export interface PaginationDetails { + /** + * The name of the field in the response that can be paged over. + */ + itemName: string; + /** + * The possible types for the iterable field. + */ + itemTypes: TypeDetails[]; + /** + * Name of the field containing the nextLink value. + * If missing, all results are returned in a single page. + */ + nextLinkName?: string; + /** + * The name of the operation to call with the nextLink. + */ + nextLinkOperationName?: string; + /** + * The name of the operationGroup that nextLinkOperationName resides in. + */ + group?: string; + /** + * The name of the operation that nextLinkOperationName references. + */ + member?: string; + /** + * Indicates whether this operation is used by another operation to get pages. + */ + isNextLinkMethod: boolean; +} diff --git a/src/transforms/extensions.ts b/src/transforms/extensions.ts new file mode 100644 index 000000000000..33b41dacf1f2 --- /dev/null +++ b/src/transforms/extensions.ts @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + CodeModel, + Operation, + SchemaType, + Parameter, + StringSchema, + Protocol, + ParameterLocation +} from "@azure-tools/codemodel"; +import { cloneOperation } from "../utils/cloneOperation"; +import { extractPaginationDetails } from "../utils/extractPaginationDetails"; +import { getLanguageMetadata } from "../utils/languageHelpers"; + +/** + * Normalizes the CodeModel based on available Azure extensions. + * This may result in additional operations being inserted into the model. + * @param codeModel The model that contains all the information required to generate a service API. + */ +export function normalizeModelWithExtensions(codeModel: CodeModel) { + addPageableMethods(codeModel); +} + +/** + * Adds the Next method for each operation with an x-ms-pageable extension. + * @param codeModel + */ +function addPageableMethods(codeModel: CodeModel) { + const operationGroups = codeModel.operationGroups; + + for (const operationGroup of operationGroups) { + const operationGroupMetadata = getLanguageMetadata(operationGroup.language); + const operations = operationGroup.operations.slice(); + + for (const operation of operations) { + const paginationDetails = extractPaginationDetails(operation); + const operationMetadata = getLanguageMetadata(operation.language); + const operationName = operationMetadata.name; + const operationDescription = operationMetadata.description; + + if (!paginationDetails || !paginationDetails.nextLinkName) { + // The operation either doesn't support pagination or returns all items in a single page. + // Therefore, it is not necessary to create a pageable method. + continue; + } + + const nextLinkOperationName = paginationDetails.nextLinkOperationName; + if (!nextLinkOperationName) { + // We don't know what the new operation name is. + throw new Error( + `Unable to determine the x-ms-pageable operationName for "${operationName}".` + ); + } + + // Attempt to find the nextLinkOperationName in the code model. + let nextLinkMethod = findOperation( + codeModel, + paginationDetails.group ?? operationGroupMetadata.name, + nextLinkOperationName + ); + + if (nextLinkMethod) { + // The operation to call to get subsequent pages already exists, so we don't need to create it. + const metadata = getLanguageMetadata(nextLinkMethod.language); + metadata.paging.isNextLinkMethod = true; + continue; + } + + // The "Next" operation doesn't exist, so we need to create it using current operation as a base. + nextLinkMethod = cloneOperation( + operation, + nextLinkOperationName, + operationDescription + ); + + const nextLinkMethodMetadata = getLanguageMetadata( + nextLinkMethod.language + ); + nextLinkMethodMetadata.paging.isNextLinkMethod = true; + + // Since this is a brand new operation, the nextLink will be a partial or absolute url. + const nextLinkRequestProtocol = + nextLinkMethod.request.protocol.http ?? new Protocol(); + nextLinkRequestProtocol.path = "{nextLink}"; + + // Create the nextLink parameter. + // This will appear as a required parameter to the "Next" operation. + const httpProtocol = new Protocol(); + httpProtocol.in = ParameterLocation.Path; + const nextLinkParameter = new Parameter( + "nextLink", + `The nextLink from the previous successful call to the ${operationName} method.`, + new StringSchema("string", ""), + { + required: true, + language: { + default: { + serializedName: "nextLink" + } + }, + extensions: { + "x-ms-skip-url-encoding": true + }, + protocol: { + http: httpProtocol + } + } + ); + nextLinkMethod.request.addParameter(nextLinkParameter); + + operationGroup.addOperation(nextLinkMethod); + } + } +} + +function findOperation( + codeModel: CodeModel, + operationGroupName: string, + operationName: string +): Operation | undefined { + const operationGroup = codeModel.getOperationGroup(operationGroupName); + return operationGroup?.operations.find(operation => { + const languageMetadata = getLanguageMetadata(operation.language); + return languageMetadata.name === operationName; + }); +} diff --git a/src/transforms/operationTransforms.ts b/src/transforms/operationTransforms.ts index 0a7d7f1024ae..626624a6b68d 100644 --- a/src/transforms/operationTransforms.ts +++ b/src/transforms/operationTransforms.ts @@ -33,6 +33,7 @@ import { ParameterDetails } from "../models/parameterDetails"; import { PropertyKind, TypeDetails } from "../models/modelDetails"; import { KnownMediaType } from "@azure-tools/codegen"; import { headersToSchema } from "../utils/headersToSchema"; +import { extractPaginationDetails } from "../utils/extractPaginationDetails"; export function transformOperationSpec( operationDetails: OperationDetails, @@ -222,6 +223,7 @@ export async function transformOperation( operationGroupName: string ): Promise { const metadata = getLanguageMetadata(operation.language); + const pagination = extractPaginationDetails(operation); const name = normalizeName(metadata.name, NameType.Property); const operationFullName = `${operationGroupName}_${name}`; const responsesAndErrors = [ @@ -252,7 +254,8 @@ export async function transformOperation( description: metadata.description, request, responses, - mediaTypes + mediaTypes, + pagination }; } diff --git a/src/transforms/transforms.ts b/src/transforms/transforms.ts index 9ba3933e2bdc..616a0770482a 100644 --- a/src/transforms/transforms.ts +++ b/src/transforms/transforms.ts @@ -24,8 +24,7 @@ import { transformObjects, transformObject } from "./objectTransforms"; import { ObjectDetails } from "../models/modelDetails"; import { Host } from "@azure-tools/autorest-extension-base"; import { transformBaseUrl } from "./urlTransforms"; -import { KnownMediaType } from "@azure-tools/codegen"; -import { OperationGroupDetails } from "../models/operationDetails"; +import { normalizeModelWithExtensions } from "./extensions"; export async function transformChoices(codeModel: CodeModel) { const choices = [ @@ -57,6 +56,7 @@ export async function transformCodeModel( host: Host ): Promise { const className = normalizeName(codeModel.info.title, NameType.Class); + normalizeModelWithExtensions(codeModel); const [uberParents, operationGroups] = await Promise.all([ getUberParents(codeModel), diff --git a/src/utils/cloneOperation.ts b/src/utils/cloneOperation.ts new file mode 100644 index 000000000000..b5a441516906 --- /dev/null +++ b/src/utils/cloneOperation.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { Operation } from "@azure-tools/codemodel"; +import { cloneDeep } from "lodash"; +import { getLanguageMetadata } from "./languageHelpers"; + +/** + * Clone an operation and overwrite the operation name and description. + * @param operation + * @param operationName + * @param operationDescription + */ +export function cloneOperation( + operation: Operation, + operationName: string, + operationDescription: string +) { + const operationInitializer = cloneDeep(operation); + // filter out methods + for (const key of Object.keys(operationInitializer)) { + if (typeof (operationInitializer as any)[key] === "function") { + delete (operationInitializer as any)[key]; + } + } + const newOperation = new Operation( + operationName, + operationDescription, + operationInitializer + ); + const operationMetadata = getLanguageMetadata(newOperation.language); + operationMetadata.name = operationName; + operationMetadata.description = operationName; + + return newOperation; +} diff --git a/src/utils/extractPaginationDetails.ts b/src/utils/extractPaginationDetails.ts new file mode 100644 index 000000000000..cb84c30db933 --- /dev/null +++ b/src/utils/extractPaginationDetails.ts @@ -0,0 +1,166 @@ +import { + Operation, + SchemaResponse, + SchemaType, + ObjectSchema +} from "@azure-tools/codemodel"; +import { isEqual } from "lodash"; +import { PaginationDetails } from "../models/operationDetails"; +import { getLanguageMetadata } from "./languageHelpers"; +import { getTypeForSchema, isSchemaResponse } from "./schemaHelpers"; +import { TypeDetails } from "../models/modelDetails"; + +interface PaginationExtension { + /** + * The name of the field in the response that can be paged over. + */ + itemName?: string; + /** + * Name of the field containing the nextLink value. + * An empty object indicates a null value and that all results + * are returned in a single page. + */ + nextLinkName?: string | {}; + // 'nextLinkOperation', 'group', and 'member' are used together. + /** + * Reference to the operation to call to get the next page. + */ + nextLinkOperation?: Operation; + /** + * The name of the operationGroup that nextLinkOperation resides in. + */ + group?: string; + /** + * The name of the operation that nextLinkOperation references. + */ + member?: string; + /** + * Indicates whether this operation is used by another operation to get pages. + */ + isNextLinkMethod?: boolean; +} + +/** + * Extract pagination details from the pagination extension for an operation. + * @param operation + */ +export function extractPaginationDetails( + operation: Operation +): PaginationDetails | undefined { + const languageMetadata = getLanguageMetadata(operation.language); + const paginationExtension = languageMetadata.paging; + + if (!isPaginationExtension(paginationExtension)) { + return; + } + + const nextLinkName = + typeof paginationExtension.nextLinkName === "string" + ? paginationExtension.nextLinkName + : undefined; + + let nextLinkOperationName = + paginationExtension.nextLinkOperation && languageMetadata.name; + // When nextLinkOperation is not defined, but nextLinkName is, default to Next as the operation name. + // Otherwise, since nextLinkName is not defined, we all iterable results are returned in a single page. + if (!nextLinkOperationName && nextLinkName) { + nextLinkOperationName = `${languageMetadata.name}Next`; + } + + const itemName = paginationExtension.itemName ?? "value"; + + return { + group: paginationExtension.group, + member: paginationExtension.member, + nextLinkName, + itemName, + itemTypes: getItemTypes(operation, itemName), + nextLinkOperationName, + isNextLinkMethod: Boolean(paginationExtension.isNextLinkMethod) + }; +} + +function isPaginationExtension(ext: any): ext is PaginationExtension { + if (!ext || typeof ext !== "object") { + return false; + } + + return "nextLinkName" in ext; +} + +/** + * Gets the types of the iterable field across all responses. + */ +function getItemTypes(operation: Operation, itemName: string): TypeDetails[] { + const operationName = getLanguageMetadata(operation.language).name; + const operationResponses = operation.responses ?? []; + + const itemTypes: TypeDetails[] = []; + + for (const response of operationResponses) { + if (!isSchemaResponse(response)) { + // If the response is not a SchemaResponse (e.g. an Error), + // not enough information is known about its type. + continue; + } + + const status = response.protocol.http?.status; + const typeDetails = getResponseItemType( + response, + operationName, + status, + itemName + ); + + const typeDetailsAlreadyFound = itemTypes.some(itemType => { + return isEqual(itemType, typeDetails); + }); + + if (!typeDetailsAlreadyFound) { + itemTypes.push({ ...typeDetails }); + } + } + + return itemTypes; +} + +/** + * Gets the type of the iterable field. + */ +function getResponseItemType( + response: SchemaResponse, + operationName: string, + status: string, + itemName: string +): TypeDetails { + const responseSchema = response.schema; + if (!isObjectSchema(responseSchema)) { + throw new Error( + `Response for "${operationName}" and status ${status} has "x-ms-pageable" but is not of type "object".` + ); + } + + // Find the 1st property containing the results to paginate over. + const itemProperty = responseSchema.properties?.find(property => { + const propertyName = getLanguageMetadata(property.language).name; + return propertyName === itemName; + }); + + if (!itemProperty) { + throw new Error( + `Possible malformed Swagger. Response for status "${status}" in Operation "${operationName}" doesn't have a(n) "${itemName}" property.` + ); + } + + if (itemProperty.schema.type !== SchemaType.Array) { + throw new Error( + `Possible malformed Swagger. Response for status "${status}" in Operation "${operationName}", expected property "${itemName}" to be of type array.` + ); + } + + return getTypeForSchema(itemProperty.schema); +} + +function isObjectSchema(schema: any): schema is ObjectSchema { + return schema && schema.type === SchemaType.Object; +} diff --git a/test/integration/generated/paging/LICENSE.txt b/test/integration/generated/paging/LICENSE.txt new file mode 100644 index 000000000000..4c529f375cc4 --- /dev/null +++ b/test/integration/generated/paging/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/test/integration/generated/paging/README.md b/test/integration/generated/paging/README.md new file mode 100644 index 000000000000..277d9e3551c4 --- /dev/null +++ b/test/integration/generated/paging/README.md @@ -0,0 +1,27 @@ +## Azure PagingClient SDK for JavaScript + +This package contains an isomorphic SDK for PagingClient. + +### Currently supported environments + +- Node.js version 8.x.x or higher +- Browser JavaScript + +### How to Install + +```bash +npm install pagingservice +``` + +### How to use + +#### Sample code + +Refer the sample code in the [azure-sdk-for-js-samples](https://github.com/Azure/azure-sdk-for-js-samples) repository. + +## Related projects + +- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) + + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcdn%2Farm-cdn%2FREADME.png) \ No newline at end of file diff --git a/test/integration/generated/paging/package.json b/test/integration/generated/paging/package.json new file mode 100644 index 000000000000..29f6b2eac04e --- /dev/null +++ b/test/integration/generated/paging/package.json @@ -0,0 +1,46 @@ +{ + "name": "pagingservice", + "author": "Microsoft Corporation", + "description": "Long-running Operation for AutoRest", + "version": "1.0.0-preview1", + "dependencies": { "@azure/core-http": "^1.0.0", "tslib": "^1.9.3" }, + "keywords": ["node", "azure", "typescript", "browser", "isomorphic"], + "license": "MIT", + "main": "./dist/pagingservice.js", + "module": "./esm/pagingClient.js", + "types": "./esm/pagingClient.d.ts", + "devDependencies": { + "typescript": "^3.1.1", + "rollup": "^0.66.2", + "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-sourcemaps": "^0.4.2", + "uglify-js": "^3.4.9" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js", + "repository": { + "type": "git", + "url": "https://github.com/Azure/azure-sdk-for-js.git" + }, + "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, + "files": [ + "dist/**/*.js", + "dist/**/*.js.map", + "dist/**/*.d.ts", + "dist/**/*.d.ts.map", + "esm/**/*.js", + "esm/**/*.js.map", + "esm/**/*.d.ts", + "esm/**/*.d.ts.map", + "src/**/*.ts", + "README.md", + "rollup.config.js", + "tsconfig.json" + ], + "scripts": { + "build": "tsc && rollup -c rollup.config.js && npm run minify", + "minify": "uglifyjs -c -m --comments --source-map \"content='./dist/pagingservice.js.map'\" -o ./dist/pagingservice.min.js ./dist/pagingservice.js", + "prepack": "npm install && npm run build" + }, + "sideEffects": false, + "autoPublish": true +} diff --git a/test/integration/generated/paging/rollup.config.js b/test/integration/generated/paging/rollup.config.js new file mode 100644 index 000000000000..ce788fa88714 --- /dev/null +++ b/test/integration/generated/paging/rollup.config.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import rollup from "rollup"; +import nodeResolve from "rollup-plugin-node-resolve"; +import sourcemaps from "rollup-plugin-sourcemaps"; + +/** + * @type {rollup.RollupFileOptions} + */ +const config = { + input: "./esm/pagingClient.js", + external: ["@azure/core-http", "@azure/core-arm"], + output: { + file: "./dist/pagingservice.js", + format: "umd", + name: "Pagingservice", + sourcemap: true, + globals: { + "@azure/core-http": "coreHttp", + "@azure/core-arm": "coreArm" + }, + banner: `/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ ` + }, + plugins: [nodeResolve({ module: true }), sourcemaps()] +}; + +export default config; diff --git a/test/integration/generated/paging/src/models/index.ts b/test/integration/generated/paging/src/models/index.ts new file mode 100644 index 000000000000..27dc8fd42f2d --- /dev/null +++ b/test/integration/generated/paging/src/models/index.ts @@ -0,0 +1,739 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; + +export interface ProductResultValue { + value?: Product[]; + nextLink?: string; +} + +export interface Product { + properties?: ProductProperties; +} + +export interface ProductProperties { + id?: number; + name?: string; +} + +export interface ProductResult { + values?: Product[]; + nextLink?: string; +} + +export interface OdataProductResult { + values?: Product[]; + odataNextLink?: string; +} + +export interface OperationResult { + /** + * The status of the request + */ + status?: OperationResultStatus; +} + +/** + * Defines values for OperationResultStatus. + */ +export type OperationResultStatus = + | "Succeeded" + | "Failed" + | "canceled" + | "Accepted" + | "Creating" + | "Created" + | "Updating" + | "Updated" + | "Deleting" + | "Deleted" + | "OK"; + +/** + * Contains response data for the getNoItemNamePages operation. + */ +export type PagingGetNoItemNamePagesResponse = ProductResultValue & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResultValue; + }; +}; + +/** + * Contains response data for the getNullNextLinkNamePages operation. + */ +export type PagingGetNullNextLinkNamePagesResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getSinglePages operation. + */ +export type PagingGetSinglePagesResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePages operation. + */ +export type PagingGetMultiplePagesResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetOdataMultiplePagesOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getOdataMultiplePages operation. + */ +export type PagingGetOdataMultiplePagesResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesWithOffsetOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePagesWithOffset operation. + */ +export type PagingGetMultiplePagesWithOffsetResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesRetryFirst operation. + */ +export type PagingGetMultiplePagesRetryFirstResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesRetrySecond operation. + */ +export type PagingGetMultiplePagesRetrySecondResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getSinglePagesFailure operation. + */ +export type PagingGetSinglePagesFailureResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFailure operation. + */ +export type PagingGetMultiplePagesFailureResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFailureUri operation. + */ +export type PagingGetMultiplePagesFailureUriResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFragmentNextLink operation. + */ +export type PagingGetMultiplePagesFragmentNextLinkResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFragmentWithGroupingNextLink operation. + */ +export type PagingGetMultiplePagesFragmentWithGroupingNextLinkResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesLROOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePagesLRO operation. + */ +export type PagingGetMultiplePagesLROResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the nextFragment operation. + */ +export type PagingNextFragmentResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Contains response data for the nextFragmentWithGrouping operation. + */ +export type PagingNextFragmentWithGroupingResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Contains response data for the getNoItemNamePagesNext operation. + */ +export type PagingGetNoItemNamePagesNextResponse = ProductResultValue & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResultValue; + }; +}; + +/** + * Contains response data for the getSinglePagesNext operation. + */ +export type PagingGetSinglePagesNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesNextOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePagesNext operation. + */ +export type PagingGetMultiplePagesNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetOdataMultiplePagesNextOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getOdataMultiplePagesNext operation. + */ +export type PagingGetOdataMultiplePagesNextResponse = OdataProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: OdataProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesWithOffsetNextOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePagesWithOffsetNext operation. + */ +export type PagingGetMultiplePagesWithOffsetNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesRetryFirstNext operation. + */ +export type PagingGetMultiplePagesRetryFirstNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesRetrySecondNext operation. + */ +export type PagingGetMultiplePagesRetrySecondNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getSinglePagesFailureNext operation. + */ +export type PagingGetSinglePagesFailureNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFailureNext operation. + */ +export type PagingGetMultiplePagesFailureNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Contains response data for the getMultiplePagesFailureUriNext operation. + */ +export type PagingGetMultiplePagesFailureUriNextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingGetMultiplePagesLRONextOptionalParams + extends coreHttp.OperationOptions { + clientRequestId?: string; + /** + * Sets the maximum number of items to return in the response. + */ + maxresults?: number; + /** + * Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. + */ + timeout?: number; +} + +/** + * Contains response data for the getMultiplePagesLRONext operation. + */ +export type PagingGetMultiplePagesLRONextResponse = ProductResult & { + /** + * The underlying HTTP response. + */ + _response: coreHttp.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ProductResult; + }; +}; + +/** + * Optional parameters. + */ +export interface PagingClientOptionalParams + extends coreHttp.ServiceClientOptions { + /** + * server parameter + */ + $host?: string; + /** + * Overrides client endpoint. + */ + endpoint?: string; +} diff --git a/test/integration/generated/paging/src/models/mappers.ts b/test/integration/generated/paging/src/models/mappers.ts new file mode 100644 index 000000000000..9e70bab8fadb --- /dev/null +++ b/test/integration/generated/paging/src/models/mappers.ts @@ -0,0 +1,103 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; + +export const ProductResultValue: coreHttp.CompositeMapper = { + serializedName: "ProductResultValue", + type: { + name: "Composite", + className: "ProductResultValue", + modelProperties: { + value: { + type: { + name: "Sequence", + element: { type: { name: "Composite", className: "Product" } } + }, + serializedName: "value" + }, + nextLink: { type: { name: "String" }, serializedName: "nextLink" } + } + } +}; + +export const Product: coreHttp.CompositeMapper = { + serializedName: "Product", + type: { + name: "Composite", + className: "Product", + modelProperties: { + properties: { + serializedName: "properties", + type: { name: "Composite", className: "ProductProperties" } + } + } + } +}; + +export const ProductProperties: coreHttp.CompositeMapper = { + serializedName: "ProductProperties", + type: { + name: "Composite", + className: "ProductProperties", + modelProperties: { + id: { type: { name: "Number" }, serializedName: "id" }, + name: { type: { name: "String" }, serializedName: "name" } + } + } +}; + +export const ProductResult: coreHttp.CompositeMapper = { + serializedName: "ProductResult", + type: { + name: "Composite", + className: "ProductResult", + modelProperties: { + values: { + type: { + name: "Sequence", + element: { type: { name: "Composite", className: "Product" } } + }, + serializedName: "values" + }, + nextLink: { type: { name: "String" }, serializedName: "nextLink" } + } + } +}; + +export const OdataProductResult: coreHttp.CompositeMapper = { + serializedName: "OdataProductResult", + type: { + name: "Composite", + className: "OdataProductResult", + modelProperties: { + values: { + type: { + name: "Sequence", + element: { type: { name: "Composite", className: "Product" } } + }, + serializedName: "values" + }, + odataNextLink: { + type: { name: "String" }, + serializedName: "odata.nextLink" + } + } + } +}; + +export const OperationResult: coreHttp.CompositeMapper = { + serializedName: "OperationResult", + type: { + name: "Composite", + className: "OperationResult", + modelProperties: { + status: { type: { name: "String" }, serializedName: "status" } + } + } +}; diff --git a/test/integration/generated/paging/src/models/parameters.ts b/test/integration/generated/paging/src/models/parameters.ts new file mode 100644 index 000000000000..25b970bf7482 --- /dev/null +++ b/test/integration/generated/paging/src/models/parameters.ts @@ -0,0 +1,252 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import * as Mappers from "../models/mappers"; + +export const $host: coreHttp.OperationURLParameter = { + parameterPath: "$host", + mapper: { + serializedName: "$host", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const clientRequestId: coreHttp.OperationParameter = { + parameterPath: ["options", "clientRequestId"], + mapper: { + serializedName: "client-request-id", + type: { + name: "String" + } + } +}; + +export const maxresults: coreHttp.OperationParameter = { + parameterPath: ["options", "maxresults"], + mapper: { + serializedName: "maxresults", + type: { + name: "Number" + } + } +}; + +export const timeout: coreHttp.OperationParameter = { + parameterPath: ["options", "timeout"], + mapper: { + defaultValue: 30, + serializedName: "timeout", + type: { + name: "Number" + } + } +}; + +export const offset: coreHttp.OperationURLParameter = { + parameterPath: "offset", + mapper: { + serializedName: "offset", + required: true, + type: { + name: "Number" + } + } +}; + +export const apiVersion: coreHttp.OperationQueryParameter = { + parameterPath: "apiVersion", + mapper: { + serializedName: "api_version", + required: true, + type: { + name: "String" + } + } +}; + +export const tenant: coreHttp.OperationURLParameter = { + parameterPath: "tenant", + mapper: { + serializedName: "tenant", + required: true, + type: { + name: "String" + } + } +}; + +export const apiVersion1: coreHttp.OperationQueryParameter = { + parameterPath: "apiVersion", + mapper: { + serializedName: "api_version", + required: true, + type: { + name: "String" + } + } +}; + +export const tenant1: coreHttp.OperationURLParameter = { + parameterPath: "tenant", + mapper: { + serializedName: "tenant", + required: true, + type: { + name: "String" + } + } +}; + +export const nextLink: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink1: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink2: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink3: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink4: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink5: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink6: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink7: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink8: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink9: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink10: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const nextLink11: coreHttp.OperationURLParameter = { + parameterPath: "nextLink", + mapper: { + serializedName: "nextLink", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; diff --git a/test/integration/generated/paging/src/operations/index.ts b/test/integration/generated/paging/src/operations/index.ts new file mode 100644 index 000000000000..5534f66d5e56 --- /dev/null +++ b/test/integration/generated/paging/src/operations/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export * from "./paging"; diff --git a/test/integration/generated/paging/src/operations/paging.ts b/test/integration/generated/paging/src/operations/paging.ts new file mode 100644 index 000000000000..957b2cf84c46 --- /dev/null +++ b/test/integration/generated/paging/src/operations/paging.ts @@ -0,0 +1,808 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import * as Models from "../models"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { PagingClient } from "../pagingClient"; + +/** + * Class representing a Paging. + */ +export class Paging { + private readonly client: PagingClient; + + /** + * Initialize a new instance of the class Paging class. + * @param client Reference to the service client + */ + constructor(client: PagingClient) { + this.client = client; + } + + /** + * A paging operation that must return result of the default 'value' node. + * @param options The options parameters. + */ + getNoItemNamePages( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getNoItemNamePagesOperationSpec + ) as Promise; + } + + /** + * A paging operation that must ignore any kind of nextLink, and stop after page 1. + * @param options The options parameters. + */ + getNullNextLinkNamePages( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getNullNextLinkNamePagesOperationSpec + ) as Promise; + } + + /** + * A paging operation that finishes on the first call without a nextlink + * @param options The options parameters. + */ + getSinglePages( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getSinglePagesOperationSpec + ) as Promise; + } + + /** + * A paging operation that includes a nextLink that has 10 pages + * @param options The options parameters. + */ + getMultiplePages( + options?: Models.PagingGetMultiplePagesOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesOperationSpec + ) as Promise; + } + + /** + * A paging operation that includes a nextLink in odata format that has 10 pages + * @param options The options parameters. + */ + getOdataMultiplePages( + options?: Models.PagingGetOdataMultiplePagesOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { options }, + getOdataMultiplePagesOperationSpec + ) as Promise; + } + + /** + * A paging operation that includes a nextLink that has 10 pages + * @param offset Offset of return value + * @param options The options parameters. + */ + getMultiplePagesWithOffset( + offset: number, + options?: Models.PagingGetMultiplePagesWithOffsetOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { offset, options }, + getMultiplePagesWithOffsetOperationSpec + ) as Promise; + } + + /** + * A paging operation that fails on the first call with 500 and then retries and then get a response + * including a nextLink that has 10 pages + * @param options The options parameters. + */ + getMultiplePagesRetryFirst( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesRetryFirstOperationSpec + ) as Promise; + } + + /** + * A paging operation that includes a nextLink that has 10 pages, of which the 2nd call fails first + * with 500. The client should retry and finish all 10 pages eventually. + * @param options The options parameters. + */ + getMultiplePagesRetrySecond( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesRetrySecondOperationSpec + ) as Promise; + } + + /** + * A paging operation that receives a 400 on the first call + * @param options The options parameters. + */ + getSinglePagesFailure( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getSinglePagesFailureOperationSpec + ) as Promise; + } + + /** + * A paging operation that receives a 400 on the second call + * @param options The options parameters. + */ + getMultiplePagesFailure( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesFailureOperationSpec + ) as Promise; + } + + /** + * A paging operation that receives an invalid nextLink + * @param options The options parameters. + */ + getMultiplePagesFailureUri( + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesFailureUriOperationSpec + ) as Promise; + } + + /** + * A paging operation that doesn't return a full URL, just a fragment + * @param apiVersion Sets the api version to use. + * @param tenant Sets the tenant to use. + * @param options The options parameters. + */ + getMultiplePagesFragmentNextLink( + apiVersion: string, + tenant: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { apiVersion, tenant, options }, + getMultiplePagesFragmentNextLinkOperationSpec + ) as Promise; + } + + /** + * A paging operation that doesn't return a full URL, just a fragment with parameters grouped + * @param apiVersion Sets the api version to use. + * @param tenant Sets the tenant to use. + * @param options The options parameters. + */ + getMultiplePagesFragmentWithGroupingNextLink( + apiVersion: string, + tenant: string, + options?: coreHttp.OperationOptions + ): Promise< + Models.PagingGetMultiplePagesFragmentWithGroupingNextLinkResponse + > { + return this.client.sendOperationRequest( + { apiVersion, tenant, options }, + getMultiplePagesFragmentWithGroupingNextLinkOperationSpec + ) as Promise< + Models.PagingGetMultiplePagesFragmentWithGroupingNextLinkResponse + >; + } + + /** + * A long-running paging operation that includes a nextLink that has 10 pages + * @param options The options parameters. + */ + getMultiplePagesLRO( + options?: Models.PagingGetMultiplePagesLROOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { options }, + getMultiplePagesLROOperationSpec + ) as Promise; + } + + /** + * A paging operation that doesn't return a full URL, just a fragment + * @param apiVersion Sets the api version to use. + * @param tenant Sets the tenant to use. + * @param nextLink Next link for list operation. + * @param options The options parameters. + */ + nextFragment( + apiVersion: string, + tenant: string, + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { apiVersion, tenant, nextLink, options }, + nextFragmentOperationSpec + ) as Promise; + } + + /** + * A paging operation that doesn't return a full URL, just a fragment + * @param apiVersion Sets the api version to use. + * @param tenant Sets the tenant to use. + * @param nextLink Next link for list operation. + * @param options The options parameters. + */ + nextFragmentWithGrouping( + apiVersion: string, + tenant: string, + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { apiVersion, tenant, nextLink, options }, + nextFragmentWithGroupingOperationSpec + ) as Promise; + } + + /** + * GetNoItemNamePagesNext + * @param nextLink The nextLink from the previous successful call to the GetNoItemNamePages method. + * @param options The options parameters. + */ + getNoItemNamePagesNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getNoItemNamePagesNextOperationSpec + ) as Promise; + } + + /** + * GetSinglePagesNext + * @param nextLink The nextLink from the previous successful call to the GetSinglePages method. + * @param options The options parameters. + */ + getSinglePagesNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getSinglePagesNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesNext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePages method. + * @param options The options parameters. + */ + getMultiplePagesNext( + nextLink: string, + options?: Models.PagingGetMultiplePagesNextOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesNextOperationSpec + ) as Promise; + } + + /** + * GetOdataMultiplePagesNext + * @param nextLink The nextLink from the previous successful call to the GetOdataMultiplePages method. + * @param options The options parameters. + */ + getOdataMultiplePagesNext( + nextLink: string, + options?: Models.PagingGetOdataMultiplePagesNextOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getOdataMultiplePagesNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesWithOffsetNext + * @param offset Offset of return value + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesWithOffset + * method. + * @param options The options parameters. + */ + getMultiplePagesWithOffsetNext( + offset: number, + nextLink: string, + options?: Models.PagingGetMultiplePagesWithOffsetNextOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { offset, nextLink, options }, + getMultiplePagesWithOffsetNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesRetryFirstNext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesRetryFirst + * method. + * @param options The options parameters. + */ + getMultiplePagesRetryFirstNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesRetryFirstNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesRetrySecondNext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesRetrySecond + * method. + * @param options The options parameters. + */ + getMultiplePagesRetrySecondNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesRetrySecondNextOperationSpec + ) as Promise; + } + + /** + * GetSinglePagesFailureNext + * @param nextLink The nextLink from the previous successful call to the GetSinglePagesFailure method. + * @param options The options parameters. + */ + getSinglePagesFailureNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getSinglePagesFailureNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesFailureNext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesFailure + * method. + * @param options The options parameters. + */ + getMultiplePagesFailureNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesFailureNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesFailureUriNext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesFailureUri + * method. + * @param options The options parameters. + */ + getMultiplePagesFailureUriNext( + nextLink: string, + options?: coreHttp.OperationOptions + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesFailureUriNextOperationSpec + ) as Promise; + } + + /** + * GetMultiplePagesLRONext + * @param nextLink The nextLink from the previous successful call to the GetMultiplePagesLRO method. + * @param options The options parameters. + */ + getMultiplePagesLRONext( + nextLink: string, + options?: Models.PagingGetMultiplePagesLRONextOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { nextLink, options }, + getMultiplePagesLRONextOperationSpec + ) as Promise; + } +} +// Operation Specifications + +const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); + +const getNoItemNamePagesOperationSpec: coreHttp.OperationSpec = { + path: "/paging/noitemname", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResultValue + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getNullNextLinkNamePagesOperationSpec: coreHttp.OperationSpec = { + path: "/paging/nullnextlink", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getSinglePagesOperationSpec: coreHttp.OperationSpec = { + path: "/paging/single", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getMultiplePagesOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getOdataMultiplePagesOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/odata", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getMultiplePagesWithOffsetOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/withpath/{offset}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.offset], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getMultiplePagesRetryFirstOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/retryfirst", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getMultiplePagesRetrySecondOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/retrysecond", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getSinglePagesFailureOperationSpec: coreHttp.OperationSpec = { + path: "/paging/single/failure", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getMultiplePagesFailureOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/failure", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getMultiplePagesFailureUriOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/failureuri", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + serializer +}; +const getMultiplePagesFragmentNextLinkOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/fragment/{tenant}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.$host, Parameters.tenant], + serializer +}; +const getMultiplePagesFragmentWithGroupingNextLinkOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/fragmentwithgrouping/{tenant}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + queryParameters: [Parameters.apiVersion1], + urlParameters: [Parameters.$host, Parameters.tenant1], + serializer +}; +const getMultiplePagesLROOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/lro", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const nextFragmentOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/fragment/{tenant}/{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.$host, Parameters.tenant, Parameters.nextLink], + serializer +}; +const nextFragmentWithGroupingOperationSpec: coreHttp.OperationSpec = { + path: "/paging/multiple/fragmentwithgrouping/{tenant}/{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + queryParameters: [Parameters.apiVersion1], + urlParameters: [Parameters.$host, Parameters.tenant1, Parameters.nextLink], + serializer +}; +const getNoItemNamePagesNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResultValue + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink1], + serializer +}; +const getSinglePagesNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink2], + serializer +}; +const getMultiplePagesNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink3], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getOdataMultiplePagesNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.OdataProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink4], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getMultiplePagesWithOffsetNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.offset, Parameters.nextLink5], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; +const getMultiplePagesRetryFirstNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink6], + serializer +}; +const getMultiplePagesRetrySecondNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink7], + serializer +}; +const getSinglePagesFailureNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink8], + serializer +}; +const getMultiplePagesFailureNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink9], + serializer +}; +const getMultiplePagesFailureUriNextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink10], + serializer +}; +const getMultiplePagesLRONextOperationSpec: coreHttp.OperationSpec = { + path: "{nextLink}", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.ProductResult + }, + default: {} + }, + urlParameters: [Parameters.$host, Parameters.nextLink11], + headerParameters: [ + Parameters.clientRequestId, + Parameters.maxresults, + Parameters.timeout + ], + serializer +}; diff --git a/test/integration/generated/paging/src/pagingClient.ts b/test/integration/generated/paging/src/pagingClient.ts new file mode 100644 index 000000000000..f859fc1f1933 --- /dev/null +++ b/test/integration/generated/paging/src/pagingClient.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as operations from "./operations"; +import * as Models from "./models"; +import * as Mappers from "./models/mappers"; +import { PagingClientContext } from "./pagingClientContext"; + +class PagingClient extends PagingClientContext { + /** + * Initializes a new instance of the PagingClient class. + * @param options The parameter options + */ + constructor(options?: Models.PagingClientOptionalParams) { + super(options); + this.paging = new operations.Paging(this); + } + + paging: operations.Paging; +} + +// Operation Specifications + +export { + PagingClient, + PagingClientContext, + Models as PagingModels, + Mappers as PagingMappers +}; +export * from "./operations"; diff --git a/test/integration/generated/paging/src/pagingClientContext.ts b/test/integration/generated/paging/src/pagingClientContext.ts new file mode 100644 index 000000000000..2d4658d65e2c --- /dev/null +++ b/test/integration/generated/paging/src/pagingClientContext.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import * as Models from "./models"; + +const packageName = "pagingservice"; +const packageVersion = "1.0.0-preview1"; + +export class PagingClientContext extends coreHttp.ServiceClient { + $host: string; + + /** + * Initializes a new instance of the PagingClientContext class. + * @param options The parameter options + */ + constructor(options?: Models.PagingClientOptionalParams) { + // Initializing default values for options + if (!options) { + options = {}; + } + + if (!options.userAgent) { + const defaultUserAgent = coreHttp.getDefaultUserAgentValue(); + options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; + } + + super(undefined, options); + + this.requestContentType = "application/json; charset=utf-8"; + + this.baseUri = options.endpoint || "{$host}"; + + // Assigning values to Constant parameters + this.$host = options.$host || "http://localhost:3000"; + } +} diff --git a/test/integration/generated/paging/tsconfig.json b/test/integration/generated/paging/tsconfig.json new file mode 100644 index 000000000000..422b584abd5e --- /dev/null +++ b/test/integration/generated/paging/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "es6", + "moduleResolution": "node", + "strict": true, + "target": "es5", + "sourceMap": true, + "declarationMap": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es6", "dom"], + "declaration": true, + "outDir": "./esm", + "importHelpers": true + }, + "include": ["./src/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/test/integration/paging.spec.ts b/test/integration/paging.spec.ts new file mode 100644 index 000000000000..5d7b7a7937d5 --- /dev/null +++ b/test/integration/paging.spec.ts @@ -0,0 +1,128 @@ +import { expect } from "chai"; +import { PagingClient } from "./generated/paging/src/pagingClient"; +import { + PagingGetMultiplePagesResponse, + PagingGetMultiplePagesWithOffsetResponse, + PagingGetMultiplePagesFragmentNextLinkResponse +} from "./generated/paging/src/models"; + +describe("Integration tests for Paging", () => { + let client: PagingClient; + + beforeEach(() => { + client = new PagingClient(); + }); + + describe("#getSinglePages", () => { + it("succeeds", async () => { + const response = await client.paging.getSinglePages(); + expect( + response.nextLink, + "nextLink should not be present on the response." + ).to.be.undefined; + + expect(response.values).to.deep.equal([ + { + properties: { + id: 1, + name: "Product" + } + } + ]); + }); + }); + + describe("#getSinglePagesFailure", () => { + it("throws an error", async () => { + try { + await client.paging.getSinglePagesFailure(); + throw new Error("Test failure"); + } catch (err) { + expect(err.message).to.not.equal("Test failure"); + // TODO: update core-http to 1.0.4 once released + // expect(err.statusCode).to.equal(400); + } + }); + }); + + describe("#getMultiplePages", () => { + it("succeeds", async () => { + const results = []; + let nextLink: string | undefined; + do { + let response: PagingGetMultiplePagesResponse; + if (!nextLink) { + response = await client.paging.getMultiplePages(); + } else { + response = await client.paging.getMultiplePagesNext(nextLink); + } + const values = response.values ?? []; + results.push(...values); + nextLink = response.nextLink; + } while (nextLink); + + expect(results.length).to.equal( + 10, + "Unexpected number of pages received." + ); + }); + }); + + describe("#getMultiplePagesWithOffset", () => { + it("succeeds", async () => { + const results = []; + let nextLink: string | undefined; + do { + let response: PagingGetMultiplePagesWithOffsetResponse; + if (!nextLink) { + response = await client.paging.getMultiplePagesWithOffset(100); + } else { + response = await client.paging.getMultiplePagesWithOffsetNext( + 100, + nextLink + ); + } + const values = response.values ?? []; + results.push(...values); + nextLink = response.nextLink; + } while (nextLink); + + expect(results.length).to.equal( + 10, + "Unexpected number of pages received." + ); + }); + }); + + // TODO: https://github.com/Azure/autorest.typescript/issues/574 + describe.skip("#getMultiplePagesFragmentNextLink", () => { + it("succeeds", async () => { + const results = []; + let nextLink: string | undefined; + do { + let response: PagingGetMultiplePagesFragmentNextLinkResponse; + if (!nextLink) { + response = await client.paging.getMultiplePagesFragmentNextLink( + "1.6", + "test_user", + {} + ); + } else { + response = await client.paging.nextFragment( + "1.6", + "test_user", + nextLink + ); + } + const values = response.values ?? []; + results.push(...values); + nextLink = response.odataNextLink; + } while (nextLink); + + expect(results.length).to.equal( + 10, + "Unexpected number of pages received." + ); + }); + }); +});