@autorest/typescript 6.0.0-beta.13 → 6.0.0-beta.16
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 +8 -3
- 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 +3 -0
- package/dist/src/conflictResolver.d.ts.map +1 -0
- package/dist/src/conflictResolver.js +43 -0
- package/dist/src/conflictResolver.js.map +1 -0
- 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 +85 -12
- package/dist/src/generators/indexGenerator.js.map +1 -1
- package/dist/src/generators/mappersGenerator.d.ts.map +1 -1
- package/dist/src/generators/mappersGenerator.js +81 -7
- package/dist/src/generators/mappersGenerator.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.js +6 -6
- 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/README.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 +100 -25
- package/dist/src/generators/static/packageFileGenerator.js.map +1 -1
- package/dist/src/generators/static/readmeFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/readmeFileGenerator.js +5 -1
- package/dist/src/generators/static/readmeFileGenerator.js.map +1 -1
- package/dist/src/generators/static/rollupConfigFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/rollupConfigFileGenerator.js +7 -70
- 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 +9 -10
- 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 +3 -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 +48 -159
- 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 +3 -3
- package/dist/src/restLevelClient/generateObjectTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateObjectTypes.js +28 -20
- 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 +246 -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 +23 -14
- 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 +19 -3
- 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 +29 -7
- 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/getPropertySignature.d.ts +2 -2
- package/dist/src/restLevelClient/getPropertySignature.d.ts.map +1 -1
- package/dist/src/restLevelClient/getPropertySignature.js +2 -2
- package/dist/src/restLevelClient/getPropertySignature.js.map +1 -1
- package/dist/src/restLevelClient/helpers/modelHelpers.d.ts +4 -0
- package/dist/src/restLevelClient/helpers/modelHelpers.d.ts.map +1 -0
- package/dist/src/restLevelClient/helpers/modelHelpers.js +19 -0
- package/dist/src/restLevelClient/helpers/modelHelpers.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 +8 -2
- package/dist/src/restLevelClient/schemaHelpers.d.ts.map +1 -1
- package/dist/src/restLevelClient/schemaHelpers.js +19 -9
- 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 +4 -1
- package/dist/src/transforms/operationTransforms.js.map +1 -1
- package/dist/src/transforms/parameterTransforms.d.ts.map +1 -1
- package/dist/src/transforms/parameterTransforms.js +1 -1
- package/dist/src/transforms/parameterTransforms.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 +20 -29
- 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 +70 -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 +11 -6
- 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 +18 -12
- package/src/autorestSession.ts +16 -15
- package/src/conflictResolver.ts +61 -0
- package/src/generators/clientFileGenerator.ts +262 -33
- package/src/generators/indexGenerator.ts +98 -13
- package/src/generators/mappersGenerator.ts +108 -8
- package/src/generators/modelsGenerator.ts +21 -1
- package/src/generators/operationGenerator.ts +7 -7
- 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/README.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 +113 -28
- package/src/generators/static/readmeFileGenerator.ts +8 -2
- package/src/generators/static/rollupConfigFileGenerator.ts +7 -70
- package/src/generators/static/samples.ts.hbs +49 -0
- package/src/generators/static/tsConfigFileGenerator.ts +12 -12
- 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 +9 -5
- package/src/models/clientDetails.ts +3 -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 +55 -243
- package/src/restLevelClient/generateClientDefinition.ts +343 -0
- package/src/restLevelClient/generateMethodShortcuts.ts +121 -0
- package/src/restLevelClient/generateObjectTypes.ts +57 -20
- package/src/restLevelClient/generatePagingHelper.ts +3 -2
- package/src/restLevelClient/generateParameterTypes.ts +377 -48
- package/src/restLevelClient/generatePollingHelper.ts +3 -3
- package/src/restLevelClient/generateResponseTypes.ts +30 -16
- package/src/restLevelClient/generateRestLevel.ts +24 -6
- package/src/restLevelClient/generateSchemaTypes.ts +43 -8
- package/src/restLevelClient/generateTopLevelIndexFile.ts +41 -0
- package/src/restLevelClient/getPropertySignature.ts +3 -2
- package/src/restLevelClient/helpers/modelHelpers.ts +15 -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 +25 -7
- package/src/transforms/operationTransforms.ts +6 -1
- package/src/transforms/parameterTransforms.ts +3 -1
- package/src/transforms/samplesTransforms.ts +300 -0
- package/src/transforms/transforms.ts +6 -6
- package/src/typescriptGenerator.ts +22 -46
- package/src/utils/autorestOptions.ts +121 -58
- package/src/utils/nameUtils.ts +18 -9
- 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
|
@@ -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 { env, 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
|
+
console.log("Hi, I'm a test!");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
File without changes
|
|
@@ -2,16 +2,31 @@ import { Project } from "ts-morph";
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as hbs from "handlebars";
|
|
5
|
+
import { getAutorestOptions } from "../../autorestSession";
|
|
5
6
|
|
|
6
7
|
export function generateSampleTestFile(
|
|
7
8
|
project: Project
|
|
8
9
|
) {
|
|
10
|
+
const { generateTest, restLevelClient } = getAutorestOptions();
|
|
11
|
+
if (!generateTest) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
9
14
|
const metadata = {}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (restLevelClient) {
|
|
16
|
+
const file = fs.readFileSync(path.join(__dirname, "rlcSampleTest.spec.ts.hbs"), {
|
|
17
|
+
encoding: "utf-8"
|
|
18
|
+
});
|
|
19
|
+
const readmeFileContents = hbs.compile(file, { noEscape: true });
|
|
20
|
+
project.createSourceFile("test/public/sampleTest.spec.ts", readmeFileContents(metadata), {
|
|
21
|
+
overwrite: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
const file = fs.readFileSync(path.join(__dirname, "sampleTest.ts.hbs"), {
|
|
25
|
+
encoding: "utf-8"
|
|
26
|
+
});
|
|
27
|
+
const readmeFileContents = hbs.compile(file, { noEscape: true });
|
|
28
|
+
project.createSourceFile("test/sampleTest.ts", readmeFileContents(metadata), {
|
|
29
|
+
overwrite: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -230,7 +230,7 @@ export function writeAsyncIterators(
|
|
|
230
230
|
* This method enforces Azure SDK Typescript guideline that paging methods should be named list*
|
|
231
231
|
* https://azure.github.io/azure-sdk/typescript_design.html#ts-pagination-provide-list
|
|
232
232
|
*/
|
|
233
|
-
function getPublicMethodName(operation: OperationDetails) {
|
|
233
|
+
export function getPublicMethodName(operation: OperationDetails) {
|
|
234
234
|
let initialOperationName = normalizeName(operation.name, NameType.Operation);
|
|
235
235
|
if (initialOperationName.indexOf("list") === 0) {
|
|
236
236
|
initialOperationName = initialOperationName.replace("list", "");
|
package/src/main.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AutoRestExtension,
|
|
6
|
+
AutorestExtensionHost
|
|
7
|
+
} from "@autorest/extension-base";
|
|
5
8
|
import { generateTypeScriptLibrary } from "./typescriptGenerator";
|
|
6
9
|
import { generateRestLevelClient } from "./restLevelClient/generateRestLevel";
|
|
7
10
|
import {
|
|
@@ -9,8 +12,9 @@ import {
|
|
|
9
12
|
initializeSession,
|
|
10
13
|
getAutorestOptions
|
|
11
14
|
} from "./autorestSession";
|
|
15
|
+
import { serialize } from "@azure-tools/codegen";
|
|
12
16
|
|
|
13
|
-
export async function processRequest(host:
|
|
17
|
+
export async function processRequest(host: AutorestExtensionHost) {
|
|
14
18
|
await initializeSession(host);
|
|
15
19
|
const session = getSession();
|
|
16
20
|
const { restLevelClient } = getAutorestOptions();
|
|
@@ -19,7 +23,7 @@ export async function processRequest(host: Host) {
|
|
|
19
23
|
restLevelClient
|
|
20
24
|
? await generateRestLevelClient()
|
|
21
25
|
: await generateTypeScriptLibrary(session.model, host);
|
|
22
|
-
session.
|
|
26
|
+
session.info(`Autorest.Typescript took ${Date.now() - start}ms`);
|
|
23
27
|
} catch (err) {
|
|
24
28
|
session.error("An error was encountered while handling a request:", err);
|
|
25
29
|
throw err;
|
|
@@ -28,8 +32,8 @@ export async function processRequest(host: Host) {
|
|
|
28
32
|
|
|
29
33
|
async function main() {
|
|
30
34
|
const pluginHost = new AutoRestExtension();
|
|
31
|
-
pluginHost.
|
|
32
|
-
await pluginHost.
|
|
35
|
+
pluginHost.add("typescript", processRequest);
|
|
36
|
+
await pluginHost.run();
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
main();
|
|
@@ -9,6 +9,7 @@ import { ObjectDetails } from "./modelDetails";
|
|
|
9
9
|
import { EndpointDetails } from "../transforms/urlTransforms";
|
|
10
10
|
import { KnownMediaType } from "@azure-tools/codegen";
|
|
11
11
|
import { Info } from "@autorest/codemodel";
|
|
12
|
+
import { SampleGroup } from "./sampleDetails";
|
|
12
13
|
|
|
13
14
|
export interface ClientOptions {
|
|
14
15
|
mediaTypes?: Set<KnownMediaType>;
|
|
@@ -32,4 +33,6 @@ export interface ClientDetails {
|
|
|
32
33
|
parameters: ParameterDetails[];
|
|
33
34
|
options: ClientOptions;
|
|
34
35
|
endpoint: EndpointDetails;
|
|
36
|
+
samples?: SampleGroup[];
|
|
37
|
+
allTypes: string[];
|
|
35
38
|
}
|
|
@@ -65,7 +65,7 @@ export type PolymorphicObjectDetails = BasicObjectDetails & {
|
|
|
65
65
|
export interface PropertyDetails {
|
|
66
66
|
name: string;
|
|
67
67
|
description?: string;
|
|
68
|
-
defaultValue?: string;
|
|
68
|
+
defaultValue?: string | number | boolean;
|
|
69
69
|
serializedName: string;
|
|
70
70
|
type: string;
|
|
71
71
|
required: boolean;
|
|
@@ -83,7 +83,7 @@ export interface TypeDetails {
|
|
|
83
83
|
typeName: string;
|
|
84
84
|
isConstant?: boolean;
|
|
85
85
|
nullable?: boolean;
|
|
86
|
-
defaultValue?: string;
|
|
86
|
+
defaultValue?: string | number | boolean;
|
|
87
87
|
kind: PropertyKind;
|
|
88
88
|
usedModels: string[];
|
|
89
89
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SampleGroup {
|
|
2
|
+
sampleFileName: string,
|
|
3
|
+
clientClassName: string,
|
|
4
|
+
clientPackageName: string,
|
|
5
|
+
samples: SampleDetails[],
|
|
6
|
+
importedTypes?: string[],
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SampleDetails {
|
|
10
|
+
sampleFunctionName: string,
|
|
11
|
+
clientParameterNames: string,
|
|
12
|
+
methodParameterNames: string,
|
|
13
|
+
clientParamAssignments: string[],
|
|
14
|
+
methodParamAssignments: string[],
|
|
15
|
+
originalFileLocation?: string,
|
|
16
|
+
operationName: string,
|
|
17
|
+
isTopLevel: boolean,
|
|
18
|
+
isPaging: boolean,
|
|
19
|
+
operationGroupName: string,
|
|
20
|
+
operationDescription: string,
|
|
21
|
+
clientClassName: string,
|
|
22
|
+
}
|
|
@@ -5,125 +5,40 @@ import {
|
|
|
5
5
|
ImplementationLocation
|
|
6
6
|
} from "@autorest/codemodel";
|
|
7
7
|
|
|
8
|
-
import { getResponseTypeName } from "./operationHelpers";
|
|
9
|
-
|
|
10
8
|
import {
|
|
11
|
-
CallSignatureDeclarationStructure,
|
|
12
|
-
MethodSignatureStructure,
|
|
13
|
-
OptionalKind,
|
|
14
9
|
Project,
|
|
15
|
-
SourceFile,
|
|
16
10
|
StatementStructures,
|
|
17
11
|
StructureKind,
|
|
18
12
|
VariableDeclarationKind,
|
|
19
13
|
VariableStatementStructure,
|
|
20
|
-
WriterFunction
|
|
21
|
-
Writers
|
|
14
|
+
WriterFunction
|
|
22
15
|
} from "ts-morph";
|
|
16
|
+
import * as path from 'path';
|
|
23
17
|
|
|
24
18
|
import { getAutorestOptions, getSession } from "../autorestSession";
|
|
25
19
|
import { transformBaseUrl } from "../transforms/urlTransforms";
|
|
26
20
|
import { NameType, normalizeName } from "../utils/nameUtils";
|
|
27
21
|
import { isConstantSchema } from "./schemaHelpers";
|
|
28
22
|
import { getLanguageMetadata } from "../utils/languageHelpers";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type Methods = {
|
|
34
|
-
[key: string]: [
|
|
35
|
-
{
|
|
36
|
-
optionsName: string;
|
|
37
|
-
description: string;
|
|
38
|
-
hasOptionalOptions: boolean;
|
|
39
|
-
returnType: string;
|
|
40
|
-
}
|
|
41
|
-
];
|
|
42
|
-
};
|
|
43
|
-
type Paths = {
|
|
44
|
-
[key: string]: {
|
|
45
|
-
name: string;
|
|
46
|
-
pathParameters: PathParameter[];
|
|
47
|
-
methods: Methods;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
23
|
+
import { generateMethodShortcutImplementation } from "./generateMethodShortcuts";
|
|
24
|
+
import { Paths } from "./interfaces";
|
|
25
|
+
import { pathDictionary } from './generateClientDefinition';
|
|
50
26
|
|
|
51
|
-
export function
|
|
27
|
+
export function generateClient(model: CodeModel, project: Project) {
|
|
52
28
|
const name = normalizeName(
|
|
53
29
|
getLanguageMetadata(model.language).name,
|
|
54
30
|
NameType.File
|
|
55
31
|
);
|
|
56
|
-
const
|
|
32
|
+
const { srcPath } = getAutorestOptions();
|
|
33
|
+
const clientFile = project.createSourceFile(path.join(srcPath, `${name}.ts`), undefined, {
|
|
57
34
|
overwrite: true
|
|
58
35
|
});
|
|
59
36
|
|
|
60
37
|
// Get all paths
|
|
61
|
-
const importedParameters = new Set<string>();
|
|
62
|
-
const importedResponses = new Set<string>();
|
|
63
|
-
const pathDictionary: Paths = {};
|
|
64
|
-
for (const operationGroup of model.operationGroups) {
|
|
65
|
-
for (const operation of operationGroup.operations) {
|
|
66
|
-
const operationName = getLanguageMetadata(operation.language).name;
|
|
67
|
-
const operationDescription = getLanguageMetadata(operation.language)
|
|
68
|
-
.description;
|
|
69
|
-
const pathParameters: PathParameter[] =
|
|
70
|
-
operation.parameters
|
|
71
|
-
?.filter(p => p.protocol.http?.in === ParameterLocation.Path)
|
|
72
|
-
.map(p => {
|
|
73
|
-
const languageMetadata = getLanguageMetadata(p.language);
|
|
74
|
-
return {
|
|
75
|
-
name: languageMetadata.serializedName || languageMetadata.name,
|
|
76
|
-
description: languageMetadata.description
|
|
77
|
-
};
|
|
78
|
-
}) || [];
|
|
79
|
-
|
|
80
|
-
for (const request of operation.requests || []) {
|
|
81
|
-
const path: string = (request.protocol.http?.path as string) || "";
|
|
82
|
-
const method = request.protocol.http?.method;
|
|
83
|
-
|
|
84
|
-
if (path && method) {
|
|
85
|
-
if (!pathDictionary[path]) {
|
|
86
|
-
pathDictionary[path] = {
|
|
87
|
-
pathParameters,
|
|
88
|
-
methods: {},
|
|
89
|
-
name: operationName
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const hasOptionalOptions = !hasRequiredOptions(operation);
|
|
93
|
-
|
|
94
|
-
const newMethod = {
|
|
95
|
-
description: operationDescription,
|
|
96
|
-
optionsName: getOperationOptionsType(operation, importedParameters),
|
|
97
|
-
hasOptionalOptions,
|
|
98
|
-
returnType: `Promise<${getOperationReturnType(
|
|
99
|
-
operation,
|
|
100
|
-
importedResponses
|
|
101
|
-
)}>`
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
if (pathDictionary[path].methods[`${method}`]) {
|
|
105
|
-
pathDictionary[path].methods[`${method}`].push(newMethod);
|
|
106
|
-
} else {
|
|
107
|
-
pathDictionary[path].methods[`${method}`] = [newMethod];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
clientFile.addInterface({
|
|
115
|
-
name: "Routes",
|
|
116
|
-
isExported: true,
|
|
117
|
-
callSignatures: getPathFirstRoutesInterfaceDefinition(
|
|
118
|
-
pathDictionary,
|
|
119
|
-
clientFile
|
|
120
|
-
)
|
|
121
|
-
});
|
|
122
|
-
|
|
123
38
|
const clientName = getLanguageMetadata(model.language).name;
|
|
124
39
|
const uriParameter = getClientUriParameter();
|
|
125
40
|
|
|
126
|
-
const { addCredentials, credentialKeyHeaderName } = getAutorestOptions();
|
|
41
|
+
const { addCredentials, credentialKeyHeaderName, multiClient, batch } = getAutorestOptions();
|
|
127
42
|
const credentialTypes = addCredentials ? ["TokenCredential"] : [];
|
|
128
43
|
|
|
129
44
|
if (credentialKeyHeaderName) {
|
|
@@ -136,46 +51,28 @@ export function generatePathFirstClient(model: CodeModel, project: Project) {
|
|
|
136
51
|
? []
|
|
137
52
|
: [{ name: "credentials", type: credentialTypes.join(" | ") }])
|
|
138
53
|
];
|
|
139
|
-
const
|
|
140
|
-
// const factoryTypeName = `${clientName}Factory`;
|
|
141
|
-
clientFile.addTypeAlias({
|
|
142
|
-
isExported: true,
|
|
143
|
-
name: clientIterfaceName,
|
|
144
|
-
type: Writers.intersectionType(
|
|
145
|
-
"Client",
|
|
146
|
-
Writers.objectType({ properties: [{ name: "path", type: "Routes" }] })
|
|
147
|
-
)
|
|
148
|
-
});
|
|
54
|
+
const clientInterfaceName = `${clientName}Like`;
|
|
149
55
|
|
|
150
|
-
|
|
56
|
+
const functionStatement = {
|
|
151
57
|
isExported: true,
|
|
152
|
-
name: clientName
|
|
58
|
+
name: `${clientName}`,
|
|
153
59
|
parameters: [
|
|
154
60
|
...commonClientParams,
|
|
155
61
|
{ name: "options", type: "ClientOptions = {}" }
|
|
156
62
|
],
|
|
157
|
-
returnType:
|
|
158
|
-
isDefaultExport:
|
|
159
|
-
statements: getClientFactoryBody(
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
if (importedParameters.size) {
|
|
163
|
-
clientFile.addImportDeclaration({
|
|
164
|
-
namedImports: [...importedParameters],
|
|
165
|
-
moduleSpecifier: "./parameters"
|
|
166
|
-
});
|
|
63
|
+
returnType: clientInterfaceName,
|
|
64
|
+
isDefaultExport: false,
|
|
65
|
+
statements: getClientFactoryBody(clientInterfaceName, pathDictionary)
|
|
167
66
|
}
|
|
168
67
|
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
namedImports: [...importedResponses],
|
|
172
|
-
moduleSpecifier: "./responses"
|
|
173
|
-
});
|
|
68
|
+
if (!multiClient || !batch || batch.length === 1) {
|
|
69
|
+
functionStatement.isDefaultExport = true;
|
|
174
70
|
}
|
|
71
|
+
clientFile.addFunction(functionStatement);
|
|
175
72
|
|
|
176
73
|
clientFile.addImportDeclarations([
|
|
177
74
|
{
|
|
178
|
-
namedImports: ["getClient", "ClientOptions"
|
|
75
|
+
namedImports: ["getClient", "ClientOptions"],
|
|
179
76
|
moduleSpecifier: "@azure-rest/core-client"
|
|
180
77
|
}
|
|
181
78
|
]);
|
|
@@ -184,32 +81,19 @@ export function generatePathFirstClient(model: CodeModel, project: Project) {
|
|
|
184
81
|
{
|
|
185
82
|
namedImports: credentialTypes,
|
|
186
83
|
moduleSpecifier: "@azure/core-auth"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
namedImports: [`${clientInterfaceName}`],
|
|
87
|
+
moduleSpecifier: './clientDefinitions'
|
|
187
88
|
}
|
|
188
89
|
]);
|
|
189
90
|
}
|
|
190
91
|
|
|
191
|
-
function hasRequiredOptions(operation: Operation) {
|
|
192
|
-
return getOperationParameters(operation)
|
|
193
|
-
.filter(p => p.implementation === ImplementationLocation.Method)
|
|
194
|
-
.filter(p => ["query", "body", "headers"].includes(p.protocol.http?.in))
|
|
195
|
-
.some(p => p.required);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function getOperationOptionsType(
|
|
199
|
-
operation: Operation,
|
|
200
|
-
importedParameters = new Set<string>()
|
|
201
|
-
) {
|
|
202
|
-
const paramsName = `${
|
|
203
|
-
getLanguageMetadata(operation.language).name
|
|
204
|
-
}Parameters`;
|
|
205
|
-
importedParameters.add(paramsName);
|
|
206
|
-
|
|
207
|
-
return paramsName;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
92
|
function getClientFactoryBody(
|
|
211
|
-
clientTypeName: string
|
|
93
|
+
clientTypeName: string,
|
|
94
|
+
paths: Paths
|
|
212
95
|
): string | WriterFunction | (string | WriterFunction | StatementStructures)[] {
|
|
96
|
+
const { rlcShortcut } = getAutorestOptions();
|
|
213
97
|
const { model } = getSession();
|
|
214
98
|
const { endpoint, parameterName } = transformBaseUrl(model);
|
|
215
99
|
let baseUrl: string;
|
|
@@ -258,13 +142,36 @@ function getClientFactoryBody(
|
|
|
258
142
|
}`
|
|
259
143
|
: "";
|
|
260
144
|
|
|
261
|
-
const getClient = `
|
|
262
|
-
baseUrl,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
145
|
+
const getClient = `const client = getClient(
|
|
146
|
+
baseUrl, ${credentials ? "credentials," : ""} options
|
|
147
|
+
) as ${clientTypeName};
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
let returnStatement = `return client;`;
|
|
151
|
+
|
|
152
|
+
if (rlcShortcut) {
|
|
153
|
+
const shortcutImplementations = generateMethodShortcutImplementation(
|
|
154
|
+
model,
|
|
155
|
+
paths
|
|
156
|
+
);
|
|
157
|
+
const shortcutBody = Object.keys(shortcutImplementations).map(key => {
|
|
158
|
+
// If the operation group has an empty name, it means its operations are client
|
|
159
|
+
// level operations so we need to spread the definitions. Otherwise they are
|
|
160
|
+
// within an operation group so we add them as key: value
|
|
161
|
+
return `${key ? `"${key}":` : "..."} {${shortcutImplementations[
|
|
162
|
+
key
|
|
163
|
+
].join()}}`;
|
|
164
|
+
});
|
|
165
|
+
returnStatement = `return { ...client, ${shortcutBody.join()} };`;
|
|
166
|
+
}
|
|
266
167
|
|
|
267
|
-
return [
|
|
168
|
+
return [
|
|
169
|
+
baseUrlStatement,
|
|
170
|
+
apiVersionStatement,
|
|
171
|
+
credentials,
|
|
172
|
+
getClient,
|
|
173
|
+
returnStatement
|
|
174
|
+
];
|
|
268
175
|
}
|
|
269
176
|
|
|
270
177
|
function getApiVersion(): string | undefined {
|
|
@@ -291,103 +198,8 @@ function getApiVersion(): string | undefined {
|
|
|
291
198
|
return undefined;
|
|
292
199
|
}
|
|
293
200
|
|
|
294
|
-
function getOperationReturnType(
|
|
295
|
-
operation: Operation,
|
|
296
|
-
importedResponses = new Set<string>()
|
|
297
|
-
) {
|
|
298
|
-
let returnType: string = "HttpResponse";
|
|
299
|
-
if (operation.responses && operation.responses.length) {
|
|
300
|
-
const responses = [...operation.responses, ...(operation.exceptions || [])];
|
|
301
|
-
|
|
302
|
-
const responseTypes = responses
|
|
303
|
-
.filter(
|
|
304
|
-
r => r.protocol.http?.statusCodes && r.protocol.http?.statusCodes.length
|
|
305
|
-
)
|
|
306
|
-
.map(r => {
|
|
307
|
-
const responseName = getResponseTypeName(operation, r);
|
|
308
|
-
importedResponses.add(responseName);
|
|
309
|
-
return responseName;
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
if (responseTypes.length) {
|
|
313
|
-
returnType = responseTypes.join(" | ");
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return returnType;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function getPathFirstRoutesInterfaceDefinition(
|
|
321
|
-
paths: Paths,
|
|
322
|
-
sourcefile: SourceFile
|
|
323
|
-
): CallSignatureDeclarationStructure[] {
|
|
324
|
-
const signatures: CallSignatureDeclarationStructure[] = [];
|
|
325
|
-
for (const key of Object.keys(paths)) {
|
|
326
|
-
generatePathFirstRouteMethodsDefinition(
|
|
327
|
-
paths[key].name,
|
|
328
|
-
paths[key].methods,
|
|
329
|
-
sourcefile
|
|
330
|
-
);
|
|
331
|
-
const pathParams = paths[key].pathParameters;
|
|
332
|
-
signatures.push({
|
|
333
|
-
docs: [
|
|
334
|
-
`Resource for '${key
|
|
335
|
-
.replace(/}/g, "\\}")
|
|
336
|
-
.replace(
|
|
337
|
-
/{/g,
|
|
338
|
-
"\\{"
|
|
339
|
-
)}' has methods for the following verbs: ${Object.keys(
|
|
340
|
-
paths[key].methods
|
|
341
|
-
).join(", ")}`
|
|
342
|
-
],
|
|
343
|
-
parameters: [
|
|
344
|
-
{ name: "path", type: `"${key}"` },
|
|
345
|
-
...pathParams.map(p => {
|
|
346
|
-
return { name: p.name, type: "string", description: p.description };
|
|
347
|
-
})
|
|
348
|
-
],
|
|
349
|
-
returnType: paths[key].name,
|
|
350
|
-
kind: StructureKind.CallSignature
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
return signatures;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
201
|
function getClientUriParameter() {
|
|
357
202
|
const { model } = getSession();
|
|
358
203
|
const { parameterName } = transformBaseUrl(model);
|
|
359
204
|
return parameterName;
|
|
360
205
|
}
|
|
361
|
-
|
|
362
|
-
function generatePathFirstRouteMethodsDefinition(
|
|
363
|
-
operationName: string,
|
|
364
|
-
methods: Methods,
|
|
365
|
-
file: SourceFile
|
|
366
|
-
): void {
|
|
367
|
-
const methodDefinitions: OptionalKind<MethodSignatureStructure>[] = [];
|
|
368
|
-
for (const key of Object.keys(methods)) {
|
|
369
|
-
const method = methods[key];
|
|
370
|
-
const description = methods[key][0].description;
|
|
371
|
-
|
|
372
|
-
let areAllOptional = !method.some(m => !m.hasOptionalOptions);
|
|
373
|
-
|
|
374
|
-
methodDefinitions.push({
|
|
375
|
-
name: key,
|
|
376
|
-
...(description && { docs: [{ description }] }),
|
|
377
|
-
parameters: [
|
|
378
|
-
{
|
|
379
|
-
name: "options",
|
|
380
|
-
hasQuestionToken: areAllOptional,
|
|
381
|
-
type: method.map(m => m.optionsName).join(" | ")
|
|
382
|
-
}
|
|
383
|
-
],
|
|
384
|
-
returnType: method.map(m => m.returnType).join(" | ")
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
file.addInterface({
|
|
389
|
-
methods: methodDefinitions,
|
|
390
|
-
name: operationName,
|
|
391
|
-
isExported: true
|
|
392
|
-
});
|
|
393
|
-
}
|