@azure-tools/typespec-ts 0.14.0 → 0.15.0-alpha.20230822.1
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 +9 -0
- package/dist/src/index.d.ts +1 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +148 -78
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +4 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +27 -15
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +16 -7
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +59 -12
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +2 -1
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +25 -29
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts +2 -2
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +284 -145
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +5 -5
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +9 -2
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +3 -2
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +40 -7
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +5 -3
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/docsHelpers.d.ts +3 -0
- package/dist/src/modular/helpers/docsHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/docsHelpers.js +10 -0
- package/dist/src/modular/helpers/docsHelpers.js.map +1 -0
- package/dist/src/modular/helpers/operationHelpers.d.ts +11 -4
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +197 -56
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -0
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +2 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transform.d.ts +5 -8
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +23 -13
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts +2 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts +2 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +4 -10
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +2 -12
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +6 -47
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts +2 -2
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts +2 -2
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +5 -1
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts +2 -2
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts +4 -0
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -0
- package/dist/src/transform/transformTelemetryInfo.js +42 -0
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -0
- package/dist/src/transform/transfromRLCOptions.d.ts +4 -2
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +72 -19
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/clientUtils.d.ts +2 -1
- package/dist/src/utils/clientUtils.d.ts.map +1 -1
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/interfaces.d.ts +13 -0
- package/dist/src/utils/interfaces.d.ts.map +1 -0
- package/dist/src/utils/interfaces.js +2 -0
- package/dist/src/utils/interfaces.js.map +1 -0
- package/dist/src/utils/modelUtils.d.ts +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +25 -20
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +15 -4
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +65 -1
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -18
- package/src/index.ts +231 -129
- package/src/lib.ts +4 -2
- package/src/modular/buildClassicalClient.ts +33 -16
- package/src/modular/buildClientContext.ts +18 -8
- package/src/modular/buildCodeModel.ts +71 -13
- package/src/modular/buildOperations.ts +31 -36
- package/src/modular/buildProjectFiles.ts +329 -162
- package/src/modular/buildRootIndex.ts +5 -7
- package/src/modular/buildSubpathIndex.ts +9 -2
- package/src/modular/emitModels.ts +55 -9
- package/src/modular/helpers/clientHelpers.ts +5 -3
- package/src/modular/helpers/docsHelpers.ts +10 -0
- package/src/modular/helpers/operationHelpers.ts +328 -75
- package/src/modular/helpers/typeHelpers.ts +6 -0
- package/src/modular/modularCodeModel.ts +2 -0
- package/src/transform/transform.ts +24 -31
- package/src/transform/transformApiVersionInfo.ts +1 -1
- package/src/transform/transformHelperFunctionDetails.ts +12 -11
- package/src/transform/transformParameters.ts +20 -63
- package/src/transform/transformPaths.ts +5 -5
- package/src/transform/transformResponses.ts +10 -6
- package/src/transform/transformSchemas.ts +2 -2
- package/src/transform/transformTelemetryInfo.ts +72 -0
- package/src/transform/transfromRLCOptions.ts +100 -23
- package/src/utils/clientUtils.ts +2 -4
- package/src/utils/interfaces.ts +14 -0
- package/src/utils/modelUtils.ts +18 -11
- package/src/utils/operationUtil.ts +92 -6
- package/dist/src/modular/helpers/fixmeHelpers.d.ts +0 -2
- package/dist/src/modular/helpers/fixmeHelpers.d.ts.map +0 -1
- package/dist/src/modular/helpers/fixmeHelpers.js +0 -4
- package/dist/src/modular/helpers/fixmeHelpers.js.map +0 -1
- package/dist/src/modular/helpers/parameterHelpers.d.ts +0 -3
- package/dist/src/modular/helpers/parameterHelpers.d.ts.map +0 -1
- package/dist/src/modular/helpers/parameterHelpers.js +0 -16
- package/dist/src/modular/helpers/parameterHelpers.js.map +0 -1
- package/src/modular/helpers/fixmeHelpers.ts +0 -3
- package/src/modular/helpers/parameterHelpers.ts +0 -17
|
@@ -4,7 +4,9 @@ import { importCredential } from "./helpers/credentialHelpers.js";
|
|
|
4
4
|
import { getClientName } from "./helpers/namingHelpers.js";
|
|
5
5
|
import { Client, Parameter } from "./modularCodeModel.js";
|
|
6
6
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
8
|
+
import { importModels } from "./buildOperations.js";
|
|
9
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* This function creates the file containing the modular client context
|
|
@@ -19,12 +21,13 @@ export function buildClientContext(
|
|
|
19
21
|
const { description, parameters } = client;
|
|
20
22
|
const name = getClientName(client);
|
|
21
23
|
const clientContextFile = project.createSourceFile(
|
|
22
|
-
`${srcPath}
|
|
24
|
+
`${srcPath}/${
|
|
23
25
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
24
26
|
}/api/${name}Context.ts`
|
|
25
27
|
);
|
|
26
28
|
|
|
27
29
|
let factoryFunction;
|
|
30
|
+
importModels(srcPath, clientContextFile, project, subfolder);
|
|
28
31
|
clientContextFile.addImportDeclaration({
|
|
29
32
|
moduleSpecifier: "@azure-rest/core-client",
|
|
30
33
|
namedImports: ["ClientOptions"]
|
|
@@ -47,7 +50,7 @@ export function buildClientContext(
|
|
|
47
50
|
namedExports: [`Client`]
|
|
48
51
|
});
|
|
49
52
|
factoryFunction = clientContextFile.addFunction({
|
|
50
|
-
docs:
|
|
53
|
+
docs: getDocsFromDescription(description),
|
|
51
54
|
name: `create${name}`,
|
|
52
55
|
returnType: `Client.${client.name}`,
|
|
53
56
|
parameters: getClientParameters(client),
|
|
@@ -70,7 +73,7 @@ export function buildClientContext(
|
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
factoryFunction = clientContextFile.addFunction({
|
|
73
|
-
docs:
|
|
76
|
+
docs: getDocsFromDescription(description),
|
|
74
77
|
name: `create${name}`,
|
|
75
78
|
returnType: `${rlcClientName}`,
|
|
76
79
|
parameters: getClientParameters(client),
|
|
@@ -86,22 +89,28 @@ export function buildClientContext(
|
|
|
86
89
|
(p) => p.location === "endpointPath"
|
|
87
90
|
);
|
|
88
91
|
|
|
89
|
-
let baseUrl: string | undefined = "endpoint";
|
|
90
92
|
if (baseUrlParam) {
|
|
93
|
+
let baseUrl: string | undefined = "endpoint";
|
|
91
94
|
baseUrl =
|
|
92
95
|
baseUrlParam.type.type === "constant"
|
|
93
96
|
? baseUrlParam.type.value
|
|
94
97
|
: baseUrlParam.clientName;
|
|
98
|
+
factoryFunction.addStatements([`const baseUrl = ${baseUrl}`]);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
let getClientStatement = `const clientContext = getClient(options)`;
|
|
102
|
+
|
|
103
|
+
if (baseUrlParam) {
|
|
104
|
+
getClientStatement = `const clientContext = getClient(baseUrl, options)`;
|
|
105
|
+
}
|
|
99
106
|
|
|
100
107
|
// If the client needs credentials we need to pass those to getClient
|
|
101
108
|
if (credentialsParam) {
|
|
102
109
|
importCredential(credentialsParam.type, clientContextFile);
|
|
103
110
|
addCredentialOptionsStatement(credentialsParam, factoryFunction);
|
|
104
|
-
getClientStatement =
|
|
111
|
+
getClientStatement = baseUrlParam
|
|
112
|
+
? `const clientContext = getClient(baseUrl, credential, options)`
|
|
113
|
+
: `const clientContext = getClient(credential, options)`;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
factoryFunction.addStatements([getClientStatement, "return clientContext;"]);
|
|
@@ -129,6 +138,7 @@ export function buildClientContext(
|
|
|
129
138
|
{ importModuleSpecifierEnding: "js" }
|
|
130
139
|
);
|
|
131
140
|
|
|
141
|
+
clientContextFile.fixUnusedIdentifiers();
|
|
132
142
|
return clientContextFile;
|
|
133
143
|
}
|
|
134
144
|
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
IntrinsicType,
|
|
38
38
|
getProjectedName,
|
|
39
39
|
isNullType,
|
|
40
|
+
getEncode,
|
|
40
41
|
isTemplateDeclarationOrInstance
|
|
41
42
|
} from "@typespec/compiler";
|
|
42
43
|
import {
|
|
@@ -65,7 +66,6 @@ import {
|
|
|
65
66
|
getDefaultApiVersion,
|
|
66
67
|
getClientNamespaceString,
|
|
67
68
|
createSdkContext,
|
|
68
|
-
SdkContext,
|
|
69
69
|
getSdkUnion,
|
|
70
70
|
getAllModels,
|
|
71
71
|
SdkSimpleType,
|
|
@@ -90,6 +90,7 @@ import {
|
|
|
90
90
|
getOperationGroupName,
|
|
91
91
|
getOperationName
|
|
92
92
|
} from "../utils/operationUtil.js";
|
|
93
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
93
94
|
|
|
94
95
|
interface HttpServerParameter {
|
|
95
96
|
type: "endpointPath";
|
|
@@ -460,7 +461,8 @@ function emitParameter(
|
|
|
460
461
|
location: parameter.type,
|
|
461
462
|
type: type,
|
|
462
463
|
implementation: implementation,
|
|
463
|
-
skipUrlEncoding: parameter.type === "endpointPath"
|
|
464
|
+
skipUrlEncoding: parameter.type === "endpointPath",
|
|
465
|
+
format: (parameter as any).format
|
|
464
466
|
};
|
|
465
467
|
|
|
466
468
|
if (paramMap.type.type === "constant") {
|
|
@@ -844,6 +846,10 @@ function emitProperty(
|
|
|
844
846
|
clientDefaultValue = property.default.value;
|
|
845
847
|
}
|
|
846
848
|
|
|
849
|
+
if (propertyDefaultKind === "EnumMember") {
|
|
850
|
+
clientDefaultValue = property.default.value ?? property.default.name;
|
|
851
|
+
}
|
|
852
|
+
|
|
847
853
|
// const [clientName, jsonName] = getPropertyNames(context, property);
|
|
848
854
|
const clientName = property.name;
|
|
849
855
|
const jsonName =
|
|
@@ -895,9 +901,35 @@ function emitModel(context: SdkContext, type: Model): Record<string, any> {
|
|
|
895
901
|
baseModel = getType(context, type.baseModel);
|
|
896
902
|
}
|
|
897
903
|
const effectiveName = getEffectiveSchemaType(context.program, type).name;
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
904
|
+
const overridedModelName =
|
|
905
|
+
getProjectedName(context.program, type, "javascript") ??
|
|
906
|
+
getProjectedName(context.program, type, "client") ??
|
|
907
|
+
getFriendlyName(context.program, type);
|
|
908
|
+
let modelName =
|
|
909
|
+
overridedModelName ??
|
|
910
|
+
(effectiveName ? effectiveName : getName(context.program, type));
|
|
911
|
+
if (
|
|
912
|
+
!overridedModelName &&
|
|
913
|
+
type.templateMapper &&
|
|
914
|
+
type.templateMapper.args &&
|
|
915
|
+
type.templateMapper.args.length > 0 &&
|
|
916
|
+
getPagedResult(context.program, type)
|
|
917
|
+
) {
|
|
918
|
+
modelName =
|
|
919
|
+
type.templateMapper.args
|
|
920
|
+
.map((it) => {
|
|
921
|
+
switch (it.kind) {
|
|
922
|
+
case "Model":
|
|
923
|
+
return it.name;
|
|
924
|
+
case "String":
|
|
925
|
+
return it.value;
|
|
926
|
+
default:
|
|
927
|
+
return "";
|
|
928
|
+
}
|
|
929
|
+
})
|
|
930
|
+
.join("") + "List";
|
|
931
|
+
}
|
|
932
|
+
|
|
901
933
|
return {
|
|
902
934
|
type: "model",
|
|
903
935
|
name: modelName,
|
|
@@ -996,11 +1028,12 @@ function emitCredentialUnion(cred_types: CredentialTypeUnion) {
|
|
|
996
1028
|
}
|
|
997
1029
|
|
|
998
1030
|
function emitStdScalar(
|
|
1031
|
+
program: Program,
|
|
999
1032
|
scalar: Scalar & { name: IntrinsicScalarName }
|
|
1000
1033
|
): Record<string, any> {
|
|
1001
1034
|
switch (scalar.name) {
|
|
1002
1035
|
case "bytes":
|
|
1003
|
-
return { type: "byte-array", format:
|
|
1036
|
+
return { type: "byte-array", format: getEncode(program, scalar) };
|
|
1004
1037
|
case "int8":
|
|
1005
1038
|
case "int16":
|
|
1006
1039
|
case "int32":
|
|
@@ -1095,7 +1128,7 @@ function applyIntrinsicDecorators(
|
|
|
1095
1128
|
function emitScalar(program: Program, scalar: Scalar): Record<string, any> {
|
|
1096
1129
|
let result: Record<string, any> = {};
|
|
1097
1130
|
if (program.checker.isStdType(scalar)) {
|
|
1098
|
-
result = emitStdScalar(scalar);
|
|
1131
|
+
result = emitStdScalar(program, scalar);
|
|
1099
1132
|
} else if (scalar.baseScalar) {
|
|
1100
1133
|
result = emitScalar(program, scalar.baseScalar);
|
|
1101
1134
|
}
|
|
@@ -1286,9 +1319,38 @@ function emitOperationGroups(
|
|
|
1286
1319
|
operations: clientOperations
|
|
1287
1320
|
});
|
|
1288
1321
|
}
|
|
1322
|
+
resolveConflictIfExist(operationGroups);
|
|
1289
1323
|
return operationGroups;
|
|
1290
1324
|
}
|
|
1291
1325
|
|
|
1326
|
+
function resolveConflictIfExist(operationGroups: OperationGroup[]) {
|
|
1327
|
+
if (operationGroups.length < 2) {
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
const nameSet = new Set<string>();
|
|
1332
|
+
const hasConflict = operationGroups.some((g) =>
|
|
1333
|
+
g.operations.some((op) => {
|
|
1334
|
+
if (nameSet.has(op.name)) {
|
|
1335
|
+
return true;
|
|
1336
|
+
} else {
|
|
1337
|
+
nameSet.add(op.name);
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
})
|
|
1341
|
+
);
|
|
1342
|
+
if (!hasConflict) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
// Append operation group prefix
|
|
1346
|
+
operationGroups.forEach((g) =>
|
|
1347
|
+
g.operations.forEach((op) => {
|
|
1348
|
+
op.oriName = op.name;
|
|
1349
|
+
op.name = `${g.propertyName}_${op.name}`;
|
|
1350
|
+
})
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1292
1354
|
function getServerHelper(
|
|
1293
1355
|
program: Program,
|
|
1294
1356
|
namespace: Namespace
|
|
@@ -1313,7 +1375,7 @@ function emitServerParams(
|
|
|
1313
1375
|
clientName: "endpoint",
|
|
1314
1376
|
clientDefaultValue: null,
|
|
1315
1377
|
restApiName: "$host",
|
|
1316
|
-
location: "
|
|
1378
|
+
location: "endpointPath",
|
|
1317
1379
|
type: { type: "string" },
|
|
1318
1380
|
implementation: "Client",
|
|
1319
1381
|
inOverload: false
|
|
@@ -1509,11 +1571,7 @@ export function emitCodeModel(
|
|
|
1509
1571
|
getClientNamespaceString(dpgContext)?.toLowerCase();
|
|
1510
1572
|
// Get types
|
|
1511
1573
|
const codeModel: ModularCodeModel = {
|
|
1512
|
-
options: transformRLCOptions(
|
|
1513
|
-
context.options as any,
|
|
1514
|
-
context.emitterOutputDir,
|
|
1515
|
-
dpgContext
|
|
1516
|
-
),
|
|
1574
|
+
options: transformRLCOptions(context.options as any, dpgContext),
|
|
1517
1575
|
namespace: clientNamespaceString,
|
|
1518
1576
|
subnamespaceToClients: {},
|
|
1519
1577
|
clients: [],
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Project, SourceFile } from "ts-morph";
|
|
2
|
+
import { NameType, normalizeName } from "@azure-tools/rlc-common";
|
|
2
3
|
import { buildType } from "./helpers/typeHelpers.js";
|
|
3
4
|
import {
|
|
4
5
|
getOperationFunction,
|
|
@@ -8,7 +9,8 @@ import {
|
|
|
8
9
|
} from "./helpers/operationHelpers.js";
|
|
9
10
|
import { Client, Operation } from "./modularCodeModel.js";
|
|
10
11
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
11
|
-
import {
|
|
12
|
+
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
13
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* This function creates a file under /api for each operation group.
|
|
@@ -24,14 +26,15 @@ export function buildOperationFiles(
|
|
|
24
26
|
needUnexpectedHelper: boolean = true
|
|
25
27
|
) {
|
|
26
28
|
for (const operationGroup of client.operationGroups) {
|
|
29
|
+
const importSet: Map<string, Set<string>> = new Map<string, Set<string>>();
|
|
27
30
|
const fileName = operationGroup.className
|
|
28
|
-
? `${operationGroup.className}`
|
|
31
|
+
? `${normalizeName(operationGroup.className, NameType.File)}`
|
|
29
32
|
: // When the program has no operation groups defined all operations are put
|
|
30
33
|
// into a nameless operation group. We'll call this operations.
|
|
31
34
|
"operations";
|
|
32
35
|
|
|
33
36
|
const operationGroupFile = project.createSourceFile(
|
|
34
|
-
`${srcPath}
|
|
37
|
+
`${srcPath}/${
|
|
35
38
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
36
39
|
}api/${fileName}.ts`
|
|
37
40
|
);
|
|
@@ -69,17 +72,18 @@ export function buildOperationFiles(
|
|
|
69
72
|
}
|
|
70
73
|
]);
|
|
71
74
|
}
|
|
72
|
-
const modelOptionsFile = project.createSourceFile(
|
|
73
|
-
`${srcPath}/src/${subfolder}/models/options.ts`
|
|
74
|
-
);
|
|
75
75
|
operationGroup.operations.forEach((o) => {
|
|
76
|
-
buildOperationOptions(o, modelOptionsFile);
|
|
77
76
|
const operationDeclaration = getOperationFunction(o, clientType);
|
|
78
|
-
const sendOperationDeclaration = getSendPrivateFunction(
|
|
77
|
+
const sendOperationDeclaration = getSendPrivateFunction(
|
|
78
|
+
o,
|
|
79
|
+
clientType,
|
|
80
|
+
importSet
|
|
81
|
+
);
|
|
79
82
|
const deserializeOperationDeclaration = getDeserializePrivateFunction(
|
|
80
83
|
o,
|
|
81
84
|
isRLCMultiEndpoint(dpgContext),
|
|
82
|
-
needUnexpectedHelper
|
|
85
|
+
needUnexpectedHelper,
|
|
86
|
+
importSet
|
|
83
87
|
);
|
|
84
88
|
operationGroupFile.addFunctions([
|
|
85
89
|
sendOperationDeclaration,
|
|
@@ -97,41 +101,30 @@ export function buildOperationFiles(
|
|
|
97
101
|
]
|
|
98
102
|
}
|
|
99
103
|
]);
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
if (importSet.size > 0) {
|
|
105
|
+
for (const [moduleName, imports] of importSet.entries()) {
|
|
106
|
+
operationGroupFile.addImportDeclarations([
|
|
107
|
+
{
|
|
108
|
+
moduleSpecifier: moduleName,
|
|
109
|
+
namedImports: [...imports.values()]
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
modelOptionsFile.fixMissingImports();
|
|
108
|
-
modelOptionsFile
|
|
109
|
-
.getImportDeclarations()
|
|
110
|
-
.filter((id) => {
|
|
111
|
-
return (
|
|
112
|
-
id.isModuleSpecifierRelative() &&
|
|
113
|
-
!id.getModuleSpecifierValue().endsWith(".js")
|
|
114
|
-
);
|
|
115
|
-
})
|
|
116
|
-
.map((id) => {
|
|
117
|
-
id.setModuleSpecifier(id.getModuleSpecifierValue() + ".js");
|
|
118
|
-
return id;
|
|
119
|
-
});
|
|
120
|
-
|
|
113
|
+
}
|
|
121
114
|
operationGroupFile.fixMissingImports();
|
|
122
115
|
// have to fixUnusedIdentifiers after everything get generated.
|
|
123
116
|
operationGroupFile.fixUnusedIdentifiers();
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
|
|
127
|
-
function importModels(
|
|
120
|
+
export function importModels(
|
|
128
121
|
srcPath: string,
|
|
129
122
|
sourceFile: SourceFile,
|
|
130
123
|
project: Project,
|
|
131
124
|
subfolder: string = ""
|
|
132
125
|
) {
|
|
133
126
|
const modelsFile = project.getSourceFile(
|
|
134
|
-
`${srcPath}
|
|
127
|
+
`${srcPath}/${
|
|
135
128
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
136
129
|
}models/models.ts`
|
|
137
130
|
);
|
|
@@ -141,10 +134,12 @@ function importModels(
|
|
|
141
134
|
models.push(entry[0]);
|
|
142
135
|
}
|
|
143
136
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
137
|
+
if (models.length > 0) {
|
|
138
|
+
sourceFile.addImportDeclaration({
|
|
139
|
+
moduleSpecifier: "../models/models.js",
|
|
140
|
+
namedImports: models
|
|
141
|
+
});
|
|
142
|
+
}
|
|
148
143
|
|
|
149
144
|
// Import all models and then let ts-morph clean up the unused ones
|
|
150
145
|
// we can't fixUnusedIdentifiers here because the operaiton files are still being generated.
|
|
@@ -174,7 +169,7 @@ export function buildOperationOptions(
|
|
|
174
169
|
extends: ["OperationOptions"],
|
|
175
170
|
properties: options.map((p) => {
|
|
176
171
|
return {
|
|
177
|
-
docs:
|
|
172
|
+
docs: getDocsFromDescription(p.description),
|
|
178
173
|
hasQuestionToken: true,
|
|
179
174
|
...buildType(p.clientName, p.type)
|
|
180
175
|
};
|