@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
|
@@ -4,12 +4,15 @@ import { getAutorestOptions, getSession } from "../autorestSession";
|
|
|
4
4
|
import { NameType, normalizeName } from "../utils/nameUtils";
|
|
5
5
|
import { hasPagingOperations } from "../utils/extractPaginationDetails";
|
|
6
6
|
import { hasPollingOperations } from "../restLevelClient/helpers/hasPollingOperations";
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
hasInputModels,
|
|
9
|
+
hasOutputModels
|
|
10
|
+
} from "../restLevelClient/helpers/modelHelpers";
|
|
8
11
|
export function generateIndexFile(
|
|
9
12
|
project: Project,
|
|
10
13
|
clientDetails?: ClientDetails
|
|
11
14
|
) {
|
|
12
|
-
const { restLevelClient, srcPath } = getAutorestOptions();
|
|
15
|
+
const { restLevelClient, srcPath, multiClient, batch } = getAutorestOptions();
|
|
13
16
|
const indexFile = project.createSourceFile(`${srcPath}/index.ts`, undefined, {
|
|
14
17
|
overwrite: true
|
|
15
18
|
});
|
|
@@ -21,36 +24,122 @@ export function generateIndexFile(
|
|
|
21
24
|
);
|
|
22
25
|
}
|
|
23
26
|
generateHLCIndex(clientDetails, indexFile);
|
|
24
|
-
} else {
|
|
27
|
+
} else if (!multiClient || !batch || batch?.length === 1) {
|
|
28
|
+
// if we are generate single client package for RLC
|
|
25
29
|
generateRLCIndex(indexFile);
|
|
30
|
+
} else {
|
|
31
|
+
generateRLCIndexForMultiClient(indexFile);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
// to generate a index.ts for each single module inside the multi client RLC package
|
|
36
|
+
function generateRLCIndexForMultiClient(file: SourceFile) {
|
|
30
37
|
const { model } = getSession();
|
|
31
38
|
const clientName = model.language.default.name;
|
|
39
|
+
const createClientFuncName = `${clientName}`;
|
|
32
40
|
const moduleName = normalizeName(clientName, NameType.File);
|
|
33
41
|
|
|
34
42
|
file.addImportDeclaration({
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
namespaceImport: "Parameters",
|
|
44
|
+
moduleSpecifier: "./parameters"
|
|
37
45
|
});
|
|
38
46
|
|
|
47
|
+
file.addImportDeclaration({
|
|
48
|
+
namespaceImport: "Responses",
|
|
49
|
+
moduleSpecifier: "./responses"
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
file.addImportDeclaration({
|
|
53
|
+
namespaceImport: "Client",
|
|
54
|
+
moduleSpecifier: "./clientDefinitions"
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const exports = ['Parameters', 'Responses', 'Client'];
|
|
58
|
+
if (hasInputModels(model)) {
|
|
59
|
+
file.addImportDeclaration({
|
|
60
|
+
namespaceImport: "Models",
|
|
61
|
+
moduleSpecifier: "./models",
|
|
62
|
+
});
|
|
63
|
+
exports.push("Models");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (hasOutputModels(model)) {
|
|
67
|
+
file.addImportDeclaration({
|
|
68
|
+
namespaceImport: "OutputModels",
|
|
69
|
+
moduleSpecifier: "./outputModels",
|
|
70
|
+
});
|
|
71
|
+
exports.push("OutputModels");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (hasPagingOperations(model)) {
|
|
75
|
+
file.addImportDeclaration({
|
|
76
|
+
namespaceImport: "PaginateHelper",
|
|
77
|
+
moduleSpecifier: './paginateHelper',
|
|
78
|
+
});
|
|
79
|
+
exports.push("PaginateHelper");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (hasPollingOperations(model)) {
|
|
83
|
+
file.addImportDeclaration({
|
|
84
|
+
namespaceImport: 'PollingHelper',
|
|
85
|
+
moduleSpecifier: './pollingHelper',
|
|
86
|
+
})
|
|
87
|
+
exports.push("PollingHelper");
|
|
88
|
+
}
|
|
89
|
+
|
|
39
90
|
file.addExportDeclarations([
|
|
40
91
|
{
|
|
41
|
-
moduleSpecifier: `./${moduleName}
|
|
92
|
+
moduleSpecifier: `./${moduleName}`,
|
|
93
|
+
namedExports: [createClientFuncName],
|
|
42
94
|
},
|
|
43
95
|
{
|
|
44
|
-
|
|
96
|
+
namedExports: [...exports]
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function generateRLCIndex(file: SourceFile) {
|
|
102
|
+
const { model } = getSession();
|
|
103
|
+
const clientName = model.language.default.name;
|
|
104
|
+
const createClientFuncName = `${clientName}`;
|
|
105
|
+
const moduleName = normalizeName(clientName, NameType.File);
|
|
106
|
+
|
|
107
|
+
file.addImportDeclaration({
|
|
108
|
+
moduleSpecifier: `./${moduleName}`,
|
|
109
|
+
defaultImport: createClientFuncName
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
file.addExportDeclarations([
|
|
113
|
+
{
|
|
114
|
+
moduleSpecifier: `./${moduleName}`,
|
|
45
115
|
},
|
|
46
116
|
{
|
|
47
117
|
moduleSpecifier: "./parameters"
|
|
48
118
|
},
|
|
49
119
|
{
|
|
50
120
|
moduleSpecifier: "./responses"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
moduleSpecifier: "./clientDefinitions"
|
|
51
124
|
}
|
|
52
125
|
]);
|
|
53
126
|
|
|
127
|
+
if (hasInputModels(model)) {
|
|
128
|
+
file.addExportDeclarations([
|
|
129
|
+
{
|
|
130
|
+
moduleSpecifier: "./models"
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (hasOutputModels(model)) {
|
|
136
|
+
file.addExportDeclarations([
|
|
137
|
+
{
|
|
138
|
+
moduleSpecifier: "./outputModels"
|
|
139
|
+
}
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
|
|
54
143
|
if (hasPagingOperations(model)) {
|
|
55
144
|
file.addExportDeclarations([
|
|
56
145
|
{
|
|
@@ -68,7 +157,7 @@ function generateRLCIndex(file: SourceFile) {
|
|
|
68
157
|
}
|
|
69
158
|
|
|
70
159
|
file.addExportAssignment({
|
|
71
|
-
expression:
|
|
160
|
+
expression: createClientFuncName,
|
|
72
161
|
isExportEquals: false
|
|
73
162
|
});
|
|
74
163
|
}
|
|
@@ -86,10 +175,6 @@ function generateHLCIndex(clientDetails: ClientDetails, file: SourceFile) {
|
|
|
86
175
|
{
|
|
87
176
|
moduleSpecifier: `./${clientDetails.sourceFileName}`,
|
|
88
177
|
namedExports: [clientDetails.className]
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
moduleSpecifier: `./${clientDetails.sourceFileName}Context`,
|
|
92
|
-
namedExports: [`${clientDetails.className}Context`]
|
|
93
178
|
}
|
|
94
179
|
]);
|
|
95
180
|
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
MapperConstraints
|
|
20
20
|
} from "@azure/core-http";
|
|
21
21
|
import { ModelProperties } from "../transforms/mapperTransforms";
|
|
22
|
-
import { keys, isEmpty, isString, isNil, isEqual } from "lodash";
|
|
22
|
+
import { keys, isEmpty, isString, isNil, isEqual, List } from "lodash";
|
|
23
23
|
import { getStringForValue, MapperTypes } from "../utils/valueHelpers";
|
|
24
24
|
import { PolymorphicObjectDetails, ObjectKind } from "../models/modelDetails";
|
|
25
25
|
import { logger } from "../utils/logger";
|
|
@@ -57,14 +57,89 @@ export function generateMappers(
|
|
|
57
57
|
mappersFile.fixUnusedIdentifiers();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function getParents(
|
|
61
|
+
mapperParentMap: Map<string, Array<string>>,
|
|
62
|
+
parent: string
|
|
63
|
+
) {
|
|
64
|
+
const list: Array<string> = new Array<string>();
|
|
65
|
+
const parents = mapperParentMap.get(parent);
|
|
66
|
+
|
|
67
|
+
if (!parents) {
|
|
68
|
+
parents!.forEach(pnt => {
|
|
69
|
+
if (!list.includes(pnt)) {
|
|
70
|
+
getParents(mapperParentMap, pnt).forEach(str => list.push(str));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!list.includes(parent)) {
|
|
76
|
+
list.push(parent);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return list;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function traverse(mapperParentMap: Map<string, Array<string>>) {
|
|
83
|
+
const list: Array<string> = new Array<string>();
|
|
84
|
+
mapperParentMap.forEach((value: string[], key: string) => {
|
|
85
|
+
value.forEach(parent => {
|
|
86
|
+
if (!list.includes(parent)) {
|
|
87
|
+
getParents(mapperParentMap, parent).forEach(str => list.push(str));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (!list.includes(key)) {
|
|
91
|
+
list.push(key);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return list;
|
|
95
|
+
}
|
|
96
|
+
|
|
60
97
|
/**
|
|
61
98
|
* This function writes to the mappers.ts file all the mappers to be used by @azure/core-http for serialization
|
|
62
99
|
*/
|
|
63
100
|
function writeMappers(sourceFile: SourceFile, { mappers }: ClientDetails) {
|
|
101
|
+
const mapperParentMap: Map<string, Array<string>> = new Map<
|
|
102
|
+
string,
|
|
103
|
+
Array<string>
|
|
104
|
+
>();
|
|
105
|
+
const mapperPositionMap: Map<string, number> = new Map<string, number>();
|
|
106
|
+
let position = 0;
|
|
107
|
+
mappers.forEach(mapper => {
|
|
108
|
+
const compositeMapper = mapper as CompositeMapper;
|
|
109
|
+
const mapperClassName = compositeMapper.type.className;
|
|
110
|
+
if (!mapperClassName) return;
|
|
111
|
+
mapperPositionMap.set(mapperClassName, position);
|
|
112
|
+
position += 1;
|
|
113
|
+
let listOfParents = mapperParentMap.get(mapperClassName);
|
|
114
|
+
if (!listOfParents) {
|
|
115
|
+
listOfParents = new Array<string>();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
compositeMapper.type.modelProperties &&
|
|
120
|
+
compositeMapper.type.modelProperties.parentsRefs
|
|
121
|
+
) {
|
|
122
|
+
const { parentsRefs } = (compositeMapper.type.modelProperties ||
|
|
123
|
+
{}) as ModelProperties;
|
|
124
|
+
|
|
125
|
+
if (parentsRefs) {
|
|
126
|
+
(parentsRefs as string[]).forEach(parentsRef => {
|
|
127
|
+
listOfParents!.push(parentsRef);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
mapperParentMap.set(mapperClassName, listOfParents);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const modifiedList = traverse(mapperParentMap);
|
|
64
136
|
const { useCoreV2 } = getAutorestOptions();
|
|
65
137
|
const generatedMappers: Map<string, Mapper> = new Map<string, Mapper>();
|
|
66
138
|
|
|
67
|
-
|
|
139
|
+
modifiedList.forEach(name => {
|
|
140
|
+
const arrayIndex = mapperPositionMap.get(name) || 0;
|
|
141
|
+
const mapper = mappers[arrayIndex];
|
|
142
|
+
|
|
68
143
|
const mapperClassName = (mapper as CompositeMapper).type.className;
|
|
69
144
|
if (!mapperClassName) {
|
|
70
145
|
logger.warning(`Expected a mapper with a className, skipping generation`);
|
|
@@ -103,6 +178,19 @@ function writeMappers(sourceFile: SourceFile, { mappers }: ClientDetails) {
|
|
|
103
178
|
leadingTrivia: writer => writer.blankLine()
|
|
104
179
|
});
|
|
105
180
|
|
|
181
|
+
const { polymorphicDiscriminator } = mapper.type as CompositeMapperType;
|
|
182
|
+
|
|
183
|
+
if (polymorphicDiscriminator) {
|
|
184
|
+
if (
|
|
185
|
+
isString(polymorphicDiscriminator) &&
|
|
186
|
+
`${polymorphicDiscriminator}`.startsWith(mapper.serializedName!)
|
|
187
|
+
) {
|
|
188
|
+
sourceFile.addStatements(
|
|
189
|
+
`${polymorphicDiscriminator}=${polymorphicDiscriminator};`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
106
194
|
// Keep track of the mapper we just generated
|
|
107
195
|
generatedMappers.set(mapperClassName, mapper);
|
|
108
196
|
});
|
|
@@ -178,7 +266,7 @@ export function writeMapper(writer: CodeBlockWriter, mapper: Mapper) {
|
|
|
178
266
|
.write("type:")
|
|
179
267
|
.block(() => {
|
|
180
268
|
// Write tipe properties for the current mapper
|
|
181
|
-
writeMapperType(writer, mapper
|
|
269
|
+
writeMapperType(writer, mapper, parents);
|
|
182
270
|
});
|
|
183
271
|
});
|
|
184
272
|
}
|
|
@@ -189,14 +277,16 @@ export function writeMapper(writer: CodeBlockWriter, mapper: Mapper) {
|
|
|
189
277
|
*/
|
|
190
278
|
function writeMapperType(
|
|
191
279
|
writer: CodeBlockWriter,
|
|
192
|
-
|
|
280
|
+
mapper: Mapper,
|
|
193
281
|
parents: string[]
|
|
194
282
|
) {
|
|
283
|
+
const mapperType = mapper.type;
|
|
284
|
+
|
|
195
285
|
if (isSequenceMapperType(mapperType)) {
|
|
196
286
|
return writeSequenceMapperType(writer, mapperType);
|
|
197
287
|
}
|
|
198
288
|
|
|
199
|
-
return writeCompositeMapperType(writer,
|
|
289
|
+
return writeCompositeMapperType(writer, mapper, parents);
|
|
200
290
|
}
|
|
201
291
|
|
|
202
292
|
/**
|
|
@@ -213,9 +303,10 @@ function isSequenceMapperType(
|
|
|
213
303
|
*/
|
|
214
304
|
function writeCompositeMapperType(
|
|
215
305
|
writer: CodeBlockWriter,
|
|
216
|
-
|
|
306
|
+
mapper: Mapper,
|
|
217
307
|
parents: string[]
|
|
218
308
|
) {
|
|
309
|
+
const mapperType = mapper.type;
|
|
219
310
|
const {
|
|
220
311
|
modelProperties,
|
|
221
312
|
polymorphicDiscriminator,
|
|
@@ -223,7 +314,14 @@ function writeCompositeMapperType(
|
|
|
223
314
|
} = mapperType as CompositeMapperType;
|
|
224
315
|
writeObjectProps(restType, writer);
|
|
225
316
|
// Write type properties that need special handling
|
|
226
|
-
|
|
317
|
+
if (polymorphicDiscriminator) {
|
|
318
|
+
if (
|
|
319
|
+
!isString(polymorphicDiscriminator) ||
|
|
320
|
+
!`${polymorphicDiscriminator}`.startsWith(mapper.serializedName!)
|
|
321
|
+
) {
|
|
322
|
+
writePolymorphicDiscriminator(writer, polymorphicDiscriminator);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
227
325
|
writeModelProperties(writer, parents, modelProperties);
|
|
228
326
|
}
|
|
229
327
|
|
|
@@ -258,7 +356,9 @@ function writeMapperContraints(
|
|
|
258
356
|
.block(() => {
|
|
259
357
|
if (Pattern) {
|
|
260
358
|
writer.write(
|
|
261
|
-
`Pattern: new RegExp("${Pattern.source
|
|
359
|
+
`Pattern: new RegExp("${Pattern.source
|
|
360
|
+
.replace(/\\/g, "\\\\")
|
|
361
|
+
.replace(/"/g, '\\"')}"), `
|
|
262
362
|
);
|
|
263
363
|
}
|
|
264
364
|
|
|
@@ -69,6 +69,10 @@ export function generateModels(clientDetails: ClientDetails, project: Project) {
|
|
|
69
69
|
namespaceImport: "coreRestPipeline",
|
|
70
70
|
moduleSpecifier: "@azure/core-rest-pipeline"
|
|
71
71
|
});
|
|
72
|
+
modelsIndexFile.addImportDeclaration({
|
|
73
|
+
namespaceImport: "coreHttpCompat",
|
|
74
|
+
moduleSpecifier: "@azure/core-http-compat"
|
|
75
|
+
});
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
writeUniontypes(clientDetails, modelsIndexFile);
|
|
@@ -77,13 +81,21 @@ export function generateModels(clientDetails: ClientDetails, project: Project) {
|
|
|
77
81
|
writeOperationModels(clientDetails, modelsIndexFile);
|
|
78
82
|
writeClientModels(clientDetails, modelsIndexFile);
|
|
79
83
|
modelsIndexFile.fixUnusedIdentifiers();
|
|
84
|
+
const allTypes = modelsIndexFile.getTypeAliases();
|
|
85
|
+
clientDetails.allTypes = allTypes
|
|
86
|
+
.filter(item => {
|
|
87
|
+
return item.isExported();
|
|
88
|
+
})
|
|
89
|
+
.map(item => {
|
|
90
|
+
return item.getName();
|
|
91
|
+
});
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
const writeClientModels = (
|
|
83
95
|
clientDetails: ClientDetails,
|
|
84
96
|
modelsIndexFile: SourceFile
|
|
85
97
|
) => {
|
|
86
|
-
const { useCoreV2 } = getAutorestOptions();
|
|
98
|
+
const { useCoreV2, coreHttpCompatMode } = getAutorestOptions();
|
|
87
99
|
let clientOptionalParams = clientDetails.parameters.filter(
|
|
88
100
|
p =>
|
|
89
101
|
(!p.required || p.defaultValue) &&
|
|
@@ -97,6 +109,8 @@ const writeClientModels = (
|
|
|
97
109
|
{
|
|
98
110
|
baseClass: !useCoreV2
|
|
99
111
|
? "coreHttp.ServiceClientOptions"
|
|
112
|
+
: coreHttpCompatMode
|
|
113
|
+
? "coreHttpCompat.ExtendedServiceClientOptions"
|
|
100
114
|
: "coreClient.ServiceClientOptions"
|
|
101
115
|
}
|
|
102
116
|
);
|
|
@@ -771,6 +785,12 @@ function getPropertyTypeName(
|
|
|
771
785
|
ignoreNullableOnOptional: boolean
|
|
772
786
|
) {
|
|
773
787
|
if (property.isConstant) {
|
|
788
|
+
if (
|
|
789
|
+
property.type === SchemaType.Number ||
|
|
790
|
+
property.type === SchemaType.Boolean
|
|
791
|
+
) {
|
|
792
|
+
return `${property.defaultValue}`;
|
|
793
|
+
}
|
|
774
794
|
return `"${getStringForValue(
|
|
775
795
|
property.defaultValue,
|
|
776
796
|
property.type,
|
|
@@ -475,7 +475,7 @@ function addClass(
|
|
|
475
475
|
name: "client",
|
|
476
476
|
isReadonly: true,
|
|
477
477
|
scope: Scope.Private,
|
|
478
|
-
type: `${clientDetails.className}
|
|
478
|
+
type: `${clientDetails.className}`
|
|
479
479
|
});
|
|
480
480
|
const constructorDefinition = operationGroupClass.addConstructor({
|
|
481
481
|
docs: [
|
|
@@ -487,7 +487,7 @@ function addClass(
|
|
|
487
487
|
{
|
|
488
488
|
name: "client",
|
|
489
489
|
hasQuestionToken: false,
|
|
490
|
-
type: `${clientDetails.className}
|
|
490
|
+
type: `${clientDetails.className}`
|
|
491
491
|
}
|
|
492
492
|
]
|
|
493
493
|
});
|
|
@@ -1319,16 +1319,16 @@ function addImports(
|
|
|
1319
1319
|
});
|
|
1320
1320
|
}
|
|
1321
1321
|
|
|
1322
|
-
const
|
|
1322
|
+
const clientClassName = `${className}`;
|
|
1323
1323
|
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1324
|
+
const clientFileName = normalizeName(
|
|
1325
|
+
clientClassName,
|
|
1326
1326
|
NameType.File
|
|
1327
1327
|
);
|
|
1328
1328
|
|
|
1329
1329
|
operationGroupFile.addImportDeclaration({
|
|
1330
|
-
namedImports: [`${
|
|
1331
|
-
moduleSpecifier: `../${
|
|
1330
|
+
namedImports: [`${clientClassName}`],
|
|
1331
|
+
moduleSpecifier: `../${clientFileName}`
|
|
1332
1332
|
});
|
|
1333
1333
|
|
|
1334
1334
|
if (hasLroOperation(operationGroupDetails)) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as hbs from 'handlebars';
|
|
4
|
+
import { Project } from 'ts-morph';
|
|
5
|
+
|
|
6
|
+
export function generateSampleEnv(project: Project) {
|
|
7
|
+
const file = fs.readFileSync(path.join(__dirname, "sampleEnv.hbs"), {
|
|
8
|
+
encoding: "utf-8"
|
|
9
|
+
});
|
|
10
|
+
const readmeFileContents = hbs.compile(file, { noEscape: true });
|
|
11
|
+
project.createSourceFile("sample.env", readmeFileContents({}), {
|
|
12
|
+
overwrite: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Project,
|
|
6
|
+
SourceFile
|
|
7
|
+
} from "ts-morph";
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as hbs from "handlebars";
|
|
11
|
+
import { getAutorestOptions, getSession } from "../../autorestSession";
|
|
12
|
+
import { ClientDetails } from "../../models/clientDetails";
|
|
13
|
+
import { SampleGroup } from "../../models/sampleDetails";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Function that writes the code for all the operations.
|
|
17
|
+
* It will generate one file per operation group and each file contains:
|
|
18
|
+
* - A class definition for the operation group
|
|
19
|
+
* - Methods and overrides for each operation
|
|
20
|
+
* - OperationSpecs for each operation
|
|
21
|
+
* @param clientDetails client details
|
|
22
|
+
* @param project project for code generation
|
|
23
|
+
*/
|
|
24
|
+
export function generateSamples(
|
|
25
|
+
clientDetails: ClientDetails,
|
|
26
|
+
project: Project
|
|
27
|
+
): void {
|
|
28
|
+
// Toplevel operations are inlined in the client
|
|
29
|
+
const sampleGroups = clientDetails.samples;
|
|
30
|
+
const session = getSession();
|
|
31
|
+
if (!sampleGroups) {
|
|
32
|
+
session.error("No samples are found! ", []);
|
|
33
|
+
}
|
|
34
|
+
for (const sampleGroup of sampleGroups as SampleGroup[]) {
|
|
35
|
+
try {
|
|
36
|
+
const file = fs.readFileSync(path.join(__dirname, "../static/samples.ts.hbs"), {
|
|
37
|
+
encoding: "utf-8"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const sampleGroupFileContents = hbs.compile(file, { noEscape: true });
|
|
41
|
+
project.createSourceFile(`samples-dev/${sampleGroup.sampleFileName}.ts`, sampleGroupFileContents(sampleGroup), {
|
|
42
|
+
overwrite: true
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
session.error("An error was encountered while handling sample generation", [sampleGroup.sampleFileName]);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -24,6 +24,8 @@ This package contains an isomorphic SDK (runs both in Node.js and in browsers) f
|
|
|
24
24
|
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
|
25
25
|
- Latest versions of Safari, Chrome, Edge and Firefox.
|
|
26
26
|
|
|
27
|
+
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
|
|
28
|
+
|
|
27
29
|
{{#if azure}}
|
|
28
30
|
### Prerequisites
|
|
29
31
|
|
|
@@ -64,17 +66,38 @@ For more information about how to create an Azure AD Application check out [this
|
|
|
64
66
|
```javascript
|
|
65
67
|
const { {{ clientClassName }} } = require("{{ clientPackageName }}");
|
|
66
68
|
const { DefaultAzureCredential } = require("@azure/identity");
|
|
69
|
+
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
|
|
70
|
+
|
|
67
71
|
const subscriptionId = "00000000-0000-0000-0000-000000000000";
|
|
68
72
|
const client = new {{ clientClassName }}(new DefaultAzureCredential(), subscriptionId);
|
|
73
|
+
|
|
74
|
+
// For client-side applications running in the browser, use this code instead:
|
|
75
|
+
// const credential = new InteractiveBrowserCredential({
|
|
76
|
+
// tenantId: "<YOUR_TENANT_ID>",
|
|
77
|
+
// clientId: "<YOUR_CLIENT_ID>"
|
|
78
|
+
// });
|
|
79
|
+
// const client = new {{ clientClassName }}(credential, subscriptionId);
|
|
69
80
|
```
|
|
70
81
|
{{else}}
|
|
71
82
|
```javascript
|
|
72
83
|
const { {{ clientClassName }} } = require("{{ clientPackageName }}");
|
|
73
84
|
const { DefaultAzureCredential } = require("@azure/identity");
|
|
85
|
+
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
|
|
86
|
+
|
|
74
87
|
const client = new {{ clientClassName }}("<endpoint>", new DefaultAzureCredential());
|
|
88
|
+
// For client-side applications running in the browser, use this code instead:
|
|
89
|
+
// const credential = new InteractiveBrowserCredential({
|
|
90
|
+
// tenantId: "<YOUR_TENANT_ID>",
|
|
91
|
+
// clientId: "<YOUR_CLIENT_ID>"
|
|
92
|
+
// });
|
|
93
|
+
// const client = new {{ clientClassName }}("<endpoint>", credential);
|
|
75
94
|
```
|
|
76
95
|
{{/if}}
|
|
77
96
|
{{/if}}{{/if}}
|
|
97
|
+
|
|
98
|
+
### JavaScript Bundle
|
|
99
|
+
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).
|
|
100
|
+
|
|
78
101
|
## Key concepts
|
|
79
102
|
|
|
80
103
|
### {{ clientClassName }}
|