Skip to content

Commit 1093f4a

Browse files
authored
[apimanagement] Update to use snippets (#32475)
### Packages impacted by this PR - @azure/arm-apimanagement - @azure/api-management-custom-widgets-scaffolder - @azure/api-management-custom-widgets-tools ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all `apimanagement` packages to use snippets. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 52eecea commit 1093f4a

File tree

10 files changed

+82
-37
lines changed

10 files changed

+82
-37
lines changed

sdk/apimanagement/api-management-custom-widgets-scaffolder/bin/execute.cjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class UI {
253253
constructor(opts) {
254254
var _a;
255255
this.width = opts.width;
256-
this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
256+
this.wrap = (_a = opts.wrap) !== null && _a !== undefined ? _a : true;
257257
this.rows = [];
258258
}
259259
span(...args) {
@@ -523,8 +523,8 @@ let mixin;
523523
function cliui(opts, _mixin) {
524524
mixin = _mixin;
525525
return new UI({
526-
width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
527-
wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
526+
width: (opts === null || opts === undefined ? undefined : opts.width) || getWindowWidth(),
527+
wrap: opts === null || opts === undefined ? undefined : opts.wrap
528528
});
529529
}
530530

@@ -875,7 +875,7 @@ const buildGetConfig = (gray, red) => {
875875
}
876876
else {
877877
gray("Retrieved from the command parameters");
878-
Object.entries(configPartial).forEach(([key, value]) => { var _a; return value != null && gray(`${(_a = fieldIdToName[key]) !== null && _a !== void 0 ? _a : key}: ${value}`); });
878+
Object.entries(configPartial).forEach(([key, value]) => { var _a; return value != null && gray(`${(_a = fieldIdToName[key]) !== null && _a !== undefined ? _a : key}: ${value}`); });
879879
return configPartial;
880880
}
881881
};

sdk/apimanagement/api-management-custom-widgets-scaffolder/bin/execute.cjs.map

+1-1
Large diffs are not rendered by default.

sdk/apimanagement/api-management-custom-widgets-scaffolder/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
5151
"unit-test:browser": "echo skipped",
5252
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
53-
"update-snippets": "echo skipped"
53+
"update-snippets": "dev-tool run update-snippets"
5454
},
5555
"devDependencies": {
5656
"@azure/dev-tool": "^1.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { describe } from "vitest";
5+
6+
describe("snippets", () => {});

sdk/apimanagement/api-management-custom-widgets-tools/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
4747
"unit-test:browser": "npm run build:test && dev-tool run test:vitest --no-test-proxy --browser",
4848
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
49-
"update-snippets": "echo skipped"
49+
"update-snippets": "dev-tool run update-snippets"
5050
},
5151
"devDependencies": {
5252
"@azure/dev-tool": "^1.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { describe } from "vitest";
5+
6+
describe("snippets", () => {});

sdk/apimanagement/arm-apimanagement/README.md

+22-13
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,32 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica
4848

4949
For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
5050

51-
```javascript
52-
const { ApiManagementClient } = require("@azure/arm-apimanagement");
53-
const { DefaultAzureCredential } = require("@azure/identity");
54-
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
51+
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.
52+
53+
```ts snippet:ReadmeSampleCreateClient_Node
54+
import { ApiManagementClient } from "@azure/arm-apimanagement";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new ApiManagementClient(new DefaultAzureCredential(), subscriptionId);
58-
59-
// For client-side applications running in the browser, use this code instead:
60-
// const credential = new InteractiveBrowserCredential({
61-
// tenantId: "<YOUR_TENANT_ID>",
62-
// clientId: "<YOUR_CLIENT_ID>"
63-
// });
64-
// const client = new ApiManagementClient(credential, subscriptionId);
6559
```
6660

61+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
62+
63+
```ts snippet:ReadmeSampleCreateClient_Browser
64+
import { InteractiveBrowserCredential } from "@azure/identity";
65+
import { ApiManagementClient } from "@azure/arm-apimanagement";
66+
67+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
68+
const credential = new InteractiveBrowserCredential({
69+
tenantId: "<YOUR_TENANT_ID>",
70+
clientId: "<YOUR_CLIENT_ID>",
71+
});
72+
const client = new ApiManagementClient(credential, subscriptionId);
73+
```
6774

6875
### JavaScript Bundle
76+
6977
To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
7078

7179
## Key concepts
@@ -80,8 +88,9 @@ To use this client library in the browser, first you need to use a bundler. For
8088

8189
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
8290

83-
```javascript
84-
const { setLogLevel } = require("@azure/logger");
91+
```ts snippet:SetLogLevel
92+
import { setLogLevel } from "@azure/logger";
93+
8594
setLogLevel("info");
8695
```
8796

sdk/apimanagement/arm-apimanagement/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@azure/core-lro": "^2.7.2",
1515
"@azure/core-paging": "^1.6.2",
1616
"@azure/core-rest-pipeline": "^1.18.0",
17-
"tslib": "^2.2.0"
17+
"tslib": "^2.8.1"
1818
},
1919
"keywords": [
2020
"node",
@@ -75,7 +75,7 @@
7575
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
7676
"unit-test:browser": "echo skipped",
7777
"unit-test:node": "dev-tool run test:vitest",
78-
"update-snippets": "echo skipped"
78+
"update-snippets": "dev-tool run update-snippets"
7979
},
8080
"sideEffects": false,
8181
"//metadata": {

sdk/apimanagement/arm-apimanagement/test/apimanagement_examples.spec.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
*/
88

99
import { createTestCredential } from "@azure-tools/test-credential";
10-
import {
11-
delay,
12-
env,
13-
isPlaybackMode,
14-
Recorder,
15-
RecorderStartOptions,
16-
} from "@azure-tools/test-recorder";
10+
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
11+
import { delay, env, isPlaybackMode, Recorder } from "@azure-tools/test-recorder";
1712
import { ApiManagementClient } from "../src/apiManagementClient.js";
1813
import { describe, it, assert, beforeEach, afterEach } from "vitest";
1914

@@ -85,7 +80,7 @@ describe("Apimanagement test", () => {
8580

8681
it("apiManagementService listByResourceGroup test", async () => {
8782
const resArray = new Array();
88-
for await (let item of client.apiManagementService.listByResourceGroup(resourceGroupName)) {
83+
for await (const item of client.apiManagementService.listByResourceGroup(resourceGroupName)) {
8984
resArray.push(item);
9085
}
9186
assert.equal(resArray.length, 1);
@@ -96,8 +91,8 @@ describe("Apimanagement test", () => {
9691
while (count < 20) {
9792
count++;
9893
const res = await client.apiManagementService.get(resourceGroupName, serviceName);
99-
if (res.provisioningState == "Succeeded") {
100-
const res = await client.apiManagementService.beginUpdateAndWait(
94+
if (res.provisioningState === "Succeeded") {
95+
const updateResult = await client.apiManagementService.beginUpdateAndWait(
10196
resourceGroupName,
10297
serviceName,
10398
{
@@ -107,7 +102,7 @@ describe("Apimanagement test", () => {
107102
},
108103
testPollingOptions,
109104
);
110-
assert.equal(res.type, "Microsoft.ApiManagement/service");
105+
assert.equal(updateResult.type, "Microsoft.ApiManagement/service");
111106
break;
112107
} else {
113108
// The resource is activating
@@ -122,7 +117,7 @@ describe("Apimanagement test", () => {
122117

123118
it("backend list test", async () => {
124119
const resArray = new Array();
125-
for await (let item of client.backend.listByService(resourceGroupName, serviceName, {
120+
for await (const item of client.backend.listByService(resourceGroupName, serviceName, {
126121
top: 1,
127122
})) {
128123
resArray.push(item);
@@ -132,7 +127,7 @@ describe("Apimanagement test", () => {
132127

133128
it("backend delete test", async () => {
134129
const resArray = new Array();
135-
for await (let item of client.backend.listByService(resourceGroupName, serviceName)) {
130+
for await (const item of client.backend.listByService(resourceGroupName, serviceName)) {
136131
resArray.push(item);
137132
}
138133
assert.equal(resArray.length, 0);
@@ -143,9 +138,11 @@ describe("Apimanagement test", () => {
143138
while (count < 20) {
144139
count++;
145140
const res = await client.apiManagementService.get(resourceGroupName, serviceName);
146-
if (res.provisioningState == "Succeeded") {
141+
if (res.provisioningState === "Succeeded") {
147142
const resArray = new Array();
148-
for await (let item of client.apiManagementService.listByResourceGroup(resourceGroupName)) {
143+
for await (const item of client.apiManagementService.listByResourceGroup(
144+
resourceGroupName,
145+
)) {
149146
resArray.push(item);
150147
}
151148
assert.equal(resArray.length, 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { describe, it } from "vitest";
5+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
6+
import { ApiManagementClient } from "@azure/arm-apimanagement";
7+
import { setLogLevel } from "@azure/logger";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient_Node", async () => {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new ApiManagementClient(new DefaultAzureCredential(), subscriptionId);
13+
});
14+
15+
it("ReadmeSampleCreateClient_Browser", async () => {
16+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
17+
const credential = new InteractiveBrowserCredential({
18+
tenantId: "<YOUR_TENANT_ID>",
19+
clientId: "<YOUR_CLIENT_ID>",
20+
});
21+
const client = new ApiManagementClient(credential, subscriptionId);
22+
});
23+
24+
it("SetLogLevel", async () => {
25+
setLogLevel("info");
26+
});
27+
});

0 commit comments

Comments
 (0)