From a6e2d066a82c378b74b80b78cfe0d4bcb0f50001 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 12 Nov 2020 00:38:06 +0000 Subject: [PATCH] CodeGen from PR 11571 in Azure/azure-rest-api-specs [Text Analytics] rename notstarted to notStarted (#11571) * rename notstarted to notStarted * adding rejected * fix allof * fix * fix * make results required * name is optional --- .../LICENSE.txt | 2 +- .../cognitiveservices-textanalytics/README.md | 160 ++++++------------ .../rollup.config.js | 4 +- .../src/models/index.ts | 13 +- .../src/models/mappers.ts | 4 +- .../src/models/parameters.ts | 5 +- .../src/textAnalyticsClient.ts | 16 +- .../src/textAnalyticsClientContext.ts | 5 +- 8 files changed, 76 insertions(+), 133 deletions(-) diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt b/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt index b73b4a1293c3..ea8fb1516028 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Microsoft +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 diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md b/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md index 905442972f0d..01cc0d4bcb70 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md @@ -15,80 +15,54 @@ npm install @azure/cognitiveservices-textanalytics ### How to use -#### nodejs - Authentication, client creation and detectLanguage as an example written in TypeScript. +#### nodejs - client creation and detectLanguage as an example written in TypeScript. -##### Install @azure/ms-rest-azure-js +##### Install @azure/ms-rest-nodeauth +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. ```bash -npm install @azure/ms-rest-azure-js +npm install @azure/ms-rest-nodeauth@"^3.0.0" ``` ##### Sample code -The following sample detects the langauge in the provided text. In addition, it provides data such as Characters count, transaction count, etc. To know more, refer to the [Azure Documentation on Text Analytics](https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview) -```javascript +While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package +```typescript +const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); const { TextAnalyticsClient } = require("@azure/cognitiveservices-textanalytics"); -const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js"); - -async function main() { - const textAnalyticsKey = - process.env["textAnalyticsKey"] || ""; - const textAnalyticsEndPoint = - process.env["textAnalyticsEndPoint"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials( - textAnalyticsKey - ); - const client = new TextAnalyticsClient( - cognitiveServiceCredentials, - textAnalyticsEndPoint - ); - const options = { - showStats: true, - languageBatchInput: { - documents: [ - { - id: "1", - text: "Sample Text" - }, - { - id: "2", - text: "Texto de ejemplo" - } - ] - } +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new TextAnalyticsClient(creds, subscriptionId); + const showStats = true; + const languageBatchInput = { + documents: [{ + countryHint: "testcountryHint", + id: "testid", + text: "testtext" + }] }; - client - .detectLanguage(options) - .then(result => { - console.log("The result is:"); - result.documents.forEach(document => { - console.log(`Id: ${document.id}`); - console.log("Detected Languages:"); - document.detectedLanguages.forEach(dl => { - console.log(dl.name); - }); - console.log( - `Characters Count: ${document.statistics.charactersCount}` - ); - console.log( - `Transactions Count: ${document.statistics.transactionsCount}` - ); - }); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); - + client.detectLanguage(showStats, languageBatchInput).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` #### browser - Authentication, client creation and detectLanguage as an example written in JavaScript. +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` + ##### Sample code +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + - index.html ```html @@ -96,58 +70,36 @@ main(); @azure/cognitiveservices-textanalytics sample + @@ -158,4 +110,4 @@ main(); - [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%2Fcognitiveservices%2Fcognitiveservices-textanalytics%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-textanalytics/README.png) diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/rollup.config.js b/sdk/cognitiveservices/cognitiveservices-textanalytics/rollup.config.js index 5f99399d86ae..5e4ea8ebfe5a 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/rollup.config.js +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/rollup.config.js @@ -21,8 +21,8 @@ const config = { "@azure/ms-rest-azure-js": "msRestAzure" }, banner: `/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * 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. diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts index 3a71da695d0b..f4dd8f49793b 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts @@ -1,6 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * 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. @@ -499,12 +499,7 @@ export type KeyPhrasesResponse = KeyPhraseBatchResult & { /** * Contains response data for the sentiment operation. */ -export type SentimentResponse = { - /** - * The parsed response body. - */ - body: any; - +export type SentimentResponse = SentimentBatchResult & { /** * The underlying HTTP response. */ @@ -517,6 +512,6 @@ export type SentimentResponse = { /** * The response body as parsed JSON or XML */ - parsedBody: any; + parsedBody: SentimentBatchResult; }; }; diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/mappers.ts index ba8d4976b59f..a61bdd3d0f5c 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/mappers.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/mappers.ts @@ -1,6 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * 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. diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/parameters.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/parameters.ts index 91e0f034e416..b7fd7c211d00 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/parameters.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/parameters.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * 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 diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts index fca998335222..621045b1b55a 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * 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 @@ -122,13 +121,13 @@ class TextAnalyticsClient extends TextAnalyticsClientContext { /** * @param callback The callback */ - sentiment(callback: msRest.ServiceCallback): void; + sentiment(callback: msRest.ServiceCallback): void; /** * @param options The optional parameters * @param callback The callback */ - sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback): void; - sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback): void; + sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.sendOperationRequest( { options @@ -241,10 +240,9 @@ const sentimentOperationSpec: msRest.OperationSpec = { 200: { bodyMapper: Mappers.SentimentBatchResult }, - 500: { + default: { bodyMapper: Mappers.ErrorResponse - }, - default: {} + } }, serializer }; diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClientContext.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClientContext.ts index 9d3b8c238aef..c8784c7854b3 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClientContext.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClientContext.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * 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