@azure-tools/typespec-ts 0.55.0-dev.8 → 0.55.0-dev.9
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/README.md +1 -77
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -80
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +2 -12
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +0 -65
- package/dist/src/lib.js.map +1 -1
- package/dist/src/rlc-common/helpers/name-constructors.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/name-constructors.js +1 -7
- package/dist/src/rlc-common/helpers/name-constructors.js.map +1 -1
- package/dist/src/rlc-common/index.d.ts +0 -16
- package/dist/src/rlc-common/index.d.ts.map +1 -1
- package/dist/src/rlc-common/index.js +0 -16
- package/dist/src/rlc-common/index.js.map +1 -1
- package/dist/src/rlc-common/interfaces.d.ts +0 -10
- package/dist/src/rlc-common/interfaces.d.ts.map +1 -1
- package/dist/src/rlc-common/interfaces.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js +0 -12
- package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.js +4 -89
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts +0 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js +2 -2
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.js.map +1 -1
- package/dist/src/rlc-common/test/build-snippets.d.ts.map +1 -1
- package/dist/src/rlc-common/test/build-snippets.js +0 -1
- package/dist/src/rlc-common/test/build-snippets.js.map +1 -1
- package/dist/src/rlc-common/test/template.d.ts +1 -1
- package/dist/src/rlc-common/test/template.d.ts.map +1 -1
- package/dist/src/rlc-common/test/template.js +0 -4
- package/dist/src/rlc-common/test/template.js.map +1 -1
- package/dist/src/transform/transform-schemas.js +1 -1
- package/dist/src/transform/transform-schemas.js.map +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +5 -11
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.d.ts +2 -2
- package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.js +19 -39
- package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
- package/dist/src/utils/client-utils.d.ts +1 -1
- package/dist/src/utils/client-utils.d.ts.map +1 -1
- package/dist/src/utils/client-utils.js +4 -5
- package/dist/src/utils/client-utils.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts +0 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +0 -13
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/model-utils.d.ts +1 -1
- package/dist/src/utils/model-utils.d.ts.map +1 -1
- package/dist/src/utils/model-utils.js +4 -11
- package/dist/src/utils/model-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -15
- package/src/index.ts +27 -105
- package/src/lib.ts +1 -77
- package/src/rlc-common/helpers/name-constructors.ts +1 -8
- package/src/rlc-common/index.ts +0 -16
- package/src/rlc-common/interfaces.ts +0 -11
- package/src/rlc-common/metadata/build-package-file.ts +0 -13
- package/src/rlc-common/metadata/build-readme-file.ts +4 -99
- package/src/rlc-common/metadata/package-json/build-azure-monorepo-package.ts +2 -3
- package/src/rlc-common/metadata/package-json/package-common.ts +0 -1
- package/src/rlc-common/test/build-snippets.ts +0 -1
- package/src/rlc-common/test/template.ts +0 -4
- package/src/transform/transform-schemas.ts +1 -1
- package/src/transform/transform.ts +4 -14
- package/src/transform/transfrom-rlc-options.ts +19 -63
- package/src/utils/client-utils.ts +4 -5
- package/src/utils/emit-util.ts +1 -14
- package/src/utils/model-utils.ts +4 -17
- package/dist/src/rlc-common/build-client-definitions.d.ts +0 -6
- package/dist/src/rlc-common/build-client-definitions.d.ts.map +0 -1
- package/dist/src/rlc-common/build-client-definitions.js +0 -157
- package/dist/src/rlc-common/build-client-definitions.js.map +0 -1
- package/dist/src/rlc-common/build-client.d.ts +0 -9
- package/dist/src/rlc-common/build-client.d.ts.map +0 -1
- package/dist/src/rlc-common/build-client.js +0 -375
- package/dist/src/rlc-common/build-client.js.map +0 -1
- package/dist/src/rlc-common/build-index-file.d.ts +0 -6
- package/dist/src/rlc-common/build-index-file.d.ts.map +0 -1
- package/dist/src/rlc-common/build-index-file.js +0 -180
- package/dist/src/rlc-common/build-index-file.js.map +0 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-is-unexpected-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +0 -219
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +0 -1
- package/dist/src/rlc-common/build-logger.d.ts +0 -6
- package/dist/src/rlc-common/build-logger.d.ts.map +0 -1
- package/dist/src/rlc-common/build-logger.js +0 -23
- package/dist/src/rlc-common/build-logger.js.map +0 -1
- package/dist/src/rlc-common/build-method-shortcuts.d.ts +0 -5
- package/dist/src/rlc-common/build-method-shortcuts.d.ts.map +0 -1
- package/dist/src/rlc-common/build-method-shortcuts.js +0 -54
- package/dist/src/rlc-common/build-method-shortcuts.js.map +0 -1
- package/dist/src/rlc-common/build-object-types.d.ts +0 -29
- package/dist/src/rlc-common/build-object-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-object-types.js +0 -410
- package/dist/src/rlc-common/build-object-types.js.map +0 -1
- package/dist/src/rlc-common/build-paginate-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-paginate-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-paginate-helper.js +0 -27
- package/dist/src/rlc-common/build-paginate-helper.js.map +0 -1
- package/dist/src/rlc-common/build-parameter-types.d.ts +0 -14
- package/dist/src/rlc-common/build-parameter-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-parameter-types.js +0 -338
- package/dist/src/rlc-common/build-parameter-types.js.map +0 -1
- package/dist/src/rlc-common/build-polling-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-polling-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-polling-helper.js +0 -59
- package/dist/src/rlc-common/build-polling-helper.js.map +0 -1
- package/dist/src/rlc-common/build-response-types.d.ts +0 -6
- package/dist/src/rlc-common/build-response-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-response-types.js +0 -140
- package/dist/src/rlc-common/build-response-types.js.map +0 -1
- package/dist/src/rlc-common/build-samples.d.ts +0 -3
- package/dist/src/rlc-common/build-samples.d.ts.map +0 -1
- package/dist/src/rlc-common/build-samples.js +0 -30
- package/dist/src/rlc-common/build-samples.js.map +0 -1
- package/dist/src/rlc-common/build-schema-type.d.ts +0 -20
- package/dist/src/rlc-common/build-schema-type.d.ts.map +0 -1
- package/dist/src/rlc-common/build-schema-type.js +0 -64
- package/dist/src/rlc-common/build-schema-type.js.map +0 -1
- package/dist/src/rlc-common/build-serialize-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-serialize-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-serialize-helper.js +0 -36
- package/dist/src/rlc-common/build-serialize-helper.js.map +0 -1
- package/dist/src/rlc-common/build-top-level-index-file.d.ts +0 -6
- package/dist/src/rlc-common/build-top-level-index-file.d.ts.map +0 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +0 -44
- package/dist/src/rlc-common/build-top-level-index-file.js.map +0 -1
- package/dist/src/rlc-common/helpers/path-utils.d.ts +0 -2
- package/dist/src/rlc-common/helpers/path-utils.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/path-utils.js +0 -9
- package/dist/src/rlc-common/helpers/path-utils.js.map +0 -1
- package/dist/src/rlc-common/helpers/shortcut-methods.d.ts +0 -4
- package/dist/src/rlc-common/helpers/shortcut-methods.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/shortcut-methods.js +0 -49
- package/dist/src/rlc-common/helpers/shortcut-methods.js.map +0 -1
- package/dist/src/rlc-common/helpers/value-generation-util.d.ts +0 -12
- package/dist/src/rlc-common/helpers/value-generation-util.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/value-generation-util.js +0 -161
- package/dist/src/rlc-common/helpers/value-generation-util.js.map +0 -1
- package/dist/src/rlc-common/transform-sample-groups.d.ts +0 -9
- package/dist/src/rlc-common/transform-sample-groups.d.ts.map +0 -1
- package/dist/src/rlc-common/transform-sample-groups.js +0 -298
- package/dist/src/rlc-common/transform-sample-groups.js.map +0 -1
- package/src/rlc-common/build-client-definitions.ts +0 -226
- package/src/rlc-common/build-client.ts +0 -463
- package/src/rlc-common/build-index-file.ts +0 -220
- package/src/rlc-common/build-is-unexpected-helper.ts +0 -241
- package/src/rlc-common/build-logger.ts +0 -29
- package/src/rlc-common/build-method-shortcuts.ts +0 -71
- package/src/rlc-common/build-object-types.ts +0 -591
- package/src/rlc-common/build-paginate-helper.ts +0 -31
- package/src/rlc-common/build-parameter-types.ts +0 -460
- package/src/rlc-common/build-polling-helper.ts +0 -80
- package/src/rlc-common/build-response-types.ts +0 -170
- package/src/rlc-common/build-samples.ts +0 -32
- package/src/rlc-common/build-schema-type.ts +0 -79
- package/src/rlc-common/build-serialize-helper.ts +0 -49
- package/src/rlc-common/build-top-level-index-file.ts +0 -51
- package/src/rlc-common/helpers/path-utils.ts +0 -8
- package/src/rlc-common/helpers/shortcut-methods.ts +0 -58
- package/src/rlc-common/helpers/value-generation-util.ts +0 -234
- package/src/rlc-common/transform-sample-groups.ts +0 -383
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import { getClientName } from "./helpers/name-constructors.js";
|
|
2
|
-
import { NameType, camelCase, normalizeName } from "./helpers/name-utils.js";
|
|
3
|
-
import { buildSchemaObjectMap } from "./helpers/schema-helpers.js";
|
|
4
|
-
import { generateParameterTypeValue } from "./helpers/value-generation-util.js";
|
|
5
|
-
import {
|
|
6
|
-
OperationMethod,
|
|
7
|
-
OperationParameter,
|
|
8
|
-
PathMetadata,
|
|
9
|
-
Paths,
|
|
10
|
-
RLCModel,
|
|
11
|
-
RLCSampleDetail,
|
|
12
|
-
RLCSampleGroup,
|
|
13
|
-
SampleParameter,
|
|
14
|
-
SampleParameters,
|
|
15
|
-
Schema,
|
|
16
|
-
} from "./interfaces.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Transform the sample data based RLC detail e.g path, operations & schemas
|
|
20
|
-
* @param model RLC detail
|
|
21
|
-
* @param allowMockValue allow to mock value if not exist, currently we always generate mock value
|
|
22
|
-
* @returns Generated sample data or undefined if not support to generate
|
|
23
|
-
*/
|
|
24
|
-
export function transformSampleGroups(model: RLCModel, allowMockValue = true) {
|
|
25
|
-
if (model.options?.multiClient || model.options?.isModularLibrary) {
|
|
26
|
-
// Not support to generate if multiple clients
|
|
27
|
-
// Not support to generate if modular libraries
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if ((model.sampleGroups && model.sampleGroups.length > 0) || !allowMockValue) {
|
|
31
|
-
// Skip to transform if already has sample data
|
|
32
|
-
// Skip to transform if not allow to mock value
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const rlcSampleGroups: RLCSampleGroup[] = [];
|
|
36
|
-
// Get all paths
|
|
37
|
-
const paths: Paths = model.paths;
|
|
38
|
-
const clientName = getClientName(model);
|
|
39
|
-
const clientInterfaceName = clientName.endsWith("Client")
|
|
40
|
-
? `${clientName}`
|
|
41
|
-
: `${clientName}Client`;
|
|
42
|
-
const defaultFactoryName = normalizeName(
|
|
43
|
-
camelCase(`create ${clientInterfaceName}`),
|
|
44
|
-
NameType.Method,
|
|
45
|
-
);
|
|
46
|
-
const packageName = model.options?.packageDetails?.name ?? "";
|
|
47
|
-
const methodParameterMap = buildMethodParamMap(model);
|
|
48
|
-
const schemaObjectMap = buildSchemaObjectMap(model);
|
|
49
|
-
for (const path in paths) {
|
|
50
|
-
const pathDetails = paths[path];
|
|
51
|
-
if (!pathDetails) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const methods = pathDetails.methods;
|
|
55
|
-
for (const method in methods) {
|
|
56
|
-
const importedDict: Record<string, Set<string>> = {};
|
|
57
|
-
const methodArray = methods[method];
|
|
58
|
-
if (!methodArray || methodArray.length === 0) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const detail = methodArray[0];
|
|
62
|
-
if (!detail) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const operatonConcante = getOperationConcate(
|
|
66
|
-
detail.operationName,
|
|
67
|
-
pathDetails.operationGroupName,
|
|
68
|
-
);
|
|
69
|
-
const operationPrefix = normalizeName(
|
|
70
|
-
camelCase(transformSpecialLetterToSpace(operatonConcante)),
|
|
71
|
-
NameType.Operation,
|
|
72
|
-
);
|
|
73
|
-
const sampleGroup: RLCSampleGroup = {
|
|
74
|
-
filename: `${operationPrefix}Sample`,
|
|
75
|
-
defaultFactoryName,
|
|
76
|
-
clientPackageName: packageName,
|
|
77
|
-
samples: [],
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// initialize the sample
|
|
81
|
-
const sample: RLCSampleDetail = {
|
|
82
|
-
description: `call operation ${detail.operationName}`,
|
|
83
|
-
name: `${operationPrefix}Sample`,
|
|
84
|
-
path,
|
|
85
|
-
defaultFactoryName,
|
|
86
|
-
clientParamAssignments: [],
|
|
87
|
-
pathParamAssignments: [],
|
|
88
|
-
methodParamAssignments: [],
|
|
89
|
-
clientParamNames: "",
|
|
90
|
-
pathParamNames: "",
|
|
91
|
-
methodParamNames: "",
|
|
92
|
-
method,
|
|
93
|
-
isLRO: detail.operationHelperDetail?.lroDetails?.isLongRunning ?? false,
|
|
94
|
-
isPaging: detail.operationHelperDetail?.isPaging ?? false,
|
|
95
|
-
useLegacyLro: false,
|
|
96
|
-
};
|
|
97
|
-
// client-level, path-level and method-level parameter preparation
|
|
98
|
-
const parameters: SampleParameters = {
|
|
99
|
-
client: convertClientLevelParameters(model, importedDict, schemaObjectMap),
|
|
100
|
-
path: convertPathLevelParameters(pathDetails, path, schemaObjectMap),
|
|
101
|
-
method: convertMethodLevelParameters(
|
|
102
|
-
methodArray,
|
|
103
|
-
schemaObjectMap,
|
|
104
|
-
methodParameterMap.get(operatonConcante),
|
|
105
|
-
),
|
|
106
|
-
};
|
|
107
|
-
// enrich parameter details
|
|
108
|
-
enrichParameterInSample(sample, parameters);
|
|
109
|
-
// enrich LRO and pagination info
|
|
110
|
-
enrichLROAndPagingInSample(detail, importedDict, packageName);
|
|
111
|
-
sampleGroup.samples.push(sample);
|
|
112
|
-
rlcSampleGroups.push(sampleGroup);
|
|
113
|
-
enrichImportedString(sampleGroup, importedDict, defaultFactoryName, packageName);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return rlcSampleGroups;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function enrichLROAndPagingInSample(
|
|
120
|
-
operation: OperationMethod,
|
|
121
|
-
importedDict: Record<string, Set<string>>,
|
|
122
|
-
packageName: string,
|
|
123
|
-
) {
|
|
124
|
-
const isLRO = operation.operationHelperDetail?.lroDetails?.isLongRunning ?? false,
|
|
125
|
-
isPaging = operation.operationHelperDetail?.isPaging ?? false;
|
|
126
|
-
if (isPaging) {
|
|
127
|
-
if (isLRO) {
|
|
128
|
-
// TODO: report warning this is not supported
|
|
129
|
-
}
|
|
130
|
-
addValueInImportedDict(packageName, "paginate", importedDict);
|
|
131
|
-
} else if (isLRO) {
|
|
132
|
-
addValueInImportedDict(packageName, "getLongRunningPoller", importedDict);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function transformSpecialLetterToSpace(str: string) {
|
|
137
|
-
if (!str) {
|
|
138
|
-
return str;
|
|
139
|
-
}
|
|
140
|
-
return str
|
|
141
|
-
.replace(/_/g, " ")
|
|
142
|
-
.replace(/\//g, " Or ")
|
|
143
|
-
.replace(/,|\.|\(|\)/g, " ")
|
|
144
|
-
.replace("'s ", " ");
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function enrichImportedString(
|
|
148
|
-
sampleGroup: RLCSampleGroup,
|
|
149
|
-
importedDict: Record<string, Set<string>>,
|
|
150
|
-
defaultFactoryName: string,
|
|
151
|
-
packageName: string,
|
|
152
|
-
) {
|
|
153
|
-
const importedTypes: string[] = [];
|
|
154
|
-
if (!importedDict[packageName] || importedDict[packageName].size === 0) {
|
|
155
|
-
importedTypes.push(`import ${defaultFactoryName} from "${packageName}";`);
|
|
156
|
-
}
|
|
157
|
-
for (const key in importedDict) {
|
|
158
|
-
const importedSet = importedDict[key];
|
|
159
|
-
if (!importedSet) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
const values = Array.from(importedSet).join(", ");
|
|
163
|
-
const hasDefaultFactory = key === packageName ? `${defaultFactoryName},` : "";
|
|
164
|
-
importedTypes.push(`import ${hasDefaultFactory} { ${values} } from "${key}";`);
|
|
165
|
-
}
|
|
166
|
-
sampleGroup.importedTypes = importedTypes;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function enrichParameterInSample(sample: RLCSampleDetail, parameters: SampleParameters) {
|
|
170
|
-
sample.clientParamAssignments = getAssignmentStrArray(parameters.client);
|
|
171
|
-
sample.clientParamNames = getContactParameterNames(parameters.client);
|
|
172
|
-
sample.pathParamAssignments = getAssignmentStrArray(parameters.path);
|
|
173
|
-
sample.pathParamNames = getContactParameterNames(parameters.path);
|
|
174
|
-
// Directly apply the inline option value as method parameter
|
|
175
|
-
sample.methodParamNames = parameters.method.length > 0 ? (parameters.method[0]?.value ?? "") : "";
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function getAssignmentStrArray(parameters: SampleParameter[]) {
|
|
179
|
-
return parameters.filter((p) => !!p.assignment).map((p) => p.assignment!);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function getContactParameterNames(parameters: SampleParameter[]) {
|
|
183
|
-
return parameters
|
|
184
|
-
.filter((p) => p.name != null)
|
|
185
|
-
.map((p) => p.name!)
|
|
186
|
-
.join(",");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function convertClientLevelParameters(
|
|
190
|
-
model: RLCModel,
|
|
191
|
-
importedDict: Record<string, Set<string>>,
|
|
192
|
-
schemaMap: Map<string, Schema>,
|
|
193
|
-
): SampleParameter[] {
|
|
194
|
-
if (!model.options) {
|
|
195
|
-
return [];
|
|
196
|
-
}
|
|
197
|
-
const clientParams: SampleParameter[] = [];
|
|
198
|
-
const urlParameters = model?.urlInfo?.urlParameters?.filter(
|
|
199
|
-
// Do not include parameters with constant values in the signature, these should go in the options bag
|
|
200
|
-
(p) => p.value === undefined,
|
|
201
|
-
);
|
|
202
|
-
const { addCredentials, credentialScopes, credentialKeyHeaderName, customHttpAuthHeaderName } =
|
|
203
|
-
model.options;
|
|
204
|
-
const hasUrlParameter = !!urlParameters,
|
|
205
|
-
hasCredentials =
|
|
206
|
-
addCredentials && (credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName);
|
|
207
|
-
|
|
208
|
-
if (hasUrlParameter) {
|
|
209
|
-
// convert the host parameters in url
|
|
210
|
-
const clientParamAssignments = urlParameters.map((urlParameter) => {
|
|
211
|
-
const urlValue = generateParameterTypeValue(urlParameter.type, urlParameter.name, schemaMap);
|
|
212
|
-
const normalizedName = normalizeName(urlParameter.name, NameType.Parameter);
|
|
213
|
-
return {
|
|
214
|
-
name: normalizedName,
|
|
215
|
-
assignment: `const ${normalizedName} = ` + urlValue + `;`,
|
|
216
|
-
};
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
clientParams.push(...clientParamAssignments);
|
|
220
|
-
}
|
|
221
|
-
if (hasCredentials) {
|
|
222
|
-
// Currently only support token credential
|
|
223
|
-
const apiKeyCredentialPackage = "@azure/core-auth";
|
|
224
|
-
const tokenCredentialPackage = "@azure/identity";
|
|
225
|
-
if (credentialKeyHeaderName) {
|
|
226
|
-
clientParams.push({
|
|
227
|
-
name: "credential",
|
|
228
|
-
assignment: `const credential = new AzureKeyCredential("{Your API key}");`,
|
|
229
|
-
});
|
|
230
|
-
addValueInImportedDict(apiKeyCredentialPackage, "AzureKeyCredential", importedDict);
|
|
231
|
-
} else if (customHttpAuthHeaderName) {
|
|
232
|
-
clientParams.push({
|
|
233
|
-
name: "credential",
|
|
234
|
-
assignment: `const credential = { key: "{Your API key}"};`,
|
|
235
|
-
});
|
|
236
|
-
} else {
|
|
237
|
-
clientParams.push({
|
|
238
|
-
name: "credential",
|
|
239
|
-
assignment: "const credential = new DefaultAzureCredential();",
|
|
240
|
-
});
|
|
241
|
-
addValueInImportedDict(tokenCredentialPackage, "DefaultAzureCredential", importedDict);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return clientParams;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function convertPathLevelParameters(
|
|
248
|
-
pathDetail: PathMetadata,
|
|
249
|
-
path: string,
|
|
250
|
-
schemaMap: Map<string, Schema>,
|
|
251
|
-
): SampleParameter[] {
|
|
252
|
-
const pathItself = {
|
|
253
|
-
name: `"${path}"`,
|
|
254
|
-
};
|
|
255
|
-
const pathParams = (pathDetail || []).pathParameters.map((p) => {
|
|
256
|
-
const pathParam: SampleParameter = {
|
|
257
|
-
name: normalizeName(p.name, NameType.Parameter),
|
|
258
|
-
};
|
|
259
|
-
const value = generateParameterTypeValue(p.type, p.name, schemaMap);
|
|
260
|
-
pathParam.assignment = `const ${pathParam.name} =` + value + `;`;
|
|
261
|
-
return pathParam;
|
|
262
|
-
});
|
|
263
|
-
return [pathItself].concat(pathParams);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function convertMethodLevelParameters(
|
|
267
|
-
methods: OperationMethod[],
|
|
268
|
-
schemaMap: Map<string, Schema>,
|
|
269
|
-
operationParameter?: OperationParameter,
|
|
270
|
-
): SampleParameter[] {
|
|
271
|
-
if (
|
|
272
|
-
!methods ||
|
|
273
|
-
methods.length === 0 ||
|
|
274
|
-
!operationParameter ||
|
|
275
|
-
operationParameter.parameters.length === 0
|
|
276
|
-
) {
|
|
277
|
-
return [];
|
|
278
|
-
}
|
|
279
|
-
const rawMethodParams = operationParameter.parameters;
|
|
280
|
-
const method = methods[0];
|
|
281
|
-
const requestParameter = rawMethodParams[0];
|
|
282
|
-
if (!method || !requestParameter) {
|
|
283
|
-
return [];
|
|
284
|
-
}
|
|
285
|
-
const hasInputParams = !!rawMethodParams && rawMethodParams.length > 0,
|
|
286
|
-
requireParam = !method.hasOptionalOptions;
|
|
287
|
-
if (!hasInputParams && !requireParam) {
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const allSideAssignments = [],
|
|
292
|
-
querySideAssignments: string[] = [],
|
|
293
|
-
headerSideAssignments: string[] = [];
|
|
294
|
-
if (
|
|
295
|
-
!!requestParameter.body &&
|
|
296
|
-
requestParameter.body &&
|
|
297
|
-
requestParameter.body.body &&
|
|
298
|
-
requestParameter.body.body?.length > 0
|
|
299
|
-
) {
|
|
300
|
-
const body = requestParameter.body.body[0];
|
|
301
|
-
if (body) {
|
|
302
|
-
const bodyTypeName = body.typeName ?? body.type;
|
|
303
|
-
if (bodyTypeName !== "string" && body.oriSchema) {
|
|
304
|
-
schemaMap.set(bodyTypeName, body.oriSchema);
|
|
305
|
-
}
|
|
306
|
-
allSideAssignments.push(
|
|
307
|
-
` body: ` + generateParameterTypeValue(bodyTypeName, "body", schemaMap),
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
requestParameter.parameters
|
|
313
|
-
?.filter((p) => p.type === "query")
|
|
314
|
-
.forEach((p) => {
|
|
315
|
-
const name = `${p.name}`;
|
|
316
|
-
querySideAssignments.push(
|
|
317
|
-
`${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap),
|
|
318
|
-
);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
if (querySideAssignments.length > 0) {
|
|
322
|
-
allSideAssignments.push(` queryParameters: { ` + querySideAssignments.join(", ") + `}`);
|
|
323
|
-
}
|
|
324
|
-
requestParameter.parameters
|
|
325
|
-
?.filter((p) => p.type === "header")
|
|
326
|
-
.filter((p) => p.name.toLowerCase() !== "contenttype")
|
|
327
|
-
.forEach((p) => {
|
|
328
|
-
const name = `${p.name}`;
|
|
329
|
-
headerSideAssignments.push(
|
|
330
|
-
`${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap),
|
|
331
|
-
);
|
|
332
|
-
});
|
|
333
|
-
if (headerSideAssignments.length > 0) {
|
|
334
|
-
allSideAssignments.push(` headers: { ` + headerSideAssignments.join(", ") + `}`);
|
|
335
|
-
}
|
|
336
|
-
const contentType = requestParameter.parameters
|
|
337
|
-
?.filter((p) => p.type === "header")
|
|
338
|
-
.filter((p) => p.name.toLowerCase() === "contenttype");
|
|
339
|
-
const firstContentType = contentType?.[0];
|
|
340
|
-
if (firstContentType) {
|
|
341
|
-
allSideAssignments.push(
|
|
342
|
-
` ${firstContentType.name}: ` +
|
|
343
|
-
generateParameterTypeValue(firstContentType.param.type, firstContentType.name, schemaMap),
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
let value: string;
|
|
347
|
-
if (allSideAssignments.length > 0) {
|
|
348
|
-
value = `{ ` + allSideAssignments.join(", ") + `}`;
|
|
349
|
-
} else {
|
|
350
|
-
return [];
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const optionParam: SampleParameter = {
|
|
354
|
-
name: "options",
|
|
355
|
-
assignment: `const options =` + value + `;`,
|
|
356
|
-
value,
|
|
357
|
-
};
|
|
358
|
-
return [optionParam];
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function addValueInImportedDict(
|
|
362
|
-
key: string,
|
|
363
|
-
val: string,
|
|
364
|
-
importedDict: Record<string, Set<string>>,
|
|
365
|
-
) {
|
|
366
|
-
if (!importedDict[key]) {
|
|
367
|
-
importedDict[key] = new Set<string>();
|
|
368
|
-
}
|
|
369
|
-
importedDict[key].add(val);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function buildMethodParamMap(model: RLCModel): Map<string, OperationParameter> {
|
|
373
|
-
const map = new Map<string, OperationParameter>();
|
|
374
|
-
(model.parameters ?? []).forEach((p) => {
|
|
375
|
-
const operatonConcante = getOperationConcate(p.operationName, p.operationGroup);
|
|
376
|
-
map.set(operatonConcante, p);
|
|
377
|
-
});
|
|
378
|
-
return map;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function getOperationConcate(opName: string, opGroup: string) {
|
|
382
|
-
return `${opGroup}_${opName}`;
|
|
383
|
-
}
|