@azure-tools/typespec-ts 0.18.0 → 0.19.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 +8 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +36 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +4 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +50 -51
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts +4 -0
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -0
- package/dist/src/modular/buildClassicalOperationGroups.js +79 -0
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -0
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +3 -2
- 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 +69 -23
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -1
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +21 -13
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +183 -73
- 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 +7 -5
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +5 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +32 -4
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +3 -2
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts +4 -0
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/classicalOperationHelpers.js +127 -0
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts +2 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +3 -2
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +2 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +14 -0
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +4 -3
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +63 -48
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +4 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +7 -5
- package/dist/src/transform/transform.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 +2 -2
- package/dist/src/transform/transformParameters.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 +2 -2
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +30 -4
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/emitUtil.d.ts.map +1 -1
- package/dist/src/utils/emitUtil.js +12 -5
- package/dist/src/utils/emitUtil.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +17 -9
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/namespaceUtils.d.ts +6 -0
- package/dist/src/utils/namespaceUtils.d.ts.map +1 -0
- package/dist/src/utils/namespaceUtils.js +54 -0
- package/dist/src/utils/namespaceUtils.js.map +1 -0
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +9 -13
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -4
- package/src/index.ts +29 -12
- package/src/lib.ts +4 -1
- package/src/modular/buildClassicalClient.ts +90 -69
- package/src/modular/buildClassicalOperationGroups.ts +151 -0
- package/src/modular/buildClientContext.ts +3 -2
- package/src/modular/buildCodeModel.ts +82 -18
- package/src/modular/buildOperations.ts +41 -16
- package/src/modular/buildProjectFiles.ts +224 -87
- package/src/modular/buildRootIndex.ts +34 -5
- package/src/modular/buildSubpathIndex.ts +41 -6
- package/src/modular/emitModels.ts +9 -2
- package/src/modular/helpers/classicalOperationHelpers.ts +212 -0
- package/src/modular/helpers/clientHelpers.ts +7 -2
- package/src/modular/helpers/namingHelpers.ts +25 -1
- package/src/modular/helpers/operationHelpers.ts +101 -46
- package/src/modular/modularCodeModel.ts +4 -0
- package/src/transform/transform.ts +10 -6
- package/src/transform/transformParameters.ts +3 -3
- package/src/transform/transformResponses.ts +4 -4
- package/src/transform/transfromRLCOptions.ts +43 -4
- package/src/utils/emitUtil.ts +10 -4
- package/src/utils/modelUtils.ts +11 -1
- package/src/utils/namespaceUtils.ts +74 -0
- package/src/utils/operationUtil.ts +10 -19
- package/dist/src/modular/helpers/credentialHelpers.d.ts +0 -7
- package/dist/src/modular/helpers/credentialHelpers.d.ts.map +0 -1
- package/dist/src/modular/helpers/credentialHelpers.js +0 -32
- package/dist/src/modular/helpers/credentialHelpers.js.map +0 -1
- package/src/modular/helpers/credentialHelpers.ts +0 -40
|
@@ -14,13 +14,14 @@ import {
|
|
|
14
14
|
} from "../modularCodeModel.js";
|
|
15
15
|
import { buildType } from "./typeHelpers.js";
|
|
16
16
|
import {
|
|
17
|
+
Imports as RuntimeImports,
|
|
17
18
|
NameType,
|
|
18
19
|
OperationResponse,
|
|
19
20
|
getResponseBaseName,
|
|
20
21
|
getResponseTypeName,
|
|
21
22
|
normalizeName
|
|
22
23
|
} from "@azure-tools/rlc-common";
|
|
23
|
-
import { getOperationName } from "./namingHelpers.js";
|
|
24
|
+
import { getClassicalLayerPrefix, getOperationName } from "./namingHelpers.js";
|
|
24
25
|
import {
|
|
25
26
|
getFixmeForMultilineDocs,
|
|
26
27
|
getDocsFromDescription
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
import { SdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
33
34
|
import { Program, NoTarget } from "@typespec/compiler";
|
|
34
35
|
import { reportDiagnostic } from "../../lib.js";
|
|
36
|
+
import { getImportSpecifier } from "@azure-tools/rlc-common";
|
|
35
37
|
|
|
36
38
|
function getRLCResponseType(rlcResponse?: OperationResponse) {
|
|
37
39
|
if (!rlcResponse?.responses) {
|
|
@@ -54,17 +56,21 @@ export function getSendPrivateFunction(
|
|
|
54
56
|
dpgContext: SdkContext,
|
|
55
57
|
operation: Operation,
|
|
56
58
|
clientType: string,
|
|
57
|
-
importSet: Map<string, Set<string
|
|
59
|
+
importSet: Map<string, Set<string>>,
|
|
60
|
+
runtimeImports: RuntimeImports
|
|
58
61
|
): OptionalKind<FunctionDeclarationStructure> {
|
|
59
62
|
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
60
63
|
const { name } = getOperationName(operation);
|
|
64
|
+
const returnType = `StreamableMethod<${getRLCResponseType(
|
|
65
|
+
operation.rlcResponse
|
|
66
|
+
)}>`;
|
|
61
67
|
|
|
62
68
|
const functionStatement: OptionalKind<FunctionDeclarationStructure> = {
|
|
63
69
|
isAsync: false,
|
|
64
70
|
isExported: true,
|
|
65
71
|
name: `_${name}Send`,
|
|
66
72
|
parameters,
|
|
67
|
-
returnType
|
|
73
|
+
returnType
|
|
68
74
|
};
|
|
69
75
|
|
|
70
76
|
const operationPath = operation.url;
|
|
@@ -77,8 +83,9 @@ export function getSendPrivateFunction(
|
|
|
77
83
|
)}).${operationMethod}({...operationOptionsToRequestParameters(options), ${getRequestParameters(
|
|
78
84
|
dpgContext,
|
|
79
85
|
operation,
|
|
80
|
-
importSet
|
|
81
|
-
|
|
86
|
+
importSet,
|
|
87
|
+
runtimeImports
|
|
88
|
+
)}}) ${operation.isOverload ? `as ${returnType}` : ``} ;`
|
|
82
89
|
);
|
|
83
90
|
|
|
84
91
|
return {
|
|
@@ -91,7 +98,8 @@ export function getDeserializePrivateFunction(
|
|
|
91
98
|
operation: Operation,
|
|
92
99
|
needSubClient: boolean,
|
|
93
100
|
needUnexpectedHelper: boolean,
|
|
94
|
-
importSet: Map<string, Set<string
|
|
101
|
+
importSet: Map<string, Set<string>>,
|
|
102
|
+
runtimeImports: RuntimeImports
|
|
95
103
|
): OptionalKind<FunctionDeclarationStructure> {
|
|
96
104
|
const { name } = getOperationName(operation);
|
|
97
105
|
|
|
@@ -157,7 +165,8 @@ export function getDeserializePrivateFunction(
|
|
|
157
165
|
getResponseMapping(
|
|
158
166
|
getAllProperties(response.type) ?? [],
|
|
159
167
|
"result.body",
|
|
160
|
-
importSet
|
|
168
|
+
importSet,
|
|
169
|
+
runtimeImports
|
|
161
170
|
).join(","),
|
|
162
171
|
`}`
|
|
163
172
|
);
|
|
@@ -169,6 +178,7 @@ export function getDeserializePrivateFunction(
|
|
|
169
178
|
response.type,
|
|
170
179
|
"result.body",
|
|
171
180
|
importSet,
|
|
181
|
+
runtimeImports,
|
|
172
182
|
response.type.nullable !== undefined ? !response.type.nullable : false,
|
|
173
183
|
response.type.format
|
|
174
184
|
)}`
|
|
@@ -184,7 +194,7 @@ function getOperationSignatureParameters(
|
|
|
184
194
|
operation: Operation,
|
|
185
195
|
clientType: string
|
|
186
196
|
): OptionalKind<ParameterDeclarationStructure>[] {
|
|
187
|
-
const optionsType = getOperationOptionsName(operation);
|
|
197
|
+
const optionsType = getOperationOptionsName(operation, true);
|
|
188
198
|
const parameters: Map<
|
|
189
199
|
string,
|
|
190
200
|
OptionalKind<ParameterDeclarationStructure>
|
|
@@ -270,12 +280,14 @@ export function getOperationFunction(
|
|
|
270
280
|
statements
|
|
271
281
|
};
|
|
272
282
|
}
|
|
273
|
-
|
|
274
283
|
export function getOperationOptionsName(
|
|
275
284
|
operation: Operation,
|
|
276
285
|
includeGroupName = false
|
|
277
286
|
) {
|
|
278
|
-
const prefix =
|
|
287
|
+
const prefix =
|
|
288
|
+
includeGroupName && operation.name.indexOf("_") === -1
|
|
289
|
+
? getClassicalLayerPrefix(operation, NameType.Interface)
|
|
290
|
+
: "";
|
|
279
291
|
const optionName = `${prefix}${toPascalCase(operation.name)}Options`;
|
|
280
292
|
if (operation.bodyParameter?.type.name === optionName) {
|
|
281
293
|
return optionName.replace(/Options$/, "RequestOptions");
|
|
@@ -291,7 +303,8 @@ export function getOperationOptionsName(
|
|
|
291
303
|
function getRequestParameters(
|
|
292
304
|
dpgContext: SdkContext,
|
|
293
305
|
operation: Operation,
|
|
294
|
-
importSet: Map<string, Set<string
|
|
306
|
+
importSet: Map<string, Set<string>>,
|
|
307
|
+
runtimeImports: RuntimeImports
|
|
295
308
|
): string {
|
|
296
309
|
if (!operation.parameters) {
|
|
297
310
|
return "";
|
|
@@ -318,7 +331,7 @@ function getRequestParameters(
|
|
|
318
331
|
param.location === "body"
|
|
319
332
|
) {
|
|
320
333
|
parametersImplementation[param.location].push({
|
|
321
|
-
paramMap: getParameterMap(param, importSet),
|
|
334
|
+
paramMap: getParameterMap(param, importSet, runtimeImports),
|
|
322
335
|
param
|
|
323
336
|
});
|
|
324
337
|
}
|
|
@@ -351,7 +364,8 @@ function getRequestParameters(
|
|
|
351
364
|
} else if (operation.bodyParameter !== undefined) {
|
|
352
365
|
paramStr = `${paramStr}${buildBodyParameter(
|
|
353
366
|
operation.bodyParameter,
|
|
354
|
-
importSet
|
|
367
|
+
importSet,
|
|
368
|
+
runtimeImports
|
|
355
369
|
)}`;
|
|
356
370
|
}
|
|
357
371
|
return paramStr;
|
|
@@ -384,7 +398,8 @@ function buildHeaderParameter(
|
|
|
384
398
|
|
|
385
399
|
function buildBodyParameter(
|
|
386
400
|
bodyParameter: BodyParameter | undefined,
|
|
387
|
-
importSet: Map<string, Set<string
|
|
401
|
+
importSet: Map<string, Set<string>>,
|
|
402
|
+
runtimeImports: RuntimeImports
|
|
388
403
|
) {
|
|
389
404
|
if (!bodyParameter) {
|
|
390
405
|
return "";
|
|
@@ -394,7 +409,8 @@ function buildBodyParameter(
|
|
|
394
409
|
const bodyParts: string[] = getRequestModelMapping(
|
|
395
410
|
bodyParameter.type,
|
|
396
411
|
bodyParameter.clientName,
|
|
397
|
-
importSet
|
|
412
|
+
importSet,
|
|
413
|
+
runtimeImports
|
|
398
414
|
);
|
|
399
415
|
|
|
400
416
|
if (bodyParameter && bodyParts.length > 0) {
|
|
@@ -407,7 +423,8 @@ function buildBodyParameter(
|
|
|
407
423
|
const bodyParts = getRequestModelMapping(
|
|
408
424
|
bodyParameter.type.elementType,
|
|
409
425
|
"p",
|
|
410
|
-
importSet
|
|
426
|
+
importSet,
|
|
427
|
+
runtimeImports
|
|
411
428
|
);
|
|
412
429
|
return `\nbody: (${bodyParameter.clientName} ?? []).map((p) => { return {
|
|
413
430
|
${bodyParts.join(", ")}
|
|
@@ -420,12 +437,10 @@ function buildBodyParameter(
|
|
|
420
437
|
bodyParameter.type.type === "byte-array" &&
|
|
421
438
|
!bodyParameter.isBinaryPayload
|
|
422
439
|
) {
|
|
423
|
-
const
|
|
440
|
+
const specifier = getImportSpecifier("coreUtil", runtimeImports);
|
|
441
|
+
const coreUtilSet = importSet.get(specifier);
|
|
424
442
|
if (!coreUtilSet) {
|
|
425
|
-
importSet.set(
|
|
426
|
-
"@azure/core-util",
|
|
427
|
-
new Set<string>().add("uint8ArrayToString")
|
|
428
|
-
);
|
|
443
|
+
importSet.set(specifier, new Set<string>().add("uint8ArrayToString"));
|
|
429
444
|
} else {
|
|
430
445
|
coreUtilSet.add("uint8ArrayToString");
|
|
431
446
|
}
|
|
@@ -460,23 +475,24 @@ function getEncodingFormat(type: { format?: string }) {
|
|
|
460
475
|
*/
|
|
461
476
|
function getParameterMap(
|
|
462
477
|
param: Parameter | Property,
|
|
463
|
-
importSet: Map<string, Set<string
|
|
478
|
+
importSet: Map<string, Set<string>>,
|
|
479
|
+
runtimeImports: RuntimeImports
|
|
464
480
|
): string {
|
|
465
481
|
if (isConstant(param)) {
|
|
466
482
|
return getConstantValue(param);
|
|
467
483
|
}
|
|
468
484
|
|
|
469
485
|
if (hasCollectionFormatInfo((param as any).location, (param as any).format)) {
|
|
470
|
-
return getCollectionFormat(param as Parameter, importSet);
|
|
486
|
+
return getCollectionFormat(param as Parameter, importSet, runtimeImports);
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
// if the parameter or property is optional, we don't need to handle the default value
|
|
474
490
|
if (isOptional(param)) {
|
|
475
|
-
return getOptional(param, importSet);
|
|
491
|
+
return getOptional(param, importSet, runtimeImports);
|
|
476
492
|
}
|
|
477
493
|
|
|
478
494
|
if (isRequired(param)) {
|
|
479
|
-
return getRequired(param, importSet);
|
|
495
|
+
return getRequired(param, importSet, runtimeImports);
|
|
480
496
|
}
|
|
481
497
|
|
|
482
498
|
throw new Error(`Parameter ${param.clientName} is not supported`);
|
|
@@ -484,7 +500,8 @@ function getParameterMap(
|
|
|
484
500
|
|
|
485
501
|
function getCollectionFormat(
|
|
486
502
|
param: Parameter,
|
|
487
|
-
importSet: Map<string, Set<string
|
|
503
|
+
importSet: Map<string, Set<string>>,
|
|
504
|
+
runtimeImports: RuntimeImports
|
|
488
505
|
) {
|
|
489
506
|
const collectionInfo = getCollectionFormatHelper(
|
|
490
507
|
param.location,
|
|
@@ -500,6 +517,7 @@ function getCollectionFormat(
|
|
|
500
517
|
param.type,
|
|
501
518
|
param.clientName,
|
|
502
519
|
importSet,
|
|
520
|
+
runtimeImports,
|
|
503
521
|
true,
|
|
504
522
|
param.format
|
|
505
523
|
)}${additionalParam})`;
|
|
@@ -510,6 +528,7 @@ function getCollectionFormat(
|
|
|
510
528
|
param.type,
|
|
511
529
|
"options?." + param.clientName,
|
|
512
530
|
importSet,
|
|
531
|
+
runtimeImports,
|
|
513
532
|
false,
|
|
514
533
|
param.format
|
|
515
534
|
)}${additionalParam}): undefined`;
|
|
@@ -547,18 +566,24 @@ function isRequired(param: Parameter | Property): param is RequiredType {
|
|
|
547
566
|
return !param.optional;
|
|
548
567
|
}
|
|
549
568
|
|
|
550
|
-
function getRequired(
|
|
569
|
+
function getRequired(
|
|
570
|
+
param: RequiredType,
|
|
571
|
+
importSet: Map<string, Set<string>>,
|
|
572
|
+
runtimeImports: RuntimeImports
|
|
573
|
+
) {
|
|
551
574
|
if (param.type.type === "model") {
|
|
552
575
|
return `"${param.restApiName}": {${getRequestModelMapping(
|
|
553
576
|
param.type,
|
|
554
577
|
param.clientName,
|
|
555
|
-
importSet
|
|
578
|
+
importSet,
|
|
579
|
+
runtimeImports
|
|
556
580
|
).join(",")}}`;
|
|
557
581
|
}
|
|
558
582
|
return `"${param.restApiName}": ${serializeRequestValue(
|
|
559
583
|
param.type,
|
|
560
584
|
param.clientName,
|
|
561
585
|
importSet,
|
|
586
|
+
runtimeImports,
|
|
562
587
|
true,
|
|
563
588
|
param.format === undefined &&
|
|
564
589
|
(param as Parameter).location === "header" &&
|
|
@@ -599,18 +624,24 @@ function isOptional(param: Parameter | Property): param is OptionalType {
|
|
|
599
624
|
return Boolean(param.optional);
|
|
600
625
|
}
|
|
601
626
|
|
|
602
|
-
function getOptional(
|
|
627
|
+
function getOptional(
|
|
628
|
+
param: OptionalType,
|
|
629
|
+
importSet: Map<string, Set<string>>,
|
|
630
|
+
runtimeImports: RuntimeImports
|
|
631
|
+
) {
|
|
603
632
|
if (param.type.type === "model") {
|
|
604
633
|
return `"${param.restApiName}": {${getRequestModelMapping(
|
|
605
634
|
param.type,
|
|
606
635
|
"options?." + param.clientName + "?",
|
|
607
|
-
importSet
|
|
636
|
+
importSet,
|
|
637
|
+
runtimeImports
|
|
608
638
|
).join(", ")}}`;
|
|
609
639
|
}
|
|
610
640
|
return `"${param.restApiName}": ${serializeRequestValue(
|
|
611
641
|
param.type,
|
|
612
642
|
`options?.${param.clientName}`,
|
|
613
643
|
importSet,
|
|
644
|
+
runtimeImports,
|
|
614
645
|
false,
|
|
615
646
|
param.format === undefined &&
|
|
616
647
|
(param as Parameter).location === "header" &&
|
|
@@ -679,7 +710,8 @@ function getNullableCheck(name: string, type: Type) {
|
|
|
679
710
|
function getRequestModelMapping(
|
|
680
711
|
modelPropertyType: Type,
|
|
681
712
|
propertyPath: string = "body",
|
|
682
|
-
importSet: Map<string, Set<string
|
|
713
|
+
importSet: Map<string, Set<string>>,
|
|
714
|
+
runtimeImports: RuntimeImports
|
|
683
715
|
) {
|
|
684
716
|
if (getAllProperties(modelPropertyType).length <= 0) {
|
|
685
717
|
return [];
|
|
@@ -722,7 +754,8 @@ function getRequestModelMapping(
|
|
|
722
754
|
`${propertyPath}.${property.clientName}${
|
|
723
755
|
property.optional ? "?" : ""
|
|
724
756
|
}`,
|
|
725
|
-
importSet
|
|
757
|
+
importSet,
|
|
758
|
+
runtimeImports
|
|
726
759
|
)}}`;
|
|
727
760
|
}
|
|
728
761
|
|
|
@@ -749,6 +782,7 @@ function getRequestModelMapping(
|
|
|
749
782
|
property.type,
|
|
750
783
|
clientValue,
|
|
751
784
|
importSet,
|
|
785
|
+
runtimeImports,
|
|
752
786
|
!property.optional,
|
|
753
787
|
property.format
|
|
754
788
|
)}`
|
|
@@ -766,7 +800,8 @@ function getRequestModelMapping(
|
|
|
766
800
|
export function getResponseMapping(
|
|
767
801
|
properties: Property[],
|
|
768
802
|
propertyPath: string = "result.body",
|
|
769
|
-
importSet: Map<string, Set<string
|
|
803
|
+
importSet: Map<string, Set<string>>,
|
|
804
|
+
runtimeImports: RuntimeImports
|
|
770
805
|
) {
|
|
771
806
|
const props: string[] = [];
|
|
772
807
|
for (const property of properties) {
|
|
@@ -803,7 +838,8 @@ export function getResponseMapping(
|
|
|
803
838
|
`${propertyPath}.${property.restApiName}${
|
|
804
839
|
property.optional ? "?" : ""
|
|
805
840
|
}`,
|
|
806
|
-
importSet
|
|
841
|
+
importSet,
|
|
842
|
+
runtimeImports
|
|
807
843
|
)}}`;
|
|
808
844
|
}
|
|
809
845
|
|
|
@@ -832,6 +868,7 @@ export function getResponseMapping(
|
|
|
832
868
|
property.type,
|
|
833
869
|
restValue,
|
|
834
870
|
importSet,
|
|
871
|
+
runtimeImports,
|
|
835
872
|
property.optional !== undefined ? !property.optional : false,
|
|
836
873
|
property.format
|
|
837
874
|
)}`
|
|
@@ -852,10 +889,12 @@ function deserializeResponseValue(
|
|
|
852
889
|
type: Type,
|
|
853
890
|
restValue: string,
|
|
854
891
|
importSet: Map<string, Set<string>>,
|
|
892
|
+
runtimeImports: RuntimeImports,
|
|
855
893
|
required: boolean,
|
|
856
894
|
format?: string
|
|
857
895
|
): string {
|
|
858
|
-
const
|
|
896
|
+
const coreSpecifier = getImportSpecifier("coreUtil", runtimeImports);
|
|
897
|
+
const coreUtilSet = importSet.get(coreSpecifier);
|
|
859
898
|
switch (type.type) {
|
|
860
899
|
case "datetime":
|
|
861
900
|
return required
|
|
@@ -865,29 +904,36 @@ function deserializeResponseValue(
|
|
|
865
904
|
: `${restValue} !== undefined? new Date(${restValue}): undefined`;
|
|
866
905
|
case "combined":
|
|
867
906
|
return `${restValue} as any`;
|
|
868
|
-
case "list":
|
|
907
|
+
case "list": {
|
|
908
|
+
const prefix =
|
|
909
|
+
required && !type.nullable
|
|
910
|
+
? `${restValue}`
|
|
911
|
+
: `!${restValue} ? ${restValue} : ${restValue}`;
|
|
869
912
|
if (type.elementType?.type === "model") {
|
|
870
|
-
return
|
|
913
|
+
return `${prefix}.map(p => ({${getResponseMapping(
|
|
871
914
|
getAllProperties(type.elementType) ?? [],
|
|
872
915
|
"p",
|
|
873
|
-
importSet
|
|
916
|
+
importSet,
|
|
917
|
+
runtimeImports
|
|
874
918
|
)}}))`;
|
|
875
919
|
} else if (needsDeserialize(type.elementType)) {
|
|
876
|
-
return
|
|
920
|
+
return `${prefix}.map(p => ${deserializeResponseValue(
|
|
877
921
|
type.elementType!,
|
|
878
922
|
"p",
|
|
879
923
|
importSet,
|
|
924
|
+
runtimeImports,
|
|
880
925
|
required,
|
|
881
926
|
type.elementType?.format
|
|
882
927
|
)})`;
|
|
883
928
|
} else {
|
|
884
929
|
return restValue;
|
|
885
930
|
}
|
|
931
|
+
}
|
|
886
932
|
case "byte-array":
|
|
887
933
|
if (format !== "binary") {
|
|
888
934
|
if (!coreUtilSet) {
|
|
889
935
|
importSet.set(
|
|
890
|
-
|
|
936
|
+
coreSpecifier,
|
|
891
937
|
new Set<string>().add("stringToUint8Array")
|
|
892
938
|
);
|
|
893
939
|
} else {
|
|
@@ -912,10 +958,12 @@ function serializeRequestValue(
|
|
|
912
958
|
type: Type,
|
|
913
959
|
clientValue: string,
|
|
914
960
|
importSet: Map<string, Set<string>>,
|
|
961
|
+
runtimeImports: RuntimeImports,
|
|
915
962
|
required: boolean,
|
|
916
963
|
format?: string
|
|
917
964
|
): string {
|
|
918
|
-
const
|
|
965
|
+
const utilSpecifier = getImportSpecifier("coreUtil", runtimeImports);
|
|
966
|
+
const coreUtilSet = importSet.get(utilSpecifier);
|
|
919
967
|
switch (type.type) {
|
|
920
968
|
case "datetime":
|
|
921
969
|
switch (type.format ?? format) {
|
|
@@ -932,29 +980,36 @@ function serializeRequestValue(
|
|
|
932
980
|
default:
|
|
933
981
|
return `${clientValue}${required ? "" : "?"}.toISOString()`;
|
|
934
982
|
}
|
|
935
|
-
case "list":
|
|
983
|
+
case "list": {
|
|
984
|
+
const prefix =
|
|
985
|
+
required && !type.nullable
|
|
986
|
+
? `${clientValue}`
|
|
987
|
+
: `!${clientValue} ? ${clientValue} : ${clientValue}`;
|
|
936
988
|
if (type.elementType?.type === "model") {
|
|
937
|
-
return
|
|
989
|
+
return `${prefix}.map(p => ({${getRequestModelMapping(
|
|
938
990
|
type.elementType,
|
|
939
991
|
"p",
|
|
940
|
-
importSet
|
|
992
|
+
importSet,
|
|
993
|
+
runtimeImports
|
|
941
994
|
)}}))`;
|
|
942
995
|
} else if (needsDeserialize(type.elementType)) {
|
|
943
|
-
return
|
|
996
|
+
return `${prefix}.map(p => ${serializeRequestValue(
|
|
944
997
|
type.elementType!,
|
|
945
998
|
"p",
|
|
946
999
|
importSet,
|
|
1000
|
+
runtimeImports,
|
|
947
1001
|
required,
|
|
948
1002
|
type.elementType?.format
|
|
949
1003
|
)})`;
|
|
950
1004
|
} else {
|
|
951
1005
|
return clientValue;
|
|
952
1006
|
}
|
|
1007
|
+
}
|
|
953
1008
|
case "byte-array":
|
|
954
1009
|
if (format !== "binary") {
|
|
955
1010
|
if (!coreUtilSet) {
|
|
956
1011
|
importSet.set(
|
|
957
|
-
|
|
1012
|
+
utilSpecifier,
|
|
958
1013
|
new Set<string>().add("uint8ArrayToString")
|
|
959
1014
|
);
|
|
960
1015
|
} else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Imports } from "@azure-tools/rlc-common";
|
|
1
2
|
import { OperationResponse, RLCOptions } from "@azure-tools/rlc-common";
|
|
2
3
|
import { Project } from "ts-morph";
|
|
3
4
|
|
|
@@ -12,6 +13,7 @@ export interface ModularCodeModel {
|
|
|
12
13
|
clients: Client[];
|
|
13
14
|
types: Type[];
|
|
14
15
|
project: Project;
|
|
16
|
+
runtimeImports: Imports;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export interface Header {
|
|
@@ -47,6 +49,7 @@ export interface OperationGroup {
|
|
|
47
49
|
className: string;
|
|
48
50
|
propertyName: string;
|
|
49
51
|
operations: Operation[];
|
|
52
|
+
namespaceHierarchies: string[];
|
|
50
53
|
}
|
|
51
54
|
export interface Policy {
|
|
52
55
|
type: string;
|
|
@@ -168,4 +171,5 @@ export interface Operation {
|
|
|
168
171
|
continuationTokenName?: string;
|
|
169
172
|
addedOn?: string;
|
|
170
173
|
rlcResponse?: OperationResponse;
|
|
174
|
+
namespaceHierarchies: string[];
|
|
171
175
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { SdkClient } from "@azure-tools/typespec-client-generator-core";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
buildRuntimeImports,
|
|
7
7
|
NameType,
|
|
8
8
|
normalizeName,
|
|
9
9
|
OperationParameter,
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
RLCOptions,
|
|
15
15
|
Schema,
|
|
16
16
|
SchemaContext,
|
|
17
|
-
UrlInfo
|
|
17
|
+
UrlInfo,
|
|
18
|
+
initInternalImports,
|
|
19
|
+
transformSampleGroups
|
|
18
20
|
} from "@azure-tools/rlc-common";
|
|
19
21
|
import { getDoc } from "@typespec/compiler";
|
|
20
22
|
import { getServers } from "@typespec/http";
|
|
@@ -35,7 +37,6 @@ import { transformApiVersionInfo } from "./transformApiVersionInfo.js";
|
|
|
35
37
|
import { getClientLroOverload } from "../utils/operationUtil.js";
|
|
36
38
|
import { transformTelemetryInfo } from "./transformTelemetryInfo.js";
|
|
37
39
|
import { SdkContext } from "../utils/interfaces.js";
|
|
38
|
-
import { transformSampleGroups } from "@azure-tools/rlc-common";
|
|
39
40
|
|
|
40
41
|
export async function transformRLCModel(
|
|
41
42
|
client: SdkClient,
|
|
@@ -58,7 +59,7 @@ export async function transformRLCModel(
|
|
|
58
59
|
"",
|
|
59
60
|
NameType.Class
|
|
60
61
|
);
|
|
61
|
-
const importSet =
|
|
62
|
+
const importSet = initInternalImports();
|
|
62
63
|
const paths: Paths = transformPaths(program, client, dpgContext);
|
|
63
64
|
const schemas: Schema[] = transformSchemas(program, client, dpgContext);
|
|
64
65
|
const responses: OperationResponse[] = transformToResponseTypes(
|
|
@@ -84,12 +85,15 @@ export async function transformRLCModel(
|
|
|
84
85
|
options,
|
|
85
86
|
schemas,
|
|
86
87
|
responses,
|
|
87
|
-
importSet,
|
|
88
88
|
apiVersionInfo,
|
|
89
89
|
parameters,
|
|
90
90
|
helperDetails,
|
|
91
91
|
urlInfo,
|
|
92
|
-
telemetryOptions
|
|
92
|
+
telemetryOptions,
|
|
93
|
+
importInfo: {
|
|
94
|
+
internalImports: importSet,
|
|
95
|
+
runtimeImports: buildRuntimeImports(options.branded)
|
|
96
|
+
}
|
|
93
97
|
};
|
|
94
98
|
model.sampleGroups = transformSampleGroups(
|
|
95
99
|
model,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
Imports,
|
|
6
6
|
ObjectSchema,
|
|
7
7
|
OperationParameter,
|
|
8
8
|
ParameterBodyMetadata,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
import { SdkContext } from "../utils/interfaces.js";
|
|
43
43
|
|
|
44
44
|
export function transformToParameterTypes(
|
|
45
|
-
importDetails:
|
|
45
|
+
importDetails: Imports,
|
|
46
46
|
client: SdkClient,
|
|
47
47
|
dpgContext: SdkContext
|
|
48
48
|
): OperationParameter[] {
|
|
@@ -74,7 +74,7 @@ export function transformToParameterTypes(
|
|
|
74
74
|
transformToParameterTypesForRoute(program, route);
|
|
75
75
|
}
|
|
76
76
|
if (outputImportedSet.size > 0) {
|
|
77
|
-
importDetails.
|
|
77
|
+
importDetails.parameter.importsSet = outputImportedSet;
|
|
78
78
|
}
|
|
79
79
|
function transformToParameterTypesForRoute(
|
|
80
80
|
program: Program,
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
} from "@azure-tools/typespec-client-generator-core";
|
|
9
9
|
import {
|
|
10
10
|
ResponseHeaderSchema,
|
|
11
|
-
ImportKind,
|
|
12
11
|
OperationResponse,
|
|
13
12
|
ResponseMetadata,
|
|
14
13
|
Schema,
|
|
15
14
|
SchemaContext,
|
|
16
|
-
getLroLogicalResponseName
|
|
15
|
+
getLroLogicalResponseName,
|
|
16
|
+
Imports
|
|
17
17
|
} from "@azure-tools/rlc-common";
|
|
18
18
|
import { getDoc, ignoreDiagnostics } from "@typespec/compiler";
|
|
19
19
|
import {
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
import { SdkContext } from "../utils/interfaces.js";
|
|
39
39
|
|
|
40
40
|
export function transformToResponseTypes(
|
|
41
|
-
importDetails:
|
|
41
|
+
importDetails: Imports,
|
|
42
42
|
client: SdkClient,
|
|
43
43
|
dpgContext: SdkContext
|
|
44
44
|
): OperationResponse[] {
|
|
@@ -70,7 +70,7 @@ export function transformToResponseTypes(
|
|
|
70
70
|
transformToResponseTypesForRoute(route);
|
|
71
71
|
}
|
|
72
72
|
if (inputImportedSet.size > 0) {
|
|
73
|
-
importDetails.
|
|
73
|
+
importDetails.response.importsSet = inputImportedSet;
|
|
74
74
|
}
|
|
75
75
|
function transformToResponseTypesForRoute(route: HttpOperation) {
|
|
76
76
|
const rlcOperationUnit: OperationResponse = {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
listOperationsInOperationGroup
|
|
22
22
|
} from "@azure-tools/typespec-client-generator-core";
|
|
23
23
|
import { getOperationName } from "../utils/operationUtil.js";
|
|
24
|
+
import { detectModelConflicts } from "../utils/namespaceUtils.js";
|
|
24
25
|
|
|
25
26
|
export function transformRLCOptions(
|
|
26
27
|
emitterOptions: RLCOptions,
|
|
@@ -56,9 +57,15 @@ function extractRLCOptions(
|
|
|
56
57
|
dpgContext,
|
|
57
58
|
emitterOptions
|
|
58
59
|
);
|
|
60
|
+
const enableModelNamespace = getEnableModelNamespace(
|
|
61
|
+
dpgContext,
|
|
62
|
+
emitterOptions
|
|
63
|
+
);
|
|
64
|
+
const hierarchyClient = getHierarchyClient(emitterOptions);
|
|
59
65
|
return {
|
|
60
66
|
...emitterOptions,
|
|
61
67
|
...credentialInfo,
|
|
68
|
+
branded: getBranded(emitterOptions),
|
|
62
69
|
includeShortcuts,
|
|
63
70
|
packageDetails,
|
|
64
71
|
generateMetadata,
|
|
@@ -67,7 +74,9 @@ function extractRLCOptions(
|
|
|
67
74
|
serviceInfo,
|
|
68
75
|
azureOutputDirectory,
|
|
69
76
|
sourceFrom: "TypeSpec",
|
|
70
|
-
enableOperationGroup
|
|
77
|
+
enableOperationGroup,
|
|
78
|
+
enableModelNamespace,
|
|
79
|
+
hierarchyClient
|
|
71
80
|
};
|
|
72
81
|
}
|
|
73
82
|
|
|
@@ -136,15 +145,41 @@ function getEnableOperationGroup(
|
|
|
136
145
|
) {
|
|
137
146
|
return emitterOptions.enableOperationGroup;
|
|
138
147
|
}
|
|
139
|
-
//
|
|
148
|
+
// Only detect if existing name conflicts if customers don't set hierarchyClient to true
|
|
140
149
|
return detectIfNameConflicts(dpgContext);
|
|
141
150
|
}
|
|
142
151
|
|
|
152
|
+
function getEnableModelNamespace(
|
|
153
|
+
dpgContext: SdkContext,
|
|
154
|
+
emitterOptions: RLCOptions
|
|
155
|
+
) {
|
|
156
|
+
if (
|
|
157
|
+
emitterOptions.enableModelNamespace === true ||
|
|
158
|
+
emitterOptions.enableModelNamespace === false
|
|
159
|
+
) {
|
|
160
|
+
return emitterOptions.enableModelNamespace;
|
|
161
|
+
}
|
|
162
|
+
// Detect if existing name conflicts if customers didn't set the option explicitly
|
|
163
|
+
return detectModelConflicts(dpgContext);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getHierarchyClient(emitterOptions: RLCOptions) {
|
|
167
|
+
if (
|
|
168
|
+
emitterOptions.hierarchyClient === true ||
|
|
169
|
+
emitterOptions.hierarchyClient === false
|
|
170
|
+
) {
|
|
171
|
+
return emitterOptions.hierarchyClient;
|
|
172
|
+
}
|
|
173
|
+
// enable hierarchy client by default if customers didn't set the option explicitly
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
143
177
|
function detectIfNameConflicts(dpgContext: SdkContext) {
|
|
144
178
|
const clients = getRLCClients(dpgContext);
|
|
145
179
|
const program = dpgContext.program;
|
|
146
|
-
const nameSet = new Set<string>();
|
|
147
180
|
for (const client of clients) {
|
|
181
|
+
// only consider it's conflict when there are conflicts in the same client
|
|
182
|
+
const nameSet = new Set<string>();
|
|
148
183
|
const operationGroups = listOperationGroups(dpgContext, client);
|
|
149
184
|
for (const operationGroup of operationGroups) {
|
|
150
185
|
const operations = listOperationsInOperationGroup(
|
|
@@ -181,6 +216,10 @@ function getIncludeShortcuts(emitterOptions: RLCOptions) {
|
|
|
181
216
|
return Boolean(emitterOptions.includeShortcuts);
|
|
182
217
|
}
|
|
183
218
|
|
|
219
|
+
function getBranded(emitterOptions: RLCOptions) {
|
|
220
|
+
return emitterOptions.branded !== undefined ? emitterOptions.branded : true;
|
|
221
|
+
}
|
|
222
|
+
|
|
184
223
|
function getPackageDetails(
|
|
185
224
|
program: Program,
|
|
186
225
|
emitterOptions: RLCOptions
|
|
@@ -246,7 +285,7 @@ export function getCredentialInfo(
|
|
|
246
285
|
) {
|
|
247
286
|
const securityInfo = processAuth(program);
|
|
248
287
|
const addCredentials =
|
|
249
|
-
|
|
288
|
+
emitterOptions.addCredentials === false
|
|
250
289
|
? false
|
|
251
290
|
: securityInfo
|
|
252
291
|
? securityInfo.addCredentials
|