@azure-tools/typespec-ts 0.14.0 → 0.15.0
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 +7 -6
- 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 +6 -6
- 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 +19 -25
- 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 +2 -1
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +36 -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 +10 -3
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +162 -35
- 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/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 +1 -6
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +2 -2
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +4 -1
- 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 +27 -13
- 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 +14 -9
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +4 -4
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +1 -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 +10 -7
- package/src/modular/buildClientContext.ts +18 -8
- package/src/modular/buildCodeModel.ts +7 -9
- package/src/modular/buildOperations.ts +25 -32
- 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 +47 -5
- package/src/modular/helpers/clientHelpers.ts +5 -3
- package/src/modular/helpers/docsHelpers.ts +10 -0
- package/src/modular/helpers/operationHelpers.ts +277 -36
- package/src/modular/helpers/typeHelpers.ts +6 -0
- package/src/transform/transform.ts +24 -31
- package/src/transform/transformApiVersionInfo.ts +1 -1
- package/src/transform/transformHelperFunctionDetails.ts +2 -7
- package/src/transform/transformParameters.ts +15 -12
- 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 +34 -15
- package/src/utils/clientUtils.ts +2 -4
- package/src/utils/interfaces.ts +14 -0
- package/src/utils/modelUtils.ts +17 -8
- package/src/utils/operationUtil.ts +5 -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
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
SdkClient,
|
|
6
|
-
SdkContext
|
|
7
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
4
|
+
import { SdkClient } from "@azure-tools/typespec-client-generator-core";
|
|
8
5
|
import {
|
|
9
6
|
ImportKind,
|
|
10
7
|
NameType,
|
|
@@ -19,7 +16,7 @@ import {
|
|
|
19
16
|
SchemaContext,
|
|
20
17
|
UrlInfo
|
|
21
18
|
} from "@azure-tools/rlc-common";
|
|
22
|
-
import {
|
|
19
|
+
import { getDoc } from "@typespec/compiler";
|
|
23
20
|
import { getServers } from "@typespec/http";
|
|
24
21
|
import { join } from "path";
|
|
25
22
|
import {
|
|
@@ -34,32 +31,19 @@ import { transformToParameterTypes } from "./transformParameters.js";
|
|
|
34
31
|
import { transformPaths } from "./transformPaths.js";
|
|
35
32
|
import { transformToResponseTypes } from "./transformResponses.js";
|
|
36
33
|
import { transformSchemas } from "./transformSchemas.js";
|
|
37
|
-
import { transformRLCOptions } from "./transfromRLCOptions.js";
|
|
38
34
|
import { transformApiVersionInfo } from "./transformApiVersionInfo.js";
|
|
39
35
|
import { getClientLroOverload } from "../utils/operationUtil.js";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
options?: RLCOptions;
|
|
43
|
-
}
|
|
36
|
+
import { transformTelemetryInfo } from "./transformTelemetryInfo.js";
|
|
37
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
44
38
|
|
|
45
39
|
export async function transformRLCModel(
|
|
46
|
-
program: Program,
|
|
47
|
-
emitterOptions: RLCOptions,
|
|
48
40
|
client: SdkClient,
|
|
49
|
-
|
|
50
|
-
dpgContext: RLCSdkContext
|
|
41
|
+
dpgContext: SdkContext
|
|
51
42
|
): Promise<RLCModel> {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
emitterOutputDir,
|
|
55
|
-
dpgContext
|
|
56
|
-
);
|
|
57
|
-
dpgContext.options = options;
|
|
43
|
+
const program = dpgContext.program;
|
|
44
|
+
const options: RLCOptions = dpgContext.rlcOptions!;
|
|
58
45
|
const srcPath = join(
|
|
59
|
-
|
|
60
|
-
"src",
|
|
61
|
-
// When generating modular library, RLC has to go under rest folder
|
|
62
|
-
options.isModularLibrary ? "rest" : "",
|
|
46
|
+
dpgContext.generationPathDetail?.rlcSourcesDir ?? "",
|
|
63
47
|
options.batch && options.batch.length > 1
|
|
64
48
|
? normalizeName(client.name.replace("Client", ""), NameType.File)
|
|
65
49
|
: ""
|
|
@@ -90,8 +74,9 @@ export async function transformRLCModel(
|
|
|
90
74
|
const helperDetails = transformHelperFunctionDetails(client, dpgContext);
|
|
91
75
|
// Enrich client-level annotation detail
|
|
92
76
|
helperDetails.clientLroOverload = getClientLroOverload(paths);
|
|
93
|
-
const urlInfo = transformUrlInfo(
|
|
77
|
+
const urlInfo = transformUrlInfo(dpgContext);
|
|
94
78
|
const apiVersionInfo = transformApiVersionInfo(client, dpgContext, urlInfo);
|
|
79
|
+
const telemetryOptions = transformTelemetryInfo(dpgContext, client);
|
|
95
80
|
return {
|
|
96
81
|
srcPath,
|
|
97
82
|
libraryName,
|
|
@@ -103,14 +88,13 @@ export async function transformRLCModel(
|
|
|
103
88
|
apiVersionInfo,
|
|
104
89
|
parameters,
|
|
105
90
|
helperDetails,
|
|
106
|
-
urlInfo
|
|
91
|
+
urlInfo,
|
|
92
|
+
telemetryOptions
|
|
107
93
|
};
|
|
108
94
|
}
|
|
109
95
|
|
|
110
|
-
export function transformUrlInfo(
|
|
111
|
-
program
|
|
112
|
-
dpgContext: SdkContext
|
|
113
|
-
): UrlInfo | undefined {
|
|
96
|
+
export function transformUrlInfo(dpgContext: SdkContext): UrlInfo | undefined {
|
|
97
|
+
const program = dpgContext.program;
|
|
114
98
|
const serviceNs = getDefaultService(program)?.type;
|
|
115
99
|
let endpoint = undefined;
|
|
116
100
|
const urlParameters: PathParameter[] = [];
|
|
@@ -137,7 +121,8 @@ export function transformUrlInfo(
|
|
|
137
121
|
property!
|
|
138
122
|
);
|
|
139
123
|
urlParameters.push({
|
|
140
|
-
|
|
124
|
+
oriName: key,
|
|
125
|
+
name: normalizeName(key, NameType.Parameter, true),
|
|
141
126
|
type: getTypeName(schema),
|
|
142
127
|
description:
|
|
143
128
|
(getDoc(program, property) &&
|
|
@@ -148,6 +133,14 @@ export function transformUrlInfo(
|
|
|
148
133
|
}
|
|
149
134
|
}
|
|
150
135
|
}
|
|
136
|
+
if (endpoint && urlParameters.length > 0) {
|
|
137
|
+
for (const param of urlParameters) {
|
|
138
|
+
if (param.oriName) {
|
|
139
|
+
const regexp = new RegExp(`{${param.oriName}}`, "g");
|
|
140
|
+
endpoint = endpoint.replace(regexp, `{${param.name}}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
151
144
|
// Set the default value if missing endpoint parameter
|
|
152
145
|
if (endpoint == undefined && urlParameters.length === 0) {
|
|
153
146
|
endpoint = "{endpoint}";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SdkClient,
|
|
3
|
-
SdkContext,
|
|
4
3
|
isApiVersion,
|
|
5
4
|
listOperationGroups,
|
|
6
5
|
listOperationsInOperationGroup
|
|
@@ -19,6 +18,7 @@ import {
|
|
|
19
18
|
getSchemaForType,
|
|
20
19
|
trimUsage
|
|
21
20
|
} from "../utils/modelUtils.js";
|
|
21
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
22
22
|
|
|
23
23
|
export function transformApiVersionInfo(
|
|
24
24
|
client: SdkClient,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PagedResultMetadata } from "@azure-tools/typespec-azure-core";
|
|
2
2
|
import {
|
|
3
3
|
SdkClient,
|
|
4
|
-
SdkContext,
|
|
5
4
|
listOperationGroups,
|
|
6
5
|
listOperationsInOperationGroup
|
|
7
6
|
} from "@azure-tools/typespec-client-generator-core";
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
hasPollingOperations
|
|
15
14
|
} from "../utils/operationUtil.js";
|
|
16
15
|
import { getSpecialSerializeInfo } from "./transformParameters.js";
|
|
16
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
17
17
|
|
|
18
18
|
export function transformHelperFunctionDetails(
|
|
19
19
|
client: SdkClient,
|
|
@@ -168,12 +168,7 @@ function extractPageDetailFromCore(
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
function parseNextLinkName(paged: PagedResultMetadata): string | undefined {
|
|
171
|
-
|
|
172
|
-
if (pathComponents) {
|
|
173
|
-
// TODO: This logic breaks down if there actually is a dotted path.
|
|
174
|
-
return pathComponents[pathComponents.length - 1];
|
|
175
|
-
}
|
|
176
|
-
return undefined;
|
|
171
|
+
return paged.nextLinkProperty?.name;
|
|
177
172
|
}
|
|
178
173
|
|
|
179
174
|
function parseItemName(paged: PagedResultMetadata): string | undefined {
|
|
@@ -39,12 +39,12 @@ import {
|
|
|
39
39
|
listOperationsInOperationGroup,
|
|
40
40
|
isApiVersion
|
|
41
41
|
} from "@azure-tools/typespec-client-generator-core";
|
|
42
|
-
import {
|
|
42
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
43
43
|
|
|
44
44
|
export function transformToParameterTypes(
|
|
45
45
|
importDetails: Map<ImportKind, Set<string>>,
|
|
46
46
|
client: SdkClient,
|
|
47
|
-
dpgContext:
|
|
47
|
+
dpgContext: SdkContext
|
|
48
48
|
): OperationParameter[] {
|
|
49
49
|
const program = dpgContext.program;
|
|
50
50
|
const operationGroups = listOperationGroups(dpgContext, client);
|
|
@@ -114,7 +114,7 @@ export function transformToParameterTypes(
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function getParameterMetadata(
|
|
117
|
-
dpgContext:
|
|
117
|
+
dpgContext: SdkContext,
|
|
118
118
|
paramType: "query" | "path" | "header",
|
|
119
119
|
parameter: HttpOperationParameter
|
|
120
120
|
): ParameterMetadata {
|
|
@@ -180,7 +180,7 @@ function getParameterName(name: string) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
function transformQueryParameters(
|
|
183
|
-
dpgContext:
|
|
183
|
+
dpgContext: SdkContext,
|
|
184
184
|
parameters: HttpOperationParameters
|
|
185
185
|
): ParameterMetadata[] {
|
|
186
186
|
const queryParameters = parameters.parameters.filter(
|
|
@@ -207,7 +207,7 @@ function transformPathParameters() {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
function transformHeaderParameters(
|
|
210
|
-
dpgContext:
|
|
210
|
+
dpgContext: SdkContext,
|
|
211
211
|
parameters: HttpOperationParameters
|
|
212
212
|
): ParameterMetadata[] {
|
|
213
213
|
const headerParameters = parameters.parameters.filter(
|
|
@@ -222,7 +222,7 @@ function transformHeaderParameters(
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
function transformBodyParameters(
|
|
225
|
-
dpgContext:
|
|
225
|
+
dpgContext: SdkContext,
|
|
226
226
|
parameters: HttpOperationParameters,
|
|
227
227
|
headers: ParameterMetadata[],
|
|
228
228
|
importedModels: Set<string>,
|
|
@@ -264,7 +264,7 @@ function transformBodyParameters(
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
function transformNormalBody(
|
|
267
|
-
dpgContext:
|
|
267
|
+
dpgContext: SdkContext,
|
|
268
268
|
bodyType: Type,
|
|
269
269
|
parameters: HttpOperationParameters,
|
|
270
270
|
importedModels: Set<string>,
|
|
@@ -307,7 +307,7 @@ function transformNormalBody(
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
function transformMultiFormBody(
|
|
310
|
-
dpgContext:
|
|
310
|
+
dpgContext: SdkContext,
|
|
311
311
|
bodyType: Type,
|
|
312
312
|
parameters: HttpOperationParameters,
|
|
313
313
|
importedModels: Set<string>
|
|
@@ -374,7 +374,7 @@ function transformMultiFormBody(
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
function getBodyDetail(
|
|
377
|
-
dpgContext:
|
|
377
|
+
dpgContext: SdkContext,
|
|
378
378
|
bodyType: Type,
|
|
379
379
|
headers: ParameterMetadata[]
|
|
380
380
|
) {
|
|
@@ -389,7 +389,7 @@ function getBodyDetail(
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
function extractNameFromCadlType(
|
|
392
|
-
dpgContext:
|
|
392
|
+
dpgContext: SdkContext,
|
|
393
393
|
cadlType: Type,
|
|
394
394
|
importedModels: Set<string>,
|
|
395
395
|
headers?: ParameterMetadata[]
|
|
@@ -402,7 +402,10 @@ function extractNameFromCadlType(
|
|
|
402
402
|
if (importedNames) {
|
|
403
403
|
importedNames.forEach(importedModels.add, importedModels);
|
|
404
404
|
}
|
|
405
|
-
let typeName = getTypeName(bodySchema
|
|
405
|
+
let typeName = getTypeName(bodySchema, [
|
|
406
|
+
SchemaContext.Input,
|
|
407
|
+
SchemaContext.Exception
|
|
408
|
+
]);
|
|
406
409
|
if (isAnonymousModel(bodySchema)) {
|
|
407
410
|
// Handle anonymous Model
|
|
408
411
|
return generateAnomymousModelSigniture(bodySchema, importedModels);
|
|
@@ -451,7 +454,7 @@ function generateAnomymousModelSigniture(
|
|
|
451
454
|
}
|
|
452
455
|
|
|
453
456
|
function extractDescriptionsFromBody(
|
|
454
|
-
dpgContext:
|
|
457
|
+
dpgContext: SdkContext,
|
|
455
458
|
bodyType: Type,
|
|
456
459
|
parameters: HttpOperationParameters
|
|
457
460
|
) {
|
|
@@ -32,12 +32,12 @@ import {
|
|
|
32
32
|
isDefinedStatusCode,
|
|
33
33
|
isPagingOperation
|
|
34
34
|
} from "../utils/operationUtil.js";
|
|
35
|
-
import {
|
|
35
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
36
36
|
|
|
37
37
|
export function transformPaths(
|
|
38
38
|
program: Program,
|
|
39
39
|
client: SdkClient,
|
|
40
|
-
dpgContext:
|
|
40
|
+
dpgContext: SdkContext
|
|
41
41
|
): Paths {
|
|
42
42
|
const operationGroups = listOperationGroups(dpgContext, client);
|
|
43
43
|
const paths: Paths = {};
|
|
@@ -72,7 +72,7 @@ export function transformPaths(
|
|
|
72
72
|
* an operation can end up returning.
|
|
73
73
|
*/
|
|
74
74
|
function getResponseTypes(
|
|
75
|
-
dpgContext:
|
|
75
|
+
dpgContext: SdkContext,
|
|
76
76
|
operation: HttpOperation
|
|
77
77
|
): ResponseTypes {
|
|
78
78
|
const returnTypes: ResponseTypes = {
|
|
@@ -104,7 +104,7 @@ function getResponseTypes(
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
function transformOperation(
|
|
107
|
-
dpgContext:
|
|
107
|
+
dpgContext: SdkContext,
|
|
108
108
|
route: HttpOperation,
|
|
109
109
|
paths: Paths
|
|
110
110
|
) {
|
|
@@ -180,7 +180,7 @@ function escapeCoreName(name: string) {
|
|
|
180
180
|
return name;
|
|
181
181
|
}
|
|
182
182
|
function hasRequiredOptions(
|
|
183
|
-
dpgContext:
|
|
183
|
+
dpgContext: SdkContext,
|
|
184
184
|
routeParameters: HttpOperationParameters
|
|
185
185
|
) {
|
|
186
186
|
const isRequiredBodyParam = routeParameters.bodyParameter?.optional === false;
|
|
@@ -34,12 +34,12 @@ import {
|
|
|
34
34
|
getOperationLroOverload,
|
|
35
35
|
getOperationName
|
|
36
36
|
} from "../utils/operationUtil.js";
|
|
37
|
-
import {
|
|
37
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
38
38
|
|
|
39
39
|
export function transformToResponseTypes(
|
|
40
40
|
importDetails: Map<ImportKind, Set<string>>,
|
|
41
41
|
client: SdkClient,
|
|
42
|
-
dpgContext:
|
|
42
|
+
dpgContext: SdkContext
|
|
43
43
|
): OperationResponse[] {
|
|
44
44
|
const program = dpgContext.program;
|
|
45
45
|
const operationGroups = listOperationGroups(dpgContext, client);
|
|
@@ -114,7 +114,7 @@ export function transformToResponseTypes(
|
|
|
114
114
|
* @returns rlc header shcema
|
|
115
115
|
*/
|
|
116
116
|
function transformHeaders(
|
|
117
|
-
dpgContext:
|
|
117
|
+
dpgContext: SdkContext,
|
|
118
118
|
response: HttpOperationResponse
|
|
119
119
|
): ResponseHeaderSchema[] | undefined {
|
|
120
120
|
if (!response.responses.length) {
|
|
@@ -154,7 +154,7 @@ function transformHeaders(
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
function transformBody(
|
|
157
|
-
dpgContext:
|
|
157
|
+
dpgContext: SdkContext,
|
|
158
158
|
response: HttpOperationResponse,
|
|
159
159
|
importedModels: Set<string>
|
|
160
160
|
) {
|
|
@@ -188,7 +188,11 @@ function transformBody(
|
|
|
188
188
|
const bodyType = getTypeName(bodySchema);
|
|
189
189
|
const importedNames = getImportedModelName(bodySchema);
|
|
190
190
|
if (importedNames) {
|
|
191
|
-
importedNames
|
|
191
|
+
importedNames
|
|
192
|
+
.filter((name) => {
|
|
193
|
+
return name !== "any";
|
|
194
|
+
})
|
|
195
|
+
.forEach(importedModels.add, importedModels);
|
|
192
196
|
}
|
|
193
197
|
typeSet.add(bodyType);
|
|
194
198
|
}
|
|
@@ -206,7 +210,7 @@ function transformBody(
|
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
function transformLroLogicalResponse(
|
|
209
|
-
dpgContext:
|
|
213
|
+
dpgContext: SdkContext,
|
|
210
214
|
route: HttpOperation,
|
|
211
215
|
operationGroupName: string,
|
|
212
216
|
existingResponses: ResponseMetadata[]
|
|
@@ -15,12 +15,12 @@ import {
|
|
|
15
15
|
getBodyType,
|
|
16
16
|
trimUsage
|
|
17
17
|
} from "../utils/modelUtils.js";
|
|
18
|
-
import {
|
|
18
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
19
19
|
|
|
20
20
|
export function transformSchemas(
|
|
21
21
|
program: Program,
|
|
22
22
|
client: SdkClient,
|
|
23
|
-
dpgContext:
|
|
23
|
+
dpgContext: SdkContext
|
|
24
24
|
) {
|
|
25
25
|
const schemas: Map<string, SchemaContext[]> = new Map<
|
|
26
26
|
string,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TelemetryInfo } from "@azure-tools/rlc-common";
|
|
2
|
+
import {
|
|
3
|
+
SdkClient,
|
|
4
|
+
SdkContext,
|
|
5
|
+
listOperationGroups,
|
|
6
|
+
listOperationsInOperationGroup
|
|
7
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
8
|
+
import { ignoreDiagnostics } from "@typespec/compiler";
|
|
9
|
+
import { getHttpOperation, HttpOperation } from "@typespec/http";
|
|
10
|
+
|
|
11
|
+
export function transformTelemetryInfo(
|
|
12
|
+
dpgContext: SdkContext,
|
|
13
|
+
client: SdkClient
|
|
14
|
+
): TelemetryInfo | undefined {
|
|
15
|
+
const customRequestIdHeaderName = getCustomRequestHeaderNameForClient(
|
|
16
|
+
dpgContext,
|
|
17
|
+
client
|
|
18
|
+
);
|
|
19
|
+
if (customRequestIdHeaderName) {
|
|
20
|
+
return {
|
|
21
|
+
customRequestIdHeaderName
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getCustomRequestHeaderNameForClient(
|
|
28
|
+
dpgContext: SdkContext,
|
|
29
|
+
client: SdkClient
|
|
30
|
+
) {
|
|
31
|
+
const program = dpgContext.program;
|
|
32
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
33
|
+
for (const operationGroup of operationGroups) {
|
|
34
|
+
const operations = listOperationsInOperationGroup(
|
|
35
|
+
dpgContext,
|
|
36
|
+
operationGroup
|
|
37
|
+
);
|
|
38
|
+
for (const op of operations) {
|
|
39
|
+
const headerName = getCustomRequestHeaderNameForOperation(
|
|
40
|
+
ignoreDiagnostics(getHttpOperation(program, op))
|
|
41
|
+
);
|
|
42
|
+
if (headerName != undefined) {
|
|
43
|
+
return headerName;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
48
|
+
for (const clientOp of clientOperations) {
|
|
49
|
+
const headerName = getCustomRequestHeaderNameForOperation(
|
|
50
|
+
ignoreDiagnostics(getHttpOperation(program, clientOp))
|
|
51
|
+
);
|
|
52
|
+
if (headerName != undefined) {
|
|
53
|
+
return headerName;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getCustomRequestHeaderNameForOperation(
|
|
60
|
+
route: HttpOperation
|
|
61
|
+
): string | undefined {
|
|
62
|
+
const CUSTOM_REQUEST_HEADER_NAME = "client-request-id";
|
|
63
|
+
const params = route.parameters.parameters.filter(
|
|
64
|
+
(p) =>
|
|
65
|
+
p.type === "header" && p.name.toLowerCase() === CUSTOM_REQUEST_HEADER_NAME
|
|
66
|
+
);
|
|
67
|
+
if (params.length > 0) {
|
|
68
|
+
return CUSTOM_REQUEST_HEADER_NAME;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
@@ -10,18 +10,17 @@ import { getAuthentication } from "@typespec/http";
|
|
|
10
10
|
import { reportDiagnostic } from "../lib.js";
|
|
11
11
|
import { getDefaultService } from "../utils/modelUtils.js";
|
|
12
12
|
import { getRLCClients } from "../utils/clientUtils.js";
|
|
13
|
-
import {
|
|
13
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
14
14
|
|
|
15
15
|
export function transformRLCOptions(
|
|
16
16
|
emitterOptions: RLCOptions,
|
|
17
|
-
|
|
18
|
-
dpgContext: RLCSdkContext
|
|
17
|
+
dpgContext: SdkContext
|
|
19
18
|
): RLCOptions {
|
|
20
19
|
// Extract the options from emitter option
|
|
21
20
|
const options = extractRLCOptions(
|
|
22
21
|
dpgContext.program,
|
|
23
22
|
emitterOptions,
|
|
24
|
-
|
|
23
|
+
dpgContext.generationPathDetail?.rootDir ?? ""
|
|
25
24
|
);
|
|
26
25
|
const batch = getRLCClients(dpgContext);
|
|
27
26
|
options.batch = batch;
|
|
@@ -31,16 +30,17 @@ export function transformRLCOptions(
|
|
|
31
30
|
function extractRLCOptions(
|
|
32
31
|
program: Program,
|
|
33
32
|
emitterOptions: RLCOptions,
|
|
34
|
-
|
|
33
|
+
generationRootDir: string
|
|
35
34
|
): RLCOptions {
|
|
36
35
|
const includeShortcuts = getIncludeShortcuts(emitterOptions);
|
|
37
36
|
const packageDetails = getPackageDetails(program, emitterOptions);
|
|
38
37
|
const serviceInfo = getServiceInfo(program);
|
|
39
38
|
const azureSdkForJs = getAzureSdkForJs(emitterOptions);
|
|
40
|
-
const generateMetadata =
|
|
41
|
-
|
|
39
|
+
const generateMetadata: undefined | boolean =
|
|
40
|
+
getGenerateMetadata(emitterOptions);
|
|
41
|
+
const generateTest: undefined | boolean = getGenerateTest(emitterOptions);
|
|
42
42
|
const credentialInfo = getCredentialInfo(program, emitterOptions);
|
|
43
|
-
const azureOutputDirectory = getAzureOutputDirectory(
|
|
43
|
+
const azureOutputDirectory = getAzureOutputDirectory(generationRootDir);
|
|
44
44
|
const enableOperationGroup = getEnableOperationGroup(emitterOptions);
|
|
45
45
|
return {
|
|
46
46
|
...emitterOptions,
|
|
@@ -71,6 +71,9 @@ function processAuth(program: Program) {
|
|
|
71
71
|
for (const auth of option.schemes) {
|
|
72
72
|
switch (auth.type) {
|
|
73
73
|
case "http":
|
|
74
|
+
securityInfo.addCredentials = true;
|
|
75
|
+
securityInfo.customHttpAuthHeaderName = "Authorization";
|
|
76
|
+
securityInfo.customHttpAuthSharedKeyPrefix = auth.scheme;
|
|
74
77
|
break;
|
|
75
78
|
case "apiKey":
|
|
76
79
|
if (auth.in === "cookie") {
|
|
@@ -160,17 +163,23 @@ function getAzureSdkForJs(emitterOptions: RLCOptions) {
|
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
function getGenerateMetadata(emitterOptions: RLCOptions) {
|
|
163
|
-
|
|
166
|
+
if (
|
|
167
|
+
emitterOptions.generateMetadata === undefined ||
|
|
164
168
|
emitterOptions.generateMetadata === null
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
return Boolean(emitterOptions.generateMetadata);
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
function getGenerateTest(emitterOptions: RLCOptions) {
|
|
170
|
-
|
|
176
|
+
if (
|
|
177
|
+
emitterOptions.generateTest === undefined ||
|
|
171
178
|
emitterOptions.generateTest === null
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
return Boolean(emitterOptions.generateTest);
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
export function getCredentialInfo(
|
|
@@ -192,10 +201,20 @@ export function getCredentialInfo(
|
|
|
192
201
|
securityInfo && securityInfo.credentialKeyHeaderName
|
|
193
202
|
? securityInfo.credentialKeyHeaderName
|
|
194
203
|
: emitterOptions.credentialKeyHeaderName;
|
|
204
|
+
const customHttpAuthHeaderName =
|
|
205
|
+
securityInfo && securityInfo.customHttpAuthHeaderName
|
|
206
|
+
? securityInfo.customHttpAuthHeaderName
|
|
207
|
+
: emitterOptions.customHttpAuthHeaderName;
|
|
208
|
+
const customHttpAuthSharedKeyPrefix =
|
|
209
|
+
securityInfo && securityInfo.customHttpAuthSharedKeyPrefix
|
|
210
|
+
? securityInfo.customHttpAuthSharedKeyPrefix
|
|
211
|
+
: emitterOptions.customHttpAuthSharedKeyPrefix;
|
|
195
212
|
return {
|
|
196
213
|
addCredentials,
|
|
197
214
|
credentialScopes,
|
|
198
|
-
credentialKeyHeaderName
|
|
215
|
+
credentialKeyHeaderName,
|
|
216
|
+
customHttpAuthHeaderName,
|
|
217
|
+
customHttpAuthSharedKeyPrefix
|
|
199
218
|
};
|
|
200
219
|
}
|
|
201
220
|
|
package/src/utils/clientUtils.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SdkClient,
|
|
3
|
-
SdkContext
|
|
4
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
1
|
+
import { SdkClient } from "@azure-tools/typespec-client-generator-core";
|
|
5
2
|
import { listServices } from "@typespec/compiler";
|
|
3
|
+
import { SdkContext } from "./interfaces.js";
|
|
6
4
|
|
|
7
5
|
export function getRLCClients(dpgContext: SdkContext): SdkClient[] {
|
|
8
6
|
const services = listServices(dpgContext.program);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RLCOptions } from "@azure-tools/rlc-common";
|
|
2
|
+
import { SdkContext as TCGCSdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
3
|
+
|
|
4
|
+
export interface SdkContext extends TCGCSdkContext {
|
|
5
|
+
rlcOptions?: RLCOptions;
|
|
6
|
+
generationPathDetail?: GenerationDirDetail;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface GenerationDirDetail {
|
|
10
|
+
rootDir: string;
|
|
11
|
+
rlcSourcesDir: string;
|
|
12
|
+
modularSourcesDir?: string;
|
|
13
|
+
metadataDir: string;
|
|
14
|
+
}
|
package/src/utils/modelUtils.ts
CHANGED
|
@@ -63,10 +63,10 @@ import {
|
|
|
63
63
|
import { getPagedResult, isFixed } from "@azure-tools/typespec-azure-core";
|
|
64
64
|
import { extractPagedMetadataNested } from "./operationUtil.js";
|
|
65
65
|
import {
|
|
66
|
-
SdkContext,
|
|
67
66
|
getDefaultApiVersion,
|
|
68
67
|
isApiVersion
|
|
69
68
|
} from "@azure-tools/typespec-client-generator-core";
|
|
69
|
+
import { SdkContext } from "./interfaces.js";
|
|
70
70
|
|
|
71
71
|
export function getBinaryType(usage: SchemaContext[]) {
|
|
72
72
|
return usage.includes(SchemaContext.Output)
|
|
@@ -146,7 +146,7 @@ export function getSchemaForType(
|
|
|
146
146
|
if (type.kind === "Model") {
|
|
147
147
|
const schema = getSchemaForModel(dpgContext, type, usage, needRef) as any;
|
|
148
148
|
if (usage && usage.includes(SchemaContext.Output)) {
|
|
149
|
-
if (!schema.name) {
|
|
149
|
+
if (!schema.name || schema.name === "") {
|
|
150
150
|
//TODO: HANDLE ANONYMOUS
|
|
151
151
|
schema.outputTypeName =
|
|
152
152
|
schema.type === "object" ? "Record<string, any>" : "any";
|
|
@@ -811,19 +811,28 @@ function mapCadlStdTypeToTypeScript(
|
|
|
811
811
|
!isUnknownType(indexer.value!) &&
|
|
812
812
|
!isUnionType(indexer.value!)
|
|
813
813
|
) {
|
|
814
|
-
schema.typeName = `Record<string, ${valueType.
|
|
814
|
+
schema.typeName = `Record<string, ${valueType.typeName}>`;
|
|
815
815
|
schema.valueTypeName = valueType.name;
|
|
816
816
|
if (usage && usage.includes(SchemaContext.Output)) {
|
|
817
|
-
schema.outputTypeName = `Record<string, ${valueType.
|
|
818
|
-
schema.outputValueTypeName = `${valueType.
|
|
817
|
+
schema.outputTypeName = `Record<string, ${valueType.outputTypeName}>`;
|
|
818
|
+
schema.outputValueTypeName = `${valueType.outputTypeName}`;
|
|
819
819
|
}
|
|
820
820
|
} else if (isUnknownType(indexer.value!)) {
|
|
821
|
-
schema.typeName = `Record<string, ${
|
|
821
|
+
schema.typeName = `Record<string, ${
|
|
822
|
+
valueType.typeName ?? valueType.type
|
|
823
|
+
}>`;
|
|
822
824
|
if (usage && usage.includes(SchemaContext.Output)) {
|
|
823
|
-
schema.outputTypeName = `Record<string, ${
|
|
825
|
+
schema.outputTypeName = `Record<string, ${
|
|
826
|
+
valueType.outputTypeName ?? valueType.type
|
|
827
|
+
}>`;
|
|
824
828
|
}
|
|
825
829
|
} else {
|
|
826
|
-
schema.typeName = `Record<string, ${getTypeName(valueType,
|
|
830
|
+
schema.typeName = `Record<string, ${getTypeName(valueType, [
|
|
831
|
+
SchemaContext.Input
|
|
832
|
+
])}>`;
|
|
833
|
+
schema.outputTypeName = `Record<string, ${getTypeName(valueType, [
|
|
834
|
+
SchemaContext.Output
|
|
835
|
+
])}>`;
|
|
827
836
|
}
|
|
828
837
|
} else if (name === "integer") {
|
|
829
838
|
schema = {
|
|
@@ -32,7 +32,6 @@ import {
|
|
|
32
32
|
} from "@azure-tools/typespec-azure-core";
|
|
33
33
|
import {
|
|
34
34
|
SdkClient,
|
|
35
|
-
SdkContext,
|
|
36
35
|
listOperationGroups,
|
|
37
36
|
listOperationsInOperationGroup
|
|
38
37
|
} from "@azure-tools/typespec-client-generator-core";
|
|
@@ -42,7 +41,7 @@ import {
|
|
|
42
41
|
OPERATION_LRO_HIGH_PRIORITY
|
|
43
42
|
} from "@azure-tools/rlc-common";
|
|
44
43
|
import { isByteOrByteUnion } from "./modelUtils.js";
|
|
45
|
-
import {
|
|
44
|
+
import { SdkContext } from "./interfaces.js";
|
|
46
45
|
|
|
47
46
|
export function getOperationStatuscode(
|
|
48
47
|
response: HttpOperationResponse
|
|
@@ -56,18 +55,18 @@ export function getOperationStatuscode(
|
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
export function getOperationGroupName(
|
|
59
|
-
dpgContext:
|
|
58
|
+
dpgContext: SdkContext,
|
|
60
59
|
route?: HttpOperation
|
|
61
60
|
): string;
|
|
62
61
|
export function getOperationGroupName(
|
|
63
|
-
dpgContext:
|
|
62
|
+
dpgContext: SdkContext,
|
|
64
63
|
operation?: Operation
|
|
65
64
|
): string;
|
|
66
65
|
export function getOperationGroupName(
|
|
67
|
-
dpgContext:
|
|
66
|
+
dpgContext: SdkContext,
|
|
68
67
|
operationOrRoute?: Operation | HttpOperation
|
|
69
68
|
) {
|
|
70
|
-
if (!dpgContext.
|
|
69
|
+
if (!dpgContext.rlcOptions?.enableOperationGroup || !operationOrRoute) {
|
|
71
70
|
return "";
|
|
72
71
|
}
|
|
73
72
|
const program = dpgContext.program;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixmeHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/fixmeHelpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAElE"}
|