@autorest/typescript 6.0.0-beta.14 → 6.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +41 -5
- package/dist/src/autorestSession.d.ts +12 -4
- package/dist/src/autorestSession.d.ts.map +1 -1
- package/dist/src/autorestSession.js +3 -9
- package/dist/src/autorestSession.js.map +1 -1
- package/dist/src/conflictResolver.d.ts.map +1 -1
- package/dist/src/conflictResolver.js.map +1 -1
- package/dist/src/generators/clientFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/clientFileGenerator.js +181 -31
- package/dist/src/generators/clientFileGenerator.js.map +1 -1
- package/dist/src/generators/indexGenerator.d.ts.map +1 -1
- package/dist/src/generators/indexGenerator.js +70 -9
- package/dist/src/generators/indexGenerator.js.map +1 -1
- package/dist/src/generators/modelsGenerator.d.ts.map +1 -1
- package/dist/src/generators/modelsGenerator.js +20 -2
- package/dist/src/generators/modelsGenerator.js.map +1 -1
- package/dist/src/generators/operationGenerator.d.ts.map +1 -1
- package/dist/src/generators/operationGenerator.js +10 -8
- package/dist/src/generators/operationGenerator.js.map +1 -1
- package/dist/src/generators/samples/sampleEnv.hbs +4 -0
- package/dist/src/generators/samples/sampleEnvGenerator.d.ts +3 -0
- package/dist/src/generators/samples/sampleEnvGenerator.d.ts.map +1 -0
- package/dist/src/generators/samples/sampleEnvGenerator.js +17 -0
- package/dist/src/generators/samples/sampleEnvGenerator.js.map +1 -0
- package/dist/src/generators/samples/sampleGenerator.d.ts +13 -0
- package/dist/src/generators/samples/sampleGenerator.d.ts.map +1 -0
- package/dist/src/generators/samples/sampleGenerator.js +43 -0
- package/dist/src/generators/samples/sampleGenerator.js.map +1 -0
- package/dist/src/generators/static/apiExtractorConfig.js +2 -2
- package/dist/src/generators/static/apiExtractorConfig.js.map +1 -1
- package/dist/src/generators/static/esLintConfigGenerator.d.ts +3 -0
- package/dist/src/generators/static/esLintConfigGenerator.d.ts.map +1 -0
- package/dist/src/generators/static/esLintConfigGenerator.js +26 -0
- package/dist/src/generators/static/esLintConfigGenerator.js.map +1 -0
- package/dist/src/generators/static/{README.md.hbs → hlcREADME.md.hbs} +23 -0
- package/dist/src/generators/static/karma.conf.js.hbs +141 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.d.ts +3 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.js +23 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.js.map +1 -0
- package/dist/src/generators/static/packageFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/packageFileGenerator.js +174 -48
- package/dist/src/generators/static/packageFileGenerator.js.map +1 -1
- package/dist/src/generators/static/readmeFileGenerator.d.ts +2 -2
- package/dist/src/generators/static/readmeFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/readmeFileGenerator.js +35 -17
- package/dist/src/generators/static/readmeFileGenerator.js.map +1 -1
- package/dist/src/generators/static/rlcREADME.md.hbs +71 -0
- package/dist/src/generators/static/rollupConfigFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/rollupConfigFileGenerator.js +12 -71
- package/dist/src/generators/static/rollupConfigFileGenerator.js.map +1 -1
- package/dist/src/generators/static/samples.ts.hbs +49 -0
- package/dist/src/generators/static/tsConfigFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/tsConfigFileGenerator.js +40 -18
- package/dist/src/generators/static/tsConfigFileGenerator.js.map +1 -1
- package/dist/src/generators/test/envBrowserFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/envBrowserFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/envBrowserFileGenerator.js +15 -0
- package/dist/src/generators/test/envBrowserFileGenerator.js.map +1 -0
- package/dist/src/generators/test/envFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/envFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/envFileGenerator.js +23 -0
- package/dist/src/generators/test/envFileGenerator.js.map +1 -0
- package/dist/src/generators/test/recordedClientFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/recordedClientFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/recordedClientFileGenerator.js +23 -0
- package/dist/src/generators/test/recordedClientFileGenerator.js.map +1 -0
- package/dist/src/generators/test/rlcEnv.ts.hbs +3 -0
- package/dist/src/generators/test/rlcRecordedClient.ts.hbs +35 -0
- package/dist/src/generators/test/rlcSampleTest.spec.ts.hbs +19 -0
- package/dist/src/generators/{static → test}/sampleTest.ts.hbs +0 -0
- package/dist/src/generators/test/sampleTestGenerator.d.ts.map +1 -1
- package/dist/src/generators/test/sampleTestGenerator.js +23 -7
- package/dist/src/generators/test/sampleTestGenerator.js.map +1 -1
- package/dist/src/generators/utils/pagingOperations.d.ts +5 -0
- package/dist/src/generators/utils/pagingOperations.d.ts.map +1 -1
- package/dist/src/generators/utils/pagingOperations.js +2 -1
- package/dist/src/generators/utils/pagingOperations.js.map +1 -1
- package/dist/src/main.d.ts +2 -2
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +3 -3
- package/dist/src/main.js.map +1 -1
- package/dist/src/models/clientDetails.d.ts +7 -0
- package/dist/src/models/clientDetails.d.ts.map +1 -1
- package/dist/src/models/modelDetails.d.ts +2 -2
- package/dist/src/models/modelDetails.d.ts.map +1 -1
- package/dist/src/models/operationDetails.d.ts +1 -0
- package/dist/src/models/operationDetails.d.ts.map +1 -1
- package/dist/src/models/sampleDetails.d.ts +22 -0
- package/dist/src/models/sampleDetails.d.ts.map +1 -0
- package/dist/src/models/sampleDetails.js +3 -0
- package/dist/src/models/sampleDetails.js.map +1 -0
- package/dist/src/restLevelClient/generateClient.d.ts +1 -1
- package/dist/src/restLevelClient/generateClient.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateClient.js +81 -163
- package/dist/src/restLevelClient/generateClient.js.map +1 -1
- package/dist/src/restLevelClient/generateClientDefinition.d.ts +6 -0
- package/dist/src/restLevelClient/generateClientDefinition.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateClientDefinition.js +231 -0
- package/dist/src/restLevelClient/generateClientDefinition.js.map +1 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.d.ts +8 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.js +70 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.js.map +1 -0
- package/dist/src/restLevelClient/generateObjectTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateObjectTypes.js.map +1 -1
- package/dist/src/restLevelClient/generatePagingHelper.d.ts.map +1 -1
- package/dist/src/restLevelClient/generatePagingHelper.js +2 -1
- package/dist/src/restLevelClient/generatePagingHelper.js.map +1 -1
- package/dist/src/restLevelClient/generateParameterTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateParameterTypes.js +186 -36
- package/dist/src/restLevelClient/generateParameterTypes.js.map +1 -1
- package/dist/src/restLevelClient/generatePollingHelper.d.ts.map +1 -1
- package/dist/src/restLevelClient/generatePollingHelper.js +3 -1
- package/dist/src/restLevelClient/generatePollingHelper.js.map +1 -1
- package/dist/src/restLevelClient/generateResponseTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateResponseTypes.js +13 -7
- package/dist/src/restLevelClient/generateResponseTypes.js.map +1 -1
- package/dist/src/restLevelClient/generateRestLevel.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateRestLevel.js +26 -4
- package/dist/src/restLevelClient/generateRestLevel.js.map +1 -1
- package/dist/src/restLevelClient/generateSchemaTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateSchemaTypes.js +5 -2
- package/dist/src/restLevelClient/generateSchemaTypes.js.map +1 -1
- package/dist/src/restLevelClient/generateTopLevelIndexFile.d.ts +4 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.js +41 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.js.map +1 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.d.ts +10 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.d.ts.map +1 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.js +64 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.js.map +1 -0
- package/dist/src/restLevelClient/interfaces.d.ts +24 -0
- package/dist/src/restLevelClient/interfaces.d.ts.map +1 -0
- package/dist/src/restLevelClient/interfaces.js +3 -0
- package/dist/src/restLevelClient/interfaces.js.map +1 -0
- package/dist/src/restLevelClient/operationHelpers.d.ts.map +1 -1
- package/dist/src/restLevelClient/operationHelpers.js +4 -1
- package/dist/src/restLevelClient/operationHelpers.js.map +1 -1
- package/dist/src/restLevelClient/schemaHelpers.d.ts.map +1 -1
- package/dist/src/restLevelClient/schemaHelpers.js +4 -1
- package/dist/src/restLevelClient/schemaHelpers.js.map +1 -1
- package/dist/src/transforms/operationTransforms.d.ts.map +1 -1
- package/dist/src/transforms/operationTransforms.js +1 -0
- package/dist/src/transforms/operationTransforms.js.map +1 -1
- package/dist/src/transforms/samplesTransforms.d.ts +7 -0
- package/dist/src/transforms/samplesTransforms.d.ts.map +1 -0
- package/dist/src/transforms/samplesTransforms.js +283 -0
- package/dist/src/transforms/samplesTransforms.js.map +1 -0
- package/dist/src/transforms/transforms.d.ts +1 -2
- package/dist/src/transforms/transforms.d.ts.map +1 -1
- package/dist/src/transforms/transforms.js +4 -3
- package/dist/src/transforms/transforms.js.map +1 -1
- package/dist/src/typescriptGenerator.d.ts +2 -2
- package/dist/src/typescriptGenerator.d.ts.map +1 -1
- package/dist/src/typescriptGenerator.js +19 -8
- package/dist/src/typescriptGenerator.js.map +1 -1
- package/dist/src/utils/autorestOptions.d.ts +2 -2
- package/dist/src/utils/autorestOptions.d.ts.map +1 -1
- package/dist/src/utils/autorestOptions.js +107 -30
- package/dist/src/utils/autorestOptions.js.map +1 -1
- package/dist/src/utils/nameUtils.d.ts +6 -2
- package/dist/src/utils/nameUtils.d.ts.map +1 -1
- package/dist/src/utils/nameUtils.js +9 -5
- package/dist/src/utils/nameUtils.js.map +1 -1
- package/dist/src/utils/schemaHelpers.js +8 -3
- package/dist/src/utils/schemaHelpers.js.map +1 -1
- package/package.json +16 -10
- package/src/autorestSession.ts +20 -16
- package/src/conflictResolver.ts +0 -1
- package/src/generators/clientFileGenerator.ts +264 -33
- package/src/generators/indexGenerator.ts +78 -9
- package/src/generators/modelsGenerator.ts +21 -1
- package/src/generators/operationGenerator.ts +11 -9
- package/src/generators/samples/sampleEnv.hbs +4 -0
- package/src/generators/samples/sampleEnvGenerator.ts +14 -0
- package/src/generators/samples/sampleGenerator.ts +50 -0
- package/src/generators/static/apiExtractorConfig.ts +2 -2
- package/src/generators/static/esLintConfigGenerator.ts +24 -0
- package/src/generators/static/{README.md.hbs → hlcREADME.md.hbs} +23 -0
- package/src/generators/static/karma.conf.js.hbs +141 -0
- package/src/generators/static/karmaConfigFileGenerator.ts +20 -0
- package/src/generators/static/packageFileGenerator.ts +187 -48
- package/src/generators/static/readmeFileGenerator.ts +64 -35
- package/src/generators/static/rlcREADME.md.hbs +71 -0
- package/src/generators/static/rollupConfigFileGenerator.ts +13 -71
- package/src/generators/static/samples.ts.hbs +49 -0
- package/src/generators/static/tsConfigFileGenerator.ts +47 -20
- package/src/generators/test/envBrowserFileGenerator.ts +14 -0
- package/src/generators/test/envFileGenerator.ts +22 -0
- package/src/generators/test/recordedClientFileGenerator.ts +22 -0
- package/src/generators/test/rlcEnv.ts.hbs +3 -0
- package/src/generators/test/rlcRecordedClient.ts.hbs +35 -0
- package/src/generators/test/rlcSampleTest.spec.ts.hbs +19 -0
- package/src/generators/{static → test}/sampleTest.ts.hbs +0 -0
- package/src/generators/test/sampleTestGenerator.ts +23 -8
- package/src/generators/utils/pagingOperations.ts +1 -1
- package/src/main.ts +8 -5
- package/src/models/clientDetails.ts +8 -0
- package/src/models/modelDetails.ts +2 -2
- package/src/models/operationDetails.ts +1 -0
- package/src/models/sampleDetails.ts +22 -0
- package/src/restLevelClient/generateClient.ts +99 -250
- package/src/restLevelClient/generateClientDefinition.ts +343 -0
- package/src/restLevelClient/generateMethodShortcuts.ts +121 -0
- package/src/restLevelClient/generateObjectTypes.ts +1 -3
- package/src/restLevelClient/generatePagingHelper.ts +3 -2
- package/src/restLevelClient/generateParameterTypes.ts +295 -70
- package/src/restLevelClient/generatePollingHelper.ts +3 -3
- package/src/restLevelClient/generateResponseTypes.ts +13 -7
- package/src/restLevelClient/generateRestLevel.ts +32 -7
- package/src/restLevelClient/generateSchemaTypes.ts +5 -3
- package/src/restLevelClient/generateTopLevelIndexFile.ts +41 -0
- package/src/restLevelClient/helpers/operationHelpers.ts +93 -0
- package/src/restLevelClient/interfaces.ts +26 -0
- package/src/restLevelClient/operationHelpers.ts +8 -2
- package/src/restLevelClient/schemaHelpers.ts +4 -2
- package/src/transforms/operationTransforms.ts +1 -0
- package/src/transforms/samplesTransforms.ts +300 -0
- package/src/transforms/transforms.ts +6 -6
- package/src/typescriptGenerator.ts +20 -11
- package/src/utils/autorestOptions.ts +170 -59
- package/src/utils/nameUtils.ts +16 -8
- package/src/utils/schemaHelpers.ts +2 -2
- package/dist/src/generators/clientContextFileGenerator.d.ts +0 -5
- package/dist/src/generators/clientContextFileGenerator.d.ts.map +0 -1
- package/dist/src/generators/clientContextFileGenerator.js +0 -263
- package/dist/src/generators/clientContextFileGenerator.js.map +0 -1
- package/dist/src/restLevelClient/helpers/getOperationParameters.d.ts +0 -6
- package/dist/src/restLevelClient/helpers/getOperationParameters.d.ts.map +0 -1
- package/dist/src/restLevelClient/helpers/getOperationParameters.js +0 -29
- package/dist/src/restLevelClient/helpers/getOperationParameters.js.map +0 -1
- package/src/generators/clientContextFileGenerator.ts +0 -405
- package/src/restLevelClient/helpers/getOperationParameters.ts +0 -34
|
@@ -5,9 +5,10 @@ import { Project } from "ts-morph";
|
|
|
5
5
|
import * as hbs from "handlebars";
|
|
6
6
|
import * as fs from "fs";
|
|
7
7
|
import * as path from "path";
|
|
8
|
-
import { ClientDetails } from "../../models/clientDetails";
|
|
9
8
|
import { getAutorestOptions } from "../../autorestSession";
|
|
10
|
-
import {
|
|
9
|
+
import { Info, Languages } from "@autorest/codemodel";
|
|
10
|
+
import { getLanguageMetadata } from "../../utils/languageHelpers";
|
|
11
|
+
import { normalizeName, NameType } from "../../utils/nameUtils";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Meta data information about the service, the package, and the client.
|
|
@@ -50,24 +51,38 @@ interface Metadata {
|
|
|
50
51
|
/** Indicates if the package is a test/releasable package. */
|
|
51
52
|
isReleasablePackage?: boolean;
|
|
52
53
|
/** indicate if the package is management plane SDK */
|
|
53
|
-
azureArm?: boolean
|
|
54
|
+
azureArm?: boolean;
|
|
55
|
+
/** The URL for the service document */
|
|
56
|
+
serviceDocURL?: string;
|
|
57
|
+
/** The dependency info for this service */
|
|
58
|
+
dependencyDescription?: string;
|
|
59
|
+
dependencyLink?: string;
|
|
60
|
+
/** Indicates if the package is a multi-client */
|
|
61
|
+
hasMultiClients?: boolean;
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
65
|
* Returns meta data information about the service, the package, and the client.
|
|
58
|
-
* @param
|
|
59
|
-
* @param packageDetails - the package details
|
|
66
|
+
* @param codeModel - include the client details
|
|
60
67
|
* @returns inferred metadata about the service, the package, and the client
|
|
61
68
|
*/
|
|
62
69
|
function createMetadata(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
azureOutputDirectory?: string,
|
|
66
|
-
addCredentials?: boolean,
|
|
67
|
-
azureArm?: boolean,
|
|
68
|
-
isTestPackage?: boolean
|
|
70
|
+
codeModelLanguage: Languages,
|
|
71
|
+
codeModelInfo: Info
|
|
69
72
|
): Metadata {
|
|
70
|
-
const
|
|
73
|
+
const {
|
|
74
|
+
packageDetails,
|
|
75
|
+
azureOutputDirectory,
|
|
76
|
+
addCredentials,
|
|
77
|
+
azureArm,
|
|
78
|
+
isTestPackage,
|
|
79
|
+
productDocLink,
|
|
80
|
+
dependencyInfo,
|
|
81
|
+
multiClient,
|
|
82
|
+
batch
|
|
83
|
+
} = getAutorestOptions();
|
|
84
|
+
|
|
85
|
+
const azureHuh = packageDetails?.scopeName === "azure" || packageDetails?.scopeName === "azure-rest";
|
|
71
86
|
const repoURL = azureHuh
|
|
72
87
|
? "https://github.com/Azure/azure-sdk-for-js"
|
|
73
88
|
: undefined;
|
|
@@ -79,9 +94,9 @@ function createMetadata(
|
|
|
79
94
|
const names = relativePackageSourcePath?.split("/").slice(1);
|
|
80
95
|
const packageParentDirectoryName = names?.[0];
|
|
81
96
|
const packageDirectoryName = names?.[1];
|
|
82
|
-
|
|
83
|
-
const clientPackageName = packageDetails
|
|
84
|
-
const serviceTitle =
|
|
97
|
+
|
|
98
|
+
const clientPackageName = packageDetails?.name;
|
|
99
|
+
const { clientClassName, serviceTitle } = getClientAndServiceName(codeModelLanguage, codeModelInfo);
|
|
85
100
|
const simpleServiceName =
|
|
86
101
|
/**
|
|
87
102
|
* It is a required convention in Azure swaggers for their titles to end with
|
|
@@ -100,6 +115,12 @@ function createMetadata(
|
|
|
100
115
|
: simpleServiceName;
|
|
101
116
|
const identityPackageURL =
|
|
102
117
|
repoURL && `${repoURL}/tree/main/sdk/identity/identity`;
|
|
118
|
+
|
|
119
|
+
var apiRefUrlQueryParameter: string = "";
|
|
120
|
+
if (packageDetails?.version.includes("beta")) {
|
|
121
|
+
apiRefUrlQueryParameter = "?view=azure-node-preview";
|
|
122
|
+
}
|
|
123
|
+
|
|
103
124
|
return {
|
|
104
125
|
serviceName: serviceName,
|
|
105
126
|
clientPackageName: clientPackageName,
|
|
@@ -113,13 +134,13 @@ function createMetadata(
|
|
|
113
134
|
: packageSourceURL && `${packageSourceURL}/samples`,
|
|
114
135
|
impressionURL: azureHuh
|
|
115
136
|
? packageParentDirectoryName &&
|
|
116
|
-
|
|
117
|
-
|
|
137
|
+
packageDirectoryName &&
|
|
138
|
+
`https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2F${packageParentDirectoryName}%2F${packageDirectoryName}%2FREADME.png`
|
|
118
139
|
: undefined,
|
|
119
140
|
clientDescriptiveName: `${serviceName} client`,
|
|
120
|
-
description:
|
|
141
|
+
description: codeModelInfo?.description,
|
|
121
142
|
apiRefURL: azureHuh
|
|
122
|
-
? `https://docs.microsoft.com/javascript/api/${clientPackageName}`
|
|
143
|
+
? `https://docs.microsoft.com/javascript/api/${clientPackageName}${apiRefUrlQueryParameter}`
|
|
123
144
|
: undefined,
|
|
124
145
|
packageNPMURL: `https://www.npmjs.com/package/${clientPackageName}`,
|
|
125
146
|
contributingGuideURL: repoURL && `${repoURL}/blob/main/CONTRIBUTING.md`,
|
|
@@ -127,36 +148,31 @@ function createMetadata(
|
|
|
127
148
|
addCredentials,
|
|
128
149
|
identityPackageURL,
|
|
129
150
|
isReleasablePackage: !isTestPackage,
|
|
130
|
-
azureArm: azureArm
|
|
151
|
+
azureArm: azureArm,
|
|
152
|
+
serviceDocURL: productDocLink,
|
|
153
|
+
dependencyDescription: dependencyInfo?.description,
|
|
154
|
+
dependencyLink: dependencyInfo?.link,
|
|
155
|
+
hasMultiClients: multiClient && batch && batch.length > 1
|
|
131
156
|
};
|
|
132
157
|
}
|
|
133
158
|
|
|
134
159
|
export function generateReadmeFile(
|
|
135
|
-
|
|
160
|
+
codeModelLanguage: Languages,
|
|
161
|
+
codeModelInfo: Info,
|
|
136
162
|
project: Project
|
|
137
163
|
) {
|
|
138
164
|
const {
|
|
139
|
-
packageDetails,
|
|
140
|
-
azureOutputDirectory,
|
|
141
165
|
generateMetadata,
|
|
142
|
-
|
|
143
|
-
azureArm,
|
|
144
|
-
isTestPackage
|
|
166
|
+
restLevelClient,
|
|
145
167
|
} = getAutorestOptions();
|
|
146
168
|
|
|
147
169
|
if (!generateMetadata) {
|
|
148
170
|
return;
|
|
149
171
|
}
|
|
150
172
|
|
|
151
|
-
const metadata = createMetadata(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
azureOutputDirectory,
|
|
155
|
-
addCredentials,
|
|
156
|
-
azureArm,
|
|
157
|
-
isTestPackage
|
|
158
|
-
);
|
|
159
|
-
const file = fs.readFileSync(path.join(__dirname, "README.md.hbs"), {
|
|
173
|
+
const metadata = createMetadata(codeModelLanguage, codeModelInfo);
|
|
174
|
+
const templateFile = !restLevelClient ? "hlcREADME.md.hbs" : "rlcREADME.md.hbs";
|
|
175
|
+
const file = fs.readFileSync(path.join(__dirname, templateFile), {
|
|
160
176
|
encoding: "utf-8"
|
|
161
177
|
});
|
|
162
178
|
const readmeFileContents = hbs.compile(file, { noEscape: true });
|
|
@@ -164,3 +180,16 @@ export function generateReadmeFile(
|
|
|
164
180
|
overwrite: true
|
|
165
181
|
});
|
|
166
182
|
}
|
|
183
|
+
|
|
184
|
+
function getClientAndServiceName(codeModelLanguage: Languages,
|
|
185
|
+
codeModelInfo: Info) {
|
|
186
|
+
const { name: clientName } = getLanguageMetadata(codeModelLanguage);
|
|
187
|
+
const className = normalizeName(
|
|
188
|
+
clientName,
|
|
189
|
+
NameType.Class,
|
|
190
|
+
true /** shouldGuard */
|
|
191
|
+
);
|
|
192
|
+
const clientClassName = className;
|
|
193
|
+
const serviceTitle = codeModelInfo?.title ?? clientClassName;
|
|
194
|
+
return { clientClassName, serviceTitle };
|
|
195
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# {{ clientDescriptiveName }} library for JavaScript
|
|
2
|
+
|
|
3
|
+
{{ description }}
|
|
4
|
+
|
|
5
|
+
**Please rely heavily on {{#if serviceDocURL}}[the service's documentation]({{ serviceDocURL }}) and {{/if}}our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
|
|
6
|
+
|
|
7
|
+
Key links:
|
|
8
|
+
|
|
9
|
+
{{#if packageSourceURL}}
|
|
10
|
+
- [Source code]({{ packageSourceURL }})
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if packageNPMURL}}
|
|
13
|
+
- [Package (NPM)]({{ packageNPMURL }})
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if apiRefURL}}
|
|
16
|
+
- [API reference documentation]({{ apiRefURL }})
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{#if serviceDocURL}}
|
|
19
|
+
- [Product documentation]({{ serviceDocURL }})
|
|
20
|
+
{{/if}}
|
|
21
|
+
{{#if samplesURL}}
|
|
22
|
+
- [Samples]({{ samplesURL }})
|
|
23
|
+
{{/if}}
|
|
24
|
+
|
|
25
|
+
## Getting started
|
|
26
|
+
|
|
27
|
+
### Currently supported environments
|
|
28
|
+
|
|
29
|
+
- Node.js version 14.x.x or higher
|
|
30
|
+
|
|
31
|
+
### Prerequisites
|
|
32
|
+
|
|
33
|
+
- You must have an [Azure subscription](https://docs.microsoft.com/en-us/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token){{#if dependencyLink}} and follow [these]({{ dependencyLink }}) instructions{{/if}} to use this package.
|
|
34
|
+
|
|
35
|
+
### Install the `{{ clientPackageName }}` package
|
|
36
|
+
|
|
37
|
+
Install the {{ clientDescriptiveName }} REST client library for JavaScript with `npm`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install {{ clientPackageName }}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Create and authenticate a `{{ clientClassName }}`
|
|
44
|
+
|
|
45
|
+
To use an [Azure Active Directory (AAD) token credential](https://docs.microsoft.com/en-us/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token),
|
|
46
|
+
provide an instance of the desired credential type obtained from the
|
|
47
|
+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
|
|
48
|
+
|
|
49
|
+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity) {{#if dependencyLink}} and
|
|
50
|
+
[{{dependencyDescription }}]({{ dependencyLink }}){{/if}}
|
|
51
|
+
|
|
52
|
+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
|
|
53
|
+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
|
|
54
|
+
can be used to authenticate the client:
|
|
55
|
+
|
|
56
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
|
|
57
|
+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
58
|
+
|
|
59
|
+
## Troubleshooting
|
|
60
|
+
|
|
61
|
+
### Logging
|
|
62
|
+
|
|
63
|
+
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`:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { setLogLevel } from "@azure/logger";
|
|
67
|
+
|
|
68
|
+
setLogLevel("info");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
@@ -5,12 +5,17 @@ import { Project } from "ts-morph";
|
|
|
5
5
|
import { getAutorestOptions } from "../../autorestSession";
|
|
6
6
|
|
|
7
7
|
export function generateRollupConfig(project: Project) {
|
|
8
|
-
const { generateMetadata } = getAutorestOptions();
|
|
8
|
+
const { generateMetadata, restLevelClient, azureSdkForJs } = getAutorestOptions();
|
|
9
9
|
|
|
10
10
|
if (!generateMetadata) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// when it's generating rlc codes, only generate rollup config in codegen test
|
|
15
|
+
if (restLevelClient && azureSdkForJs) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
const rollupFile = project.createSourceFile("rollup.config.js", undefined, {
|
|
15
20
|
overwrite: true
|
|
16
21
|
});
|
|
@@ -24,62 +29,14 @@ export function generateRollupConfig(project: Project) {
|
|
|
24
29
|
|
|
25
30
|
import nodeBuiltins from "builtin-modules";
|
|
26
31
|
|
|
27
|
-
/**
|
|
28
|
-
* Gets the proper configuration needed for rollup's commonJS plugin for @opentelemetry/api.
|
|
29
|
-
*
|
|
30
|
-
* NOTE: this manual configuration is only needed because OpenTelemetry uses an
|
|
31
|
-
* __exportStar downleveled helper function to declare its exports which confuses
|
|
32
|
-
* rollup's automatic discovery mechanism.
|
|
33
|
-
*
|
|
34
|
-
* @returns an object reference that can be \`...\`'d into your cjs() configuration.
|
|
35
|
-
*/
|
|
36
|
-
export function openTelemetryCommonJs() {
|
|
37
|
-
const namedExports = {};
|
|
38
|
-
|
|
39
|
-
for (const key of [
|
|
40
|
-
"@opentelemetry/api",
|
|
41
|
-
"@azure/core-tracing/node_modules/@opentelemetry/api"
|
|
42
|
-
]) {
|
|
43
|
-
namedExports[key] = [
|
|
44
|
-
"SpanKind",
|
|
45
|
-
"TraceFlags",
|
|
46
|
-
"getSpan",
|
|
47
|
-
"setSpan",
|
|
48
|
-
"SpanStatusCode",
|
|
49
|
-
"getSpanContext",
|
|
50
|
-
"setSpanContext"
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const releasedOpenTelemetryVersions = ["0.10.2", "1.0.0-rc.0"];
|
|
55
|
-
|
|
56
|
-
for (const version of releasedOpenTelemetryVersions) {
|
|
57
|
-
namedExports[
|
|
58
|
-
// working around a limitation in the rollup common.js plugin - it's not able to resolve these modules so the named exports listed above will not get applied. We have to drill down to the actual path.
|
|
59
|
-
\`../../../common/temp/node_modules/.pnpm/@opentelemetry/api@\${version}/node_modules/@opentelemetry/api/build/src/index.js\`
|
|
60
|
-
] = [
|
|
61
|
-
"SpanKind",
|
|
62
|
-
"TraceFlags",
|
|
63
|
-
"getSpan",
|
|
64
|
-
"setSpan",
|
|
65
|
-
"StatusCode",
|
|
66
|
-
"CanonicalCode",
|
|
67
|
-
"getSpanContext",
|
|
68
|
-
"setSpanContext"
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return namedExports;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
32
|
// #region Warning Handler
|
|
76
33
|
|
|
77
34
|
/**
|
|
78
|
-
* A function that can determine whether a
|
|
35
|
+
* A function that can determine whether a rollup warning should be ignored. If
|
|
79
36
|
* the function returns \`true\`, then the warning will not be displayed.
|
|
80
37
|
*/
|
|
81
38
|
|
|
82
|
-
function
|
|
39
|
+
function ignoreNiseSinonEval(warning) {
|
|
83
40
|
return (
|
|
84
41
|
warning.code === "EVAL" &&
|
|
85
42
|
(warning.id && ((warning.id.includes("node_modules/nise")) ||
|
|
@@ -87,7 +44,7 @@ export function generateRollupConfig(project: Project) {
|
|
|
87
44
|
);
|
|
88
45
|
}
|
|
89
46
|
|
|
90
|
-
function
|
|
47
|
+
function ignoreChaiCircularDependency(warning) {
|
|
91
48
|
return (
|
|
92
49
|
warning.code === "CIRCULAR_DEPENDENCY" &&
|
|
93
50
|
(warning.importer && warning.importer.includes("node_modules/chai") === true)
|
|
@@ -95,8 +52,8 @@ export function generateRollupConfig(project: Project) {
|
|
|
95
52
|
}
|
|
96
53
|
|
|
97
54
|
const warningInhibitors = [
|
|
98
|
-
|
|
99
|
-
|
|
55
|
+
ignoreChaiCircularDependency,
|
|
56
|
+
ignoreNiseSinonEval
|
|
100
57
|
];
|
|
101
58
|
|
|
102
59
|
/**
|
|
@@ -131,22 +88,7 @@ export function generateRollupConfig(project: Project) {
|
|
|
131
88
|
nodeResolve({
|
|
132
89
|
mainFields: ["module", "browser"]
|
|
133
90
|
}),
|
|
134
|
-
cjs(
|
|
135
|
-
namedExports: {
|
|
136
|
-
// Chai's strange internal architecture makes it impossible to statically
|
|
137
|
-
// analyze its exports.
|
|
138
|
-
chai: [
|
|
139
|
-
"version",
|
|
140
|
-
"use",
|
|
141
|
-
"util",
|
|
142
|
-
"config",
|
|
143
|
-
"expect",
|
|
144
|
-
"should",
|
|
145
|
-
"assert"
|
|
146
|
-
],
|
|
147
|
-
...openTelemetryCommonJs()
|
|
148
|
-
}
|
|
149
|
-
}),
|
|
91
|
+
cjs(),
|
|
150
92
|
json(),
|
|
151
93
|
sourcemaps()
|
|
152
94
|
//viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
|
|
@@ -185,7 +127,7 @@ export function generateRollupConfig(project: Project) {
|
|
|
185
127
|
],
|
|
186
128
|
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
|
|
187
129
|
preserveSymlinks: false,
|
|
188
|
-
plugins: [sourcemaps(), nodeResolve()
|
|
130
|
+
plugins: [sourcemaps(), nodeResolve()]
|
|
189
131
|
};
|
|
190
132
|
|
|
191
133
|
const config = [baseConfig];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
import {
|
|
5
|
+
{{#if importedTypes.length }}
|
|
6
|
+
{{#each importedTypes}}
|
|
7
|
+
{{this}},
|
|
8
|
+
{{/each}}
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{clientClassName}},
|
|
11
|
+
} from "{{clientPackageName}}";
|
|
12
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
13
|
+
|
|
14
|
+
{{#each samples}}
|
|
15
|
+
/**
|
|
16
|
+
* This sample demonstrates how to {{this.operationDescription}}
|
|
17
|
+
*
|
|
18
|
+
* @summary {{this.operationDescription}}
|
|
19
|
+
* x-ms-original-file: {{this.originalFileLocation}}
|
|
20
|
+
*/
|
|
21
|
+
async function {{this.sampleFunctionName}}() {
|
|
22
|
+
{{#each this.clientParamAssignments}}
|
|
23
|
+
{{this}}
|
|
24
|
+
{{/each}}
|
|
25
|
+
{{#each this.methodParamAssignments}}
|
|
26
|
+
{{this}}
|
|
27
|
+
{{/each}}
|
|
28
|
+
const credential = new DefaultAzureCredential();
|
|
29
|
+
const client = new {{this.clientClassName}}({{this.clientParameterNames}});
|
|
30
|
+
{{#if this.isPaging}}
|
|
31
|
+
const resArray = new Array();
|
|
32
|
+
for await (let item of client{{#unless this.isTopLevel}}.{{this.operationGroupName}}{{/unless}}.{{this.operationName}}({{this.methodParameterNames}})){
|
|
33
|
+
resArray.push(item);
|
|
34
|
+
}
|
|
35
|
+
console.log(resArray);
|
|
36
|
+
{{else}}
|
|
37
|
+
const result = await client
|
|
38
|
+
{{#unless this.isTopLevel}}
|
|
39
|
+
.{{this.operationGroupName}}
|
|
40
|
+
{{/unless}}
|
|
41
|
+
.{{this.operationName}}({{this.methodParameterNames}});
|
|
42
|
+
console.log(result);
|
|
43
|
+
|
|
44
|
+
{{/if}}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
{{this.sampleFunctionName}}().catch(console.error);
|
|
48
|
+
|
|
49
|
+
{{/each}}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Project } from "ts-morph";
|
|
5
5
|
import { getAutorestOptions } from "../../autorestSession";
|
|
6
6
|
|
|
7
|
-
const highLevelTsConfig = {
|
|
7
|
+
const highLevelTsConfig: Record<string, any> = {
|
|
8
8
|
compilerOptions: {
|
|
9
9
|
module: "es6",
|
|
10
10
|
moduleResolution: "node",
|
|
@@ -25,37 +25,64 @@ const highLevelTsConfig = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
declaration: true,
|
|
34
|
-
declarationMap: true,
|
|
35
|
-
outDir: "./dist-esm"
|
|
28
|
+
const restLevelTsConfigInAzureSdkForJs = {
|
|
29
|
+
"extends": "../../../tsconfig.package",
|
|
30
|
+
"compilerOptions": {
|
|
31
|
+
"outDir": "./dist-esm",
|
|
32
|
+
"declarationDir": "./types",
|
|
36
33
|
},
|
|
37
|
-
|
|
38
|
-
"node_modules",
|
|
39
|
-
"types",
|
|
40
|
-
"temp",
|
|
41
|
-
"browser",
|
|
42
|
-
"dist",
|
|
43
|
-
"dist-esm",
|
|
44
|
-
"./samples/**/*.ts"
|
|
45
|
-
]
|
|
34
|
+
"include": ["src/**/*.ts"]
|
|
46
35
|
};
|
|
47
36
|
|
|
37
|
+
const restLevelTsConfigNotInAzureSdkForJs ={
|
|
38
|
+
"compilerOptions": {
|
|
39
|
+
"target": "ES2017",
|
|
40
|
+
"module": "es6",
|
|
41
|
+
"lib": [],
|
|
42
|
+
"declaration": true,
|
|
43
|
+
"declarationMap": true,
|
|
44
|
+
"inlineSources": true,
|
|
45
|
+
"sourceMap": true,
|
|
46
|
+
"importHelpers": true,
|
|
47
|
+
"strict": true,
|
|
48
|
+
"alwaysStrict": true,
|
|
49
|
+
"noUnusedLocals": true,
|
|
50
|
+
"noUnusedParameters": true,
|
|
51
|
+
"noImplicitReturns": true,
|
|
52
|
+
"noFallthroughCasesInSwitch": true,
|
|
53
|
+
"forceConsistentCasingInFileNames": true,
|
|
54
|
+
"moduleResolution": "node",
|
|
55
|
+
"allowSyntheticDefaultImports": true,
|
|
56
|
+
"esModuleInterop": true,
|
|
57
|
+
"outDir": "./dist-esm",
|
|
58
|
+
"declarationDir": "./types"
|
|
59
|
+
},
|
|
60
|
+
"include": ["./src/**/*.ts"]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
48
64
|
export function generateTsConfig(project: Project) {
|
|
49
|
-
const { generateMetadata, restLevelClient, generateTest } = getAutorestOptions();
|
|
65
|
+
const { generateMetadata, restLevelClient, generateTest, packageDetails, generateSample, azureSdkForJs } = getAutorestOptions();
|
|
50
66
|
|
|
51
67
|
if (!generateMetadata) {
|
|
52
68
|
return;
|
|
53
69
|
}
|
|
54
70
|
|
|
71
|
+
const clientPackageName = packageDetails.name;
|
|
72
|
+
|
|
73
|
+
const restLevelTsConfig = azureSdkForJs? restLevelTsConfigInAzureSdkForJs : restLevelTsConfigNotInAzureSdkForJs;
|
|
74
|
+
|
|
55
75
|
if (generateTest) {
|
|
56
76
|
highLevelTsConfig.include.push("./test/**/*.ts");
|
|
77
|
+
restLevelTsConfig.include.push("./test/**/*.ts");
|
|
57
78
|
}
|
|
58
|
-
|
|
79
|
+
|
|
80
|
+
if (generateSample) {
|
|
81
|
+
highLevelTsConfig.include.push("samples-dev/**/*.ts");
|
|
82
|
+
highLevelTsConfig.compilerOptions["paths"] = {};
|
|
83
|
+
highLevelTsConfig.compilerOptions["paths"][clientPackageName] = ["./src/index"];
|
|
84
|
+
}
|
|
85
|
+
|
|
59
86
|
const tsConfigContents = restLevelClient
|
|
60
87
|
? restLevelTsConfig
|
|
61
88
|
: highLevelTsConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import { getAutorestOptions } from "../../autorestSession";
|
|
3
|
+
|
|
4
|
+
export function generateEnvBrowserFile(
|
|
5
|
+
project: Project
|
|
6
|
+
) {
|
|
7
|
+
const { generateTest, restLevelClient } = getAutorestOptions();
|
|
8
|
+
if (!generateTest || !restLevelClient) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
project.createSourceFile("test/public/utils/env.browser.ts", "", {
|
|
12
|
+
overwrite: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as hbs from "handlebars";
|
|
5
|
+
import { getAutorestOptions } from "../../autorestSession";
|
|
6
|
+
|
|
7
|
+
export function generateEnvFile(
|
|
8
|
+
project: Project
|
|
9
|
+
) {
|
|
10
|
+
const { generateTest, restLevelClient } = getAutorestOptions();
|
|
11
|
+
if (!generateTest || !restLevelClient) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const metadata = {}
|
|
15
|
+
const file = fs.readFileSync(path.join(__dirname, "rlcEnv.ts.hbs"), {
|
|
16
|
+
encoding: "utf-8"
|
|
17
|
+
});
|
|
18
|
+
const envFileContents = hbs.compile(file, { noEscape: true });
|
|
19
|
+
project.createSourceFile("test/public/utils/env.ts", envFileContents(metadata), {
|
|
20
|
+
overwrite: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as hbs from "handlebars";
|
|
5
|
+
import { getAutorestOptions } from "../../autorestSession";
|
|
6
|
+
|
|
7
|
+
export function generateRecordedClientFile(
|
|
8
|
+
project: Project
|
|
9
|
+
) {
|
|
10
|
+
const { generateTest, restLevelClient } = getAutorestOptions();
|
|
11
|
+
if (!generateTest || !restLevelClient) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const metadata = {}
|
|
15
|
+
const file = fs.readFileSync(path.join(__dirname, "rlcRecordedClient.ts.hbs"), {
|
|
16
|
+
encoding: "utf-8"
|
|
17
|
+
});
|
|
18
|
+
const recordedClientFileContents = hbs.compile(file, { noEscape: true });
|
|
19
|
+
project.createSourceFile("test/public/utils/recordedClient.ts", recordedClientFileContents(metadata), {
|
|
20
|
+
overwrite: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Context } from "mocha";
|
|
2
|
+
import { record, RecorderEnvironmentSetup, Recorder } from "@azure-tools/test-recorder";
|
|
3
|
+
import "./env";
|
|
4
|
+
|
|
5
|
+
const recorderEnvSetup: RecorderEnvironmentSetup = {
|
|
6
|
+
replaceableVariables: {
|
|
7
|
+
ENDPOINT: "https://endpoint",
|
|
8
|
+
AZURE_CLIENT_ID: "azure_client_id",
|
|
9
|
+
AZURE_CLIENT_SECRET: "azure_client_secret",
|
|
10
|
+
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
|
|
11
|
+
SUBSCRIPTION_ID: "azure_subscription_id"
|
|
12
|
+
},
|
|
13
|
+
customizationsOnRecordings: [
|
|
14
|
+
(recording: any): any =>
|
|
15
|
+
recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`),
|
|
16
|
+
// If we put ENDPOINT in replaceableVariables above, it will not capture
|
|
17
|
+
// the endpoint string used with nock, which will be expanded to
|
|
18
|
+
// https://<endpoint>:443/ and therefore will not match, so we have to do
|
|
19
|
+
// this instead.
|
|
20
|
+
(recording: string): string => {
|
|
21
|
+
const replaced = recording.replace("endpoint:443", "endpoint");
|
|
22
|
+
return replaced;
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
queryParametersToSkip: []
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* creates the recorder and reads the environment variables from the `.env` file.
|
|
30
|
+
* Should be called first in the test suite to make sure environment variables are
|
|
31
|
+
* read before they are being used.
|
|
32
|
+
*/
|
|
33
|
+
export function createRecorder(context: Context): Recorder {
|
|
34
|
+
return record(context, recorderEnvSetup);
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Recorder } from "@azure-tools/test-recorder";
|
|
2
|
+
import * as assert from "assert";
|
|
3
|
+
import { createRecorder } from "./utils/recordedClient";
|
|
4
|
+
|
|
5
|
+
describe("My test", () => {
|
|
6
|
+
let recorder: Recorder;
|
|
7
|
+
|
|
8
|
+
beforeEach(async function() {
|
|
9
|
+
recorder = createRecorder(this);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async function() {
|
|
13
|
+
await recorder.stop();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("sample test", async function() {
|
|
17
|
+
assert.equal(1, 1);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
File without changes
|