Skip to content

Commit 52eecea

Browse files
authored
[apicenter] Update apicenter projects to use snippets (#32473)
### Packages impacted by this PR - @azure/arm-apicenter ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `apicenter` to use snippets extraction. ### 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 d635c4e commit 52eecea

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

sdk/apicenter/arm-apicenter/README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,28 @@ 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://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
5050

51-
```javascript
52-
const { AzureAPICenter } = require("@azure/arm-apicenter");
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 { AzureAPICenter } from "@azure/arm-apicenter";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new AzureAPICenter(new DefaultAzureCredential(), subscriptionId);
59+
```
60+
61+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
5862

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 AzureAPICenter(credential, subscriptionId);
63+
```ts snippet:ReadmeSampleCreateClient_Browser
64+
import { InteractiveBrowserCredential } from "@azure/identity";
65+
import { AzureAPICenter } from "@azure/arm-apicenter";
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 AzureAPICenter(credential, subscriptionId);
6573
```
6674

6775
### JavaScript Bundle
@@ -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/apicenter/arm-apicenter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -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": {
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 { setLogLevel } from "@azure/logger";
6+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
7+
import { AzureAPICenter } from "@azure/arm-apicenter";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient_Node", async () => {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new AzureAPICenter(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 AzureAPICenter(credential, subscriptionId);
22+
});
23+
24+
it("SetLogLevel", async () => {
25+
setLogLevel("info");
26+
});
27+
});

0 commit comments

Comments
 (0)