From f4ea9f8d2877a0ebaba426805bff7f477d8ca871 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 7 Jun 2022 05:02:58 +0000 Subject: [PATCH] CodeGen from PR 19256 in Azure/azure-rest-api-specs [Cognitive Services] Add new deployment scale type (#19256) * [Cognitive Services] Add new deployment scale type * fix CI. * Add location on Async Header --- .../arm-cognitiveservices/CHANGELOG.md | 17 +++--- .../arm-cognitiveservices/_meta.json | 8 +-- .../arm-cognitiveservices/package.json | 26 ++++---- .../review/arm-cognitiveservices.api.md | 4 +- .../src/cognitiveServicesManagementClient.ts | 60 ++++++++++++++++++- .../arm-cognitiveservices/src/models/index.ts | 2 + .../arm-cognitiveservices/test/sampleTest.ts | 43 +++++++++++++ .../arm-cognitiveservices/tsconfig.json | 10 +--- 8 files changed, 130 insertions(+), 40 deletions(-) create mode 100644 sdk/cognitiveservices/arm-cognitiveservices/test/sampleTest.ts diff --git a/sdk/cognitiveservices/arm-cognitiveservices/CHANGELOG.md b/sdk/cognitiveservices/arm-cognitiveservices/CHANGELOG.md index 919b2c50a74f..ef82e7778563 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/CHANGELOG.md +++ b/sdk/cognitiveservices/arm-cognitiveservices/CHANGELOG.md @@ -1,15 +1,12 @@ # Release History + +## 7.2.0 (2022-06-07) + +**Features** -## 7.1.1 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - + - Enum KnownDeploymentScaleType has a new value Standard + + ## 7.1.0 (2022-04-06) **Features** diff --git a/sdk/cognitiveservices/arm-cognitiveservices/_meta.json b/sdk/cognitiveservices/arm-cognitiveservices/_meta.json index 778625a572be..c00c009449d7 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/_meta.json +++ b/sdk/cognitiveservices/arm-cognitiveservices/_meta.json @@ -1,8 +1,8 @@ { - "commit": "515a036fd42e59b65e94c8480b3a850d0b192bfc", + "commit": "01efd1f79d22d073b063554319562978c0bb1b9c", "readme": "specification/cognitiveservices/resource-manager/readme.md", - "autorest_command": "autorest --version=3.7.3 --typescript --modelerfour.lenient-model-deduplication --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=D:\\work\\azure-sdk-for-js ..\\azure-rest-api-specs\\specification\\cognitiveservices\\resource-manager\\readme.md --use=@autorest/typescript@6.0.0-alpha.18.20220329.1 --generate-sample=true", + "autorest_command": "autorest --version=3.7.3 --typescript --modelerfour.lenient-model-deduplication --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-js ../azure-rest-api-specs/specification/cognitiveservices/resource-manager/readme.md --use=@autorest/typescript@6.0.0-alpha.19.20220425.1", "repository_url": "https://github.com/Azure/azure-rest-api-specs.git", - "release_tool": "@azure-tools/js-sdk-release-tools@2.2.1", - "use": "@autorest/typescript@6.0.0-alpha.18.20220329.1" + "release_tool": "@azure-tools/js-sdk-release-tools@2.3.1", + "use": "@autorest/typescript@6.0.0-alpha.19.20220425.1" } \ No newline at end of file diff --git a/sdk/cognitiveservices/arm-cognitiveservices/package.json b/sdk/cognitiveservices/arm-cognitiveservices/package.json index 9ed13a412e71..e66b005829d2 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/package.json +++ b/sdk/cognitiveservices/arm-cognitiveservices/package.json @@ -3,7 +3,7 @@ "sdk-type": "mgmt", "author": "Microsoft Corporation", "description": "A generated SDK for CognitiveServicesManagementClient.", - "version": "7.1.1", + "version": "7.2.0", "engines": { "node": ">=12.0.0" }, @@ -11,9 +11,9 @@ "@azure/core-lro": "^2.2.0", "@azure/abort-controller": "^1.0.0", "@azure/core-paging": "^1.2.0", - "@azure/core-client": "^1.0.0", + "@azure/core-client": "^1.5.0", "@azure/core-auth": "^1.3.0", - "@azure/core-rest-pipeline": "^1.1.0", + "@azure/core-rest-pipeline": "^1.8.0", "tslib": "^2.2.0" }, "keywords": [ @@ -40,9 +40,11 @@ "uglify-js": "^3.4.9", "rimraf": "^3.0.0", "@azure/identity": "^2.0.1", - "@azure-tools/test-recorder": "^1.0.0", + "@azure-tools/test-recorder": "^2.0.0", + "@azure-tools/test-credential": "^1.0.0", "mocha": "^7.1.1", - "cross-env": "^7.0.2" + "cross-env": "^7.0.2", + "@azure/dev-tool": "^1.0.0" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitiveservices/arm-cognitiveservices", "repository": { @@ -93,7 +95,7 @@ "unit-test:node": "cross-env TEST_MODE=playback npm run integration-test:node", "unit-test:browser": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:node": "mocha -r esm --require ts-node/register --timeout 1200000 --full-trace test/*.ts --reporter ../../../common/tools/mocha-multi-reporter.js", + "integration-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 'test/*.ts'", "integration-test:browser": "echo skipped", "docs": "echo skipped" }, @@ -106,13 +108,5 @@ } ] }, - "autoPublish": true, - "//sampleConfiguration": { - "productName": "", - "productSlugs": [ - "azure" - ], - "disableDocsMs": true, - "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure/arm-cognitiveservices?view=azure-node-preview" - } -} + "autoPublish": true +} \ No newline at end of file diff --git a/sdk/cognitiveservices/arm-cognitiveservices/review/arm-cognitiveservices.api.md b/sdk/cognitiveservices/arm-cognitiveservices/review/arm-cognitiveservices.api.md index 98a3ca0cfb09..3a2c469ab10e 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/review/arm-cognitiveservices.api.md +++ b/sdk/cognitiveservices/arm-cognitiveservices/review/arm-cognitiveservices.api.md @@ -669,7 +669,9 @@ export enum KnownDeploymentProvisioningState { // @public export enum KnownDeploymentScaleType { // (undocumented) - Manual = "Manual" + Manual = "Manual", + // (undocumented) + Standard = "Standard" } // @public diff --git a/sdk/cognitiveservices/arm-cognitiveservices/src/cognitiveServicesManagementClient.ts b/sdk/cognitiveservices/arm-cognitiveservices/src/cognitiveServicesManagementClient.ts index a93c0c2617f6..c568ecc7c3ac 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/src/cognitiveServicesManagementClient.ts +++ b/sdk/cognitiveservices/arm-cognitiveservices/src/cognitiveServicesManagementClient.ts @@ -7,6 +7,12 @@ */ import * as coreClient from "@azure/core-client"; +import * as coreRestPipeline from "@azure/core-rest-pipeline"; +import { + PipelineRequest, + PipelineResponse, + SendRequest +} from "@azure/core-rest-pipeline"; import * as coreAuth from "@azure/core-auth"; import { AccountsImpl, @@ -72,7 +78,7 @@ export class CognitiveServicesManagementClient extends coreClient.ServiceClient credential: credentials }; - const packageDetails = `azsdk-js-arm-cognitiveservices/7.1.1`; + const packageDetails = `azsdk-js-arm-cognitiveservices/7.2.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` @@ -91,6 +97,29 @@ export class CognitiveServicesManagementClient extends coreClient.ServiceClient options.endpoint ?? options.baseUri ?? "https://management.azure.com" }; super(optionsWithDefaults); + + if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) { + const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies(); + const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some( + (pipelinePolicy) => + pipelinePolicy.name === + coreRestPipeline.bearerTokenAuthenticationPolicyName + ); + if (!bearerTokenAuthenticationPolicyFound) { + this.pipeline.removePolicy({ + name: coreRestPipeline.bearerTokenAuthenticationPolicyName + }); + this.pipeline.addPolicy( + coreRestPipeline.bearerTokenAuthenticationPolicy({ + scopes: `${optionsWithDefaults.baseUri}/.default`, + challengeCallbacks: { + authorizeRequestOnChallenge: + coreClient.authorizeRequestOnClaimChallenge + } + }) + ); + } + } // Parameter assignments this.subscriptionId = subscriptionId; @@ -106,6 +135,35 @@ export class CognitiveServicesManagementClient extends coreClient.ServiceClient this.privateLinkResources = new PrivateLinkResourcesImpl(this); this.deployments = new DeploymentsImpl(this); this.commitmentPlans = new CommitmentPlansImpl(this); + this.addCustomApiVersionPolicy(options.apiVersion); + } + + /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ + private addCustomApiVersionPolicy(apiVersion?: string) { + if (!apiVersion) { + return; + } + const apiVersionPolicy = { + name: "CustomApiVersionPolicy", + async sendRequest( + request: PipelineRequest, + next: SendRequest + ): Promise { + const param = request.url.split("?"); + if (param.length > 1) { + const newParams = param[1].split("&").map((item) => { + if (item.indexOf("api-version") > -1) { + return item.replace(/(?<==).*$/, apiVersion); + } else { + return item; + } + }); + request.url = param[0] + "?" + newParams.join("&"); + } + return next(request); + } + }; + this.pipeline.addPolicy(apiVersionPolicy); } /** diff --git a/sdk/cognitiveservices/arm-cognitiveservices/src/models/index.ts b/sdk/cognitiveservices/arm-cognitiveservices/src/models/index.ts index dec6c99a4c78..633a7c40edba 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/src/models/index.ts +++ b/sdk/cognitiveservices/arm-cognitiveservices/src/models/index.ts @@ -1206,6 +1206,7 @@ export type DeploymentProvisioningState = string; /** Known values of {@link DeploymentScaleType} that the service accepts. */ export enum KnownDeploymentScaleType { + Standard = "Standard", Manual = "Manual" } @@ -1214,6 +1215,7 @@ export enum KnownDeploymentScaleType { * {@link KnownDeploymentScaleType} can be used interchangeably with DeploymentScaleType, * this enum contains the known values that the service supports. * ### Known values supported by the service + * **Standard** \ * **Manual** */ export type DeploymentScaleType = string; diff --git a/sdk/cognitiveservices/arm-cognitiveservices/test/sampleTest.ts b/sdk/cognitiveservices/arm-cognitiveservices/test/sampleTest.ts new file mode 100644 index 000000000000..25aeb3ebcc36 --- /dev/null +++ b/sdk/cognitiveservices/arm-cognitiveservices/test/sampleTest.ts @@ -0,0 +1,43 @@ +/* + * 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 { + Recorder, + RecorderStartOptions, + env +} from "@azure-tools/test-recorder"; +import { assert } from "chai"; +import { Context } from "mocha"; + +const replaceableVariables: Record = { + AZURE_CLIENT_ID: "azure_client_id", + AZURE_CLIENT_SECRET: "azure_client_secret", + AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", + SUBSCRIPTION_ID: "azure_subscription_id" +}; + +const recorderOptions: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables +}; + +describe("My test", () => { + let recorder: Recorder; + + beforeEach(async function(this: Context) { + recorder = new Recorder(this.currentTest); + await recorder.start(recorderOptions); + }); + + afterEach(async function() { + await recorder.stop(); + }); + + it("sample test", async function() { + console.log("Hi, I'm a test!"); + }); +}); diff --git a/sdk/cognitiveservices/arm-cognitiveservices/tsconfig.json b/sdk/cognitiveservices/arm-cognitiveservices/tsconfig.json index 67e8e46df416..3e6ae96443f3 100644 --- a/sdk/cognitiveservices/arm-cognitiveservices/tsconfig.json +++ b/sdk/cognitiveservices/arm-cognitiveservices/tsconfig.json @@ -15,17 +15,11 @@ ], "declaration": true, "outDir": "./dist-esm", - "importHelpers": true, - "paths": { - "@azure/arm-cognitiveservices": [ - "./src/index" - ] - } + "importHelpers": true }, "include": [ "./src/**/*.ts", - "./test/**/*.ts", - "samples-dev/**/*.ts" + "./test/**/*.ts" ], "exclude": [ "node_modules"