@azure-tools/typespec-ts 0.44.1 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +64 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +42 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +1 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +19 -3
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +9 -5
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/emitSamples.js +31 -6
- package/dist/src/modular/emitSamples.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +10 -1
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.js +28 -6
- package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +28 -6
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +2 -1
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformParameters.js +1 -1
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.js +1 -1
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +1 -5
- 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 -3
- package/dist/src/utils/emitUtil.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +0 -2
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +3 -22
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +1 -5
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +2 -52
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/src/index.ts +1 -1
- package/src/lib.ts +42 -0
- package/src/modular/buildRootIndex.ts +19 -7
- package/src/modular/emitModels.ts +9 -8
- package/src/modular/emitSamples.ts +29 -4
- package/src/modular/helpers/operationHelpers.ts +11 -1
- package/src/modular/serialization/buildDeserializerFunction.ts +28 -6
- package/src/modular/serialization/buildSerializerFunction.ts +28 -6
- package/src/transform/transformApiVersionInfo.ts +2 -1
- package/src/transform/transformParameters.ts +1 -1
- package/src/transform/transformPaths.ts +1 -1
- package/src/transform/transfromRLCOptions.ts +1 -5
- package/src/utils/emitUtil.ts +16 -4
- package/src/utils/modelUtils.ts +3 -37
- package/src/utils/operationUtil.ts +1 -60
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.1",
|
|
4
4
|
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@azure-rest/core-client": "^2.3.1",
|
|
21
|
-
"@typespec/http-specs": "0.1.0-alpha.
|
|
22
|
-
"@typespec/spector": "0.1.0-alpha.
|
|
21
|
+
"@typespec/http-specs": "0.1.0-alpha.28-dev.0",
|
|
22
|
+
"@typespec/spector": "0.1.0-alpha.20-dev.0",
|
|
23
23
|
"@typespec/spec-api": "0.1.0-alpha.10-dev.0",
|
|
24
|
-
"@typespec/tspd": "0.
|
|
25
|
-
"@azure-tools/azure-http-specs": "0.1.0-alpha.
|
|
26
|
-
"@azure-tools/typespec-autorest": "^0.
|
|
27
|
-
"@azure-tools/typespec-azure-core": "^0.
|
|
28
|
-
"@azure-tools/typespec-azure-resource-manager": "^0.
|
|
29
|
-
"@azure-tools/typespec-client-generator-core": "^0.
|
|
24
|
+
"@typespec/tspd": "0.73.0",
|
|
25
|
+
"@azure-tools/azure-http-specs": "0.1.0-alpha.31-dev.0",
|
|
26
|
+
"@azure-tools/typespec-autorest": "^0.61.0",
|
|
27
|
+
"@azure-tools/typespec-azure-core": "^0.61.0",
|
|
28
|
+
"@azure-tools/typespec-azure-resource-manager": "^0.61.0",
|
|
29
|
+
"@azure-tools/typespec-client-generator-core": "^0.61.0",
|
|
30
30
|
"@azure/abort-controller": "^2.1.2",
|
|
31
31
|
"@azure/core-auth": "^1.6.0",
|
|
32
32
|
"@azure/core-lro": "^3.1.0",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"@types/node": "^18.0.0",
|
|
42
42
|
"@typescript-eslint/eslint-plugin": "^8.28.0",
|
|
43
43
|
"@typescript-eslint/parser": "^8.28.0",
|
|
44
|
-
"@typespec/compiler": "^1.
|
|
45
|
-
"@typespec/http": "^1.
|
|
46
|
-
"@typespec/openapi": "^1.
|
|
47
|
-
"@typespec/rest": "^0.
|
|
44
|
+
"@typespec/compiler": "^1.5.0",
|
|
45
|
+
"@typespec/http": "^1.5.0",
|
|
46
|
+
"@typespec/openapi": "^1.5.0",
|
|
47
|
+
"@typespec/rest": "^0.75.0",
|
|
48
48
|
"@typespec/ts-http-runtime": "^0.1.0",
|
|
49
|
-
"@typespec/versioning": "^0.
|
|
49
|
+
"@typespec/versioning": "^0.75.0",
|
|
50
50
|
"chai": "^4.3.6",
|
|
51
51
|
"chalk": "^4.0.0",
|
|
52
52
|
"cross-env": "^7.0.3",
|
|
@@ -68,16 +68,16 @@
|
|
|
68
68
|
"js-yaml": "^4.1.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@azure-tools/typespec-azure-core": "^0.
|
|
72
|
-
"@azure-tools/typespec-client-generator-core": "^0.
|
|
73
|
-
"@typespec/compiler": "^1.
|
|
74
|
-
"@typespec/http": "^1.
|
|
75
|
-
"@typespec/rest": "^0.
|
|
76
|
-
"@typespec/versioning": "^0.
|
|
77
|
-
"@typespec/xml": "^0.
|
|
71
|
+
"@azure-tools/typespec-azure-core": "^0.61.0",
|
|
72
|
+
"@azure-tools/typespec-client-generator-core": "^0.61.0",
|
|
73
|
+
"@typespec/compiler": "^1.5.0",
|
|
74
|
+
"@typespec/http": "^1.5.0",
|
|
75
|
+
"@typespec/rest": "^0.75.0",
|
|
76
|
+
"@typespec/versioning": "^0.75.0",
|
|
77
|
+
"@typespec/xml": "^0.75.0"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@azure-tools/rlc-common": "^0.
|
|
80
|
+
"@azure-tools/rlc-common": "^0.45.1",
|
|
81
81
|
"fs-extra": "^11.1.0",
|
|
82
82
|
"lodash": "^4.17.21",
|
|
83
83
|
"prettier": "^3.3.3",
|
package/src/index.ts
CHANGED
|
@@ -334,7 +334,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
334
334
|
interfaceOnly: true
|
|
335
335
|
});
|
|
336
336
|
if (isMultiClients) {
|
|
337
|
-
buildSubClientIndexFile(subClient, modularEmitterOptions);
|
|
337
|
+
buildSubClientIndexFile(dpgContext, subClient, modularEmitterOptions);
|
|
338
338
|
}
|
|
339
339
|
buildRootIndex(
|
|
340
340
|
dpgContext,
|
package/src/lib.ts
CHANGED
|
@@ -540,6 +540,48 @@ const libDef = {
|
|
|
540
540
|
messages: {
|
|
541
541
|
default: paramMessage`The parameter name ${"parameterName"} has conflicts with others and please use @clientName to rename it.`
|
|
542
542
|
}
|
|
543
|
+
},
|
|
544
|
+
"unsupported-parameter-type": {
|
|
545
|
+
severity: "error",
|
|
546
|
+
messages: {
|
|
547
|
+
default: paramMessage`Parameter '${"paramName"}' with kind '${"paramKind"}' is not supported.`
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
"unknown-sdk-method-kind": {
|
|
551
|
+
severity: "error",
|
|
552
|
+
messages: {
|
|
553
|
+
default: paramMessage`Unknown SDK method kind: '${"methodKind"}'.`
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
"client-file-not-found": {
|
|
557
|
+
severity: "error",
|
|
558
|
+
messages: {
|
|
559
|
+
default: paramMessage`Client file not found: '${"filePath"}'.`
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
"anonymous-type-serialization": {
|
|
563
|
+
severity: "error",
|
|
564
|
+
messages: {
|
|
565
|
+
default: "Serialization of anonymous types is not yet implemented."
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
"anonymous-type-deserialization": {
|
|
569
|
+
severity: "error",
|
|
570
|
+
messages: {
|
|
571
|
+
default: "Deserialization of anonymous types is not yet implemented."
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
"lro-polling-config-error": {
|
|
575
|
+
severity: "error",
|
|
576
|
+
messages: {
|
|
577
|
+
default: paramMessage`LRO polling configuration error: ${"message"}.`
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
"file-formatting-error": {
|
|
581
|
+
severity: "error",
|
|
582
|
+
messages: {
|
|
583
|
+
default: paramMessage`Failed to format file: ${"filePath"}. Error: ${"error"}.`
|
|
584
|
+
}
|
|
543
585
|
}
|
|
544
586
|
},
|
|
545
587
|
emitter: {
|
|
@@ -17,6 +17,8 @@ import { getModularClientOptions } from "../utils/clientUtils.js";
|
|
|
17
17
|
import { getMethodHierarchiesMap } from "../utils/operationUtil.js";
|
|
18
18
|
import { join } from "path/posix";
|
|
19
19
|
import { useContext } from "../contextManager.js";
|
|
20
|
+
import { reportDiagnostic } from "../lib.js";
|
|
21
|
+
import { NoTarget } from "@typespec/compiler";
|
|
20
22
|
|
|
21
23
|
export function buildRootIndex(
|
|
22
24
|
context: SdkContext,
|
|
@@ -42,12 +44,14 @@ export function buildRootIndex(
|
|
|
42
44
|
);
|
|
43
45
|
|
|
44
46
|
if (!clientFile) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
NameType.File
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
reportDiagnostic(context.program, {
|
|
48
|
+
code: "client-file-not-found",
|
|
49
|
+
format: {
|
|
50
|
+
filePath: `${srcPath}/${normalizeName(clientName, NameType.File)}.ts`
|
|
51
|
+
},
|
|
52
|
+
target: NoTarget
|
|
53
|
+
});
|
|
54
|
+
return; // Skip exporting this client but continue with others
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
exportClassicalClient(client, rootIndexFile, subfolder ?? "");
|
|
@@ -346,6 +350,7 @@ function exportModules(
|
|
|
346
350
|
}
|
|
347
351
|
|
|
348
352
|
export function buildSubClientIndexFile(
|
|
353
|
+
context: SdkContext,
|
|
349
354
|
clientMap: [string[], SdkClientType<SdkServiceOperation>],
|
|
350
355
|
emitterOptions: ModularEmitterOptions
|
|
351
356
|
) {
|
|
@@ -365,7 +370,14 @@ export function buildSubClientIndexFile(
|
|
|
365
370
|
const clientFile = project.getSourceFile(clientFilePath);
|
|
366
371
|
|
|
367
372
|
if (!clientFile) {
|
|
368
|
-
|
|
373
|
+
reportDiagnostic(context.program, {
|
|
374
|
+
code: "client-file-not-found",
|
|
375
|
+
format: {
|
|
376
|
+
filePath: clientFilePath
|
|
377
|
+
},
|
|
378
|
+
target: NoTarget
|
|
379
|
+
});
|
|
380
|
+
return; // Skip exporting this client but continue with others
|
|
369
381
|
}
|
|
370
382
|
|
|
371
383
|
exportClassicalClient(client, subClientIndexFile, subfolder ?? "", true);
|
|
@@ -46,10 +46,7 @@ import path from "path";
|
|
|
46
46
|
import { refkey } from "../framework/refkey.js";
|
|
47
47
|
import { useContext } from "../contextManager.js";
|
|
48
48
|
import { isMetadata, isOrExtendsHttpFile } from "@typespec/http";
|
|
49
|
-
import {
|
|
50
|
-
isAzureCoreErrorType,
|
|
51
|
-
isAzureCoreLroType
|
|
52
|
-
} from "../utils/modelUtils.js";
|
|
49
|
+
import { isAzureCoreErrorType } from "../utils/modelUtils.js";
|
|
53
50
|
import { isExtensibleEnum } from "./type-expressions/get-enum-expression.js";
|
|
54
51
|
import {
|
|
55
52
|
getAllDiscriminatedValues,
|
|
@@ -109,9 +106,6 @@ export function emitTypes(
|
|
|
109
106
|
if (!isGenerableType(type)) {
|
|
110
107
|
continue;
|
|
111
108
|
}
|
|
112
|
-
if (isAzureCoreLroType(type.__raw)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
109
|
|
|
116
110
|
const namespaces = getModelNamespaces(context, type);
|
|
117
111
|
const filepath = getModelsPath(sourceRoot, namespaces);
|
|
@@ -793,7 +787,14 @@ function visitClientMethod(
|
|
|
793
787
|
visitOperation(context, method.operation);
|
|
794
788
|
break;
|
|
795
789
|
default:
|
|
796
|
-
|
|
790
|
+
reportDiagnostic(context.program, {
|
|
791
|
+
code: "unknown-sdk-method-kind",
|
|
792
|
+
format: {
|
|
793
|
+
methodKind: (method as any).kind
|
|
794
|
+
},
|
|
795
|
+
target: NoTarget
|
|
796
|
+
});
|
|
797
|
+
return; // Skip processing this method but continue with others
|
|
797
798
|
}
|
|
798
799
|
}
|
|
799
800
|
|
|
@@ -425,6 +425,12 @@ function getParameterValue(value: SdkExampleValue): string {
|
|
|
425
425
|
case "utcDateTime":
|
|
426
426
|
retValue = `new Date("${value.value}")`;
|
|
427
427
|
break;
|
|
428
|
+
case "bytes": {
|
|
429
|
+
const encode = value.type.encode ?? "base64";
|
|
430
|
+
// TODO: add check for un-supported encode
|
|
431
|
+
retValue = `Buffer.from("${value.value}", "${encode}")`;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
428
434
|
default:
|
|
429
435
|
retValue = `"${value.value
|
|
430
436
|
?.toString()
|
|
@@ -454,11 +460,9 @@ function getParameterValue(value: SdkExampleValue): string {
|
|
|
454
460
|
const additionalPropertiesValue =
|
|
455
461
|
value.kind === "model" ? (value.additionalPropertiesValue ?? {}) : {};
|
|
456
462
|
for (const propName in {
|
|
457
|
-
...value.value
|
|
458
|
-
...additionalPropertiesValue
|
|
463
|
+
...value.value
|
|
459
464
|
}) {
|
|
460
|
-
const propValue =
|
|
461
|
-
value.value[propName] ?? additionalPropertiesValue[propName];
|
|
465
|
+
const propValue = value.value[propName];
|
|
462
466
|
if (propValue === undefined || propValue === null) {
|
|
463
467
|
continue;
|
|
464
468
|
}
|
|
@@ -467,6 +471,27 @@ function getParameterValue(value: SdkExampleValue): string {
|
|
|
467
471
|
getParameterValue(propValue);
|
|
468
472
|
values.push(propRetValue);
|
|
469
473
|
}
|
|
474
|
+
const additionalBags = [];
|
|
475
|
+
for (const propName in {
|
|
476
|
+
...additionalPropertiesValue
|
|
477
|
+
}) {
|
|
478
|
+
const propValue = additionalPropertiesValue[propName];
|
|
479
|
+
if (propValue === undefined || propValue === null) {
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const propRetValue =
|
|
483
|
+
`"${mapper.get(propName) ?? propName}": ` +
|
|
484
|
+
getParameterValue(propValue);
|
|
485
|
+
additionalBags.push(propRetValue);
|
|
486
|
+
}
|
|
487
|
+
if (additionalBags.length > 0) {
|
|
488
|
+
const name = mapper.get("additionalProperties")
|
|
489
|
+
? "additionalPropertiesBag"
|
|
490
|
+
: "additionalProperties";
|
|
491
|
+
values.push(`"${name}": {
|
|
492
|
+
${additionalBags.join(", ")}
|
|
493
|
+
}`);
|
|
494
|
+
}
|
|
470
495
|
|
|
471
496
|
retValue = `{${values.join(", ")}}`;
|
|
472
497
|
break;
|
|
@@ -850,7 +850,17 @@ export function getParameterMap(
|
|
|
850
850
|
return getRequired(context, param);
|
|
851
851
|
}
|
|
852
852
|
|
|
853
|
-
|
|
853
|
+
reportDiagnostic(context.program, {
|
|
854
|
+
code: "unsupported-parameter-type",
|
|
855
|
+
format: {
|
|
856
|
+
paramName: param.name,
|
|
857
|
+
paramKind: param.kind
|
|
858
|
+
},
|
|
859
|
+
target: param.__raw || NoTarget
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// Return a fallback value to allow the emitter to continue
|
|
863
|
+
return `"${param.name}": undefined`;
|
|
854
864
|
}
|
|
855
865
|
|
|
856
866
|
function getCollectionFormat(
|
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
getAdditionalPropertiesType,
|
|
33
33
|
getDirectSubtypes
|
|
34
34
|
} from "../helpers/typeHelpers.js";
|
|
35
|
+
import { reportDiagnostic } from "../../lib.js";
|
|
36
|
+
import { NoTarget } from "@typespec/compiler";
|
|
35
37
|
|
|
36
38
|
export function buildModelDeserializer(
|
|
37
39
|
context: SdkContext,
|
|
@@ -106,7 +108,11 @@ function buildPolymorphicDeserializer(
|
|
|
106
108
|
nameOnly = false
|
|
107
109
|
): FunctionDeclarationStructure | undefined | string {
|
|
108
110
|
if (!type.name) {
|
|
109
|
-
|
|
111
|
+
reportDiagnostic(context.program, {
|
|
112
|
+
code: "anonymous-type-deserialization",
|
|
113
|
+
target: type.__raw || NoTarget
|
|
114
|
+
});
|
|
115
|
+
return undefined; // Return undefined to skip this deserialization
|
|
110
116
|
}
|
|
111
117
|
const deserializeFunctionName = `${normalizeModelName(
|
|
112
118
|
context,
|
|
@@ -150,8 +156,12 @@ function buildPolymorphicDeserializer(
|
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
158
|
const union = subType?.discriminatedSubtypes ? "_Union" : "";
|
|
153
|
-
if (!subType || subType?.name) {
|
|
154
|
-
|
|
159
|
+
if (!subType || !subType?.name) {
|
|
160
|
+
reportDiagnostic(context.program, {
|
|
161
|
+
code: "anonymous-type-deserialization",
|
|
162
|
+
target: subType?.__raw || NoTarget
|
|
163
|
+
});
|
|
164
|
+
return; // Skip this subtype
|
|
155
165
|
}
|
|
156
166
|
|
|
157
167
|
const rawSubTypeName = `${subType.name}${union}`;
|
|
@@ -194,7 +204,11 @@ function buildDiscriminatedUnionDeserializer(
|
|
|
194
204
|
nameOnly = false
|
|
195
205
|
): FunctionDeclarationStructure | undefined | string {
|
|
196
206
|
if (!type.name) {
|
|
197
|
-
|
|
207
|
+
reportDiagnostic(context.program, {
|
|
208
|
+
code: "anonymous-type-deserialization",
|
|
209
|
+
target: type.__raw || NoTarget
|
|
210
|
+
});
|
|
211
|
+
return undefined; // Return undefined to skip this deserialization
|
|
198
212
|
}
|
|
199
213
|
const cases: string[] = [];
|
|
200
214
|
const output: string[] = [];
|
|
@@ -279,7 +293,11 @@ function buildUnionDeserializer(
|
|
|
279
293
|
nameOnly = false
|
|
280
294
|
): FunctionDeclarationStructure | string | undefined {
|
|
281
295
|
if (!type.name) {
|
|
282
|
-
|
|
296
|
+
reportDiagnostic(context.program, {
|
|
297
|
+
code: "anonymous-type-deserialization",
|
|
298
|
+
target: type.__raw || NoTarget
|
|
299
|
+
});
|
|
300
|
+
return ""; // Return empty string to continue processing
|
|
283
301
|
}
|
|
284
302
|
const deserializerFunctionName = `${normalizeModelName(
|
|
285
303
|
context,
|
|
@@ -314,7 +332,11 @@ function buildModelTypeDeserializer(
|
|
|
314
332
|
}
|
|
315
333
|
): FunctionDeclarationStructure | string | undefined {
|
|
316
334
|
if (!type.name) {
|
|
317
|
-
|
|
335
|
+
reportDiagnostic(context.program, {
|
|
336
|
+
code: "anonymous-type-deserialization",
|
|
337
|
+
target: type.__raw || NoTarget
|
|
338
|
+
});
|
|
339
|
+
return ""; // Return empty string to continue processing
|
|
318
340
|
}
|
|
319
341
|
const deserializerFunctionName = `${normalizeModelName(
|
|
320
342
|
context,
|
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
getAdditionalPropertiesType,
|
|
39
39
|
getDirectSubtypes
|
|
40
40
|
} from "../helpers/typeHelpers.js";
|
|
41
|
+
import { reportDiagnostic } from "../../lib.js";
|
|
42
|
+
import { NoTarget } from "@typespec/compiler";
|
|
41
43
|
|
|
42
44
|
export function buildModelSerializer(
|
|
43
45
|
context: SdkContext,
|
|
@@ -114,7 +116,11 @@ function buildPolymorphicSerializer(
|
|
|
114
116
|
nameOnly = false
|
|
115
117
|
): FunctionDeclarationStructure | undefined | string {
|
|
116
118
|
if (!type.name) {
|
|
117
|
-
|
|
119
|
+
reportDiagnostic(context.program, {
|
|
120
|
+
code: "anonymous-type-serialization",
|
|
121
|
+
target: type.__raw || NoTarget
|
|
122
|
+
});
|
|
123
|
+
return undefined; // Return undefined to skip this serialization
|
|
118
124
|
}
|
|
119
125
|
const serializeFunctionName = `${normalizeModelName(
|
|
120
126
|
context,
|
|
@@ -158,8 +164,12 @@ function buildPolymorphicSerializer(
|
|
|
158
164
|
return;
|
|
159
165
|
}
|
|
160
166
|
const union = subType?.discriminatedSubtypes ? "_Union" : "";
|
|
161
|
-
if (!subType || subType?.name) {
|
|
162
|
-
|
|
167
|
+
if (!subType || !subType?.name) {
|
|
168
|
+
reportDiagnostic(context.program, {
|
|
169
|
+
code: "anonymous-type-serialization",
|
|
170
|
+
target: subType?.__raw || NoTarget
|
|
171
|
+
});
|
|
172
|
+
return; // Skip this subtype
|
|
163
173
|
}
|
|
164
174
|
const rawSubTypeName = `${subType.name}${union}`;
|
|
165
175
|
const subTypeName = `${normalizeName(rawSubTypeName, NameType.Interface, true)}`;
|
|
@@ -201,7 +211,11 @@ function buildDiscriminatedUnionSerializer(
|
|
|
201
211
|
nameOnly = false
|
|
202
212
|
): FunctionDeclarationStructure | undefined | string {
|
|
203
213
|
if (!type.name) {
|
|
204
|
-
|
|
214
|
+
reportDiagnostic(context.program, {
|
|
215
|
+
code: "anonymous-type-serialization",
|
|
216
|
+
target: type.__raw || NoTarget
|
|
217
|
+
});
|
|
218
|
+
return undefined; // Return undefined to skip this serialization
|
|
205
219
|
}
|
|
206
220
|
const cases: string[] = [];
|
|
207
221
|
const output: string[] = [];
|
|
@@ -286,7 +300,11 @@ function buildUnionSerializer(
|
|
|
286
300
|
nameOnly = false
|
|
287
301
|
): FunctionDeclarationStructure | string {
|
|
288
302
|
if (!type.name) {
|
|
289
|
-
|
|
303
|
+
reportDiagnostic(context.program, {
|
|
304
|
+
code: "anonymous-type-serialization",
|
|
305
|
+
target: type.__raw || NoTarget
|
|
306
|
+
});
|
|
307
|
+
return ""; // Return empty string to continue processing
|
|
290
308
|
}
|
|
291
309
|
const serializerFunctionName = `${normalizeModelName(
|
|
292
310
|
context,
|
|
@@ -321,7 +339,11 @@ function buildModelTypeSerializer(
|
|
|
321
339
|
}
|
|
322
340
|
): FunctionDeclarationStructure | string {
|
|
323
341
|
if (!type.name) {
|
|
324
|
-
|
|
342
|
+
reportDiagnostic(context.program, {
|
|
343
|
+
code: "anonymous-type-deserialization",
|
|
344
|
+
target: type.__raw || NoTarget
|
|
345
|
+
});
|
|
346
|
+
return ""; // Return empty string to continue processing
|
|
325
347
|
}
|
|
326
348
|
const serializerFunctionName = `${normalizeModelName(
|
|
327
349
|
context,
|
|
@@ -75,7 +75,8 @@ export function getOperationApiVersion(
|
|
|
75
75
|
}
|
|
76
76
|
const params = route.parameters.parameters.filter(
|
|
77
77
|
(p) =>
|
|
78
|
-
(p.type === "query" || p.type === "path") &&
|
|
78
|
+
(p.type === "query" || p.type === "path") &&
|
|
79
|
+
isApiVersion(dpgContext, p.param)
|
|
79
80
|
);
|
|
80
81
|
params.map((p) => {
|
|
81
82
|
const type = getSchemaForType(dpgContext, p.param.type, {
|
|
@@ -167,7 +167,7 @@ function hasRequiredOptions(
|
|
|
167
167
|
|
|
168
168
|
const containsRequiredNonBodyParam = routeParameters.parameters
|
|
169
169
|
.filter((parameter) => ["query", "header"].includes(parameter.type))
|
|
170
|
-
.filter((parameter) => !isApiVersion(dpgContext, parameter))
|
|
170
|
+
.filter((parameter) => !isApiVersion(dpgContext, parameter.param))
|
|
171
171
|
.filter((parameter) => !!parameter.param)
|
|
172
172
|
.some((parameter) => parameter.param.optional === false);
|
|
173
173
|
return isRequiredBodyParam || containsRequiredNonBodyParam;
|
|
@@ -91,8 +91,6 @@ function extractRLCOptions(
|
|
|
91
91
|
emitterOptions["compatibility-query-multi-format"];
|
|
92
92
|
const typespecTitleMap = emitterOptions["typespec-title-map"];
|
|
93
93
|
const hasSubscriptionId = getSubscriptionId(dpgContext);
|
|
94
|
-
//TODO should remove this after finish the release tool test
|
|
95
|
-
const shouldUsePnpmDep = emitterOptions["should-use-pnpm-dep"];
|
|
96
94
|
|
|
97
95
|
return {
|
|
98
96
|
...credentialInfo,
|
|
@@ -124,9 +122,7 @@ function extractRLCOptions(
|
|
|
124
122
|
compatibilityQueryMultiFormat,
|
|
125
123
|
typespecTitleMap,
|
|
126
124
|
ignoreEnumMemberNameNormalize,
|
|
127
|
-
hasSubscriptionId
|
|
128
|
-
//TODO should remove this after finish the release tool test
|
|
129
|
-
shouldUsePnpmDep
|
|
125
|
+
hasSubscriptionId
|
|
130
126
|
};
|
|
131
127
|
}
|
|
132
128
|
|
package/src/utils/emitUtil.ts
CHANGED
|
@@ -5,10 +5,14 @@ import {
|
|
|
5
5
|
isAzurePackage,
|
|
6
6
|
RLCModel
|
|
7
7
|
} from "@azure-tools/rlc-common";
|
|
8
|
-
import { CompilerHost, Program } from "@typespec/compiler";
|
|
8
|
+
import { CompilerHost, Program, NoTarget } from "@typespec/compiler";
|
|
9
9
|
import { dirname, join } from "path";
|
|
10
10
|
import { format } from "prettier";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
prettierJSONOptions,
|
|
13
|
+
prettierTypeScriptOptions,
|
|
14
|
+
reportDiagnostic
|
|
15
|
+
} from "../lib.js";
|
|
12
16
|
|
|
13
17
|
export async function emitModels(rlcModels: RLCModel, program: Program) {
|
|
14
18
|
const schemaOutput = buildSchemaTypes(rlcModels);
|
|
@@ -78,8 +82,16 @@ async function emitFile(
|
|
|
78
82
|
isJson ? prettierJSONOptions : prettierTypeScriptOptions
|
|
79
83
|
);
|
|
80
84
|
} catch (e) {
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
reportDiagnostic(program, {
|
|
86
|
+
code: "file-formatting-error",
|
|
87
|
+
format: {
|
|
88
|
+
filePath: filePath,
|
|
89
|
+
error: String(e)
|
|
90
|
+
},
|
|
91
|
+
target: NoTarget
|
|
92
|
+
});
|
|
93
|
+
// Continue with unformatted content rather than crashing
|
|
94
|
+
console.error(`Failed to format file: ${filePath}`, e);
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
await host.mkdirp(dirname(filePath));
|
package/src/utils/modelUtils.ts
CHANGED
|
@@ -79,10 +79,7 @@ import {
|
|
|
79
79
|
getWireName,
|
|
80
80
|
isApiVersion
|
|
81
81
|
} from "@azure-tools/typespec-client-generator-core";
|
|
82
|
-
import {
|
|
83
|
-
getPagedResult,
|
|
84
|
-
getUnionAsEnum
|
|
85
|
-
} from "@azure-tools/typespec-azure-core";
|
|
82
|
+
import { getUnionAsEnum } from "@azure-tools/typespec-azure-core";
|
|
86
83
|
|
|
87
84
|
import { getModelNamespaceName } from "./namespaceUtils.js";
|
|
88
85
|
import { reportDiagnostic } from "../lib.js";
|
|
@@ -924,7 +921,7 @@ function getModelName(dpgContext: SdkContext, model: Model) {
|
|
|
924
921
|
// 4. check if this is a model with template arguments
|
|
925
922
|
let name = model.name;
|
|
926
923
|
if (model.templateMapper?.args) {
|
|
927
|
-
const isPage = getPagedResult(program, model);
|
|
924
|
+
// const isPage = getPagedResult(program, model);
|
|
928
925
|
const templateTypeNames = model.templateMapper.args
|
|
929
926
|
.map((arg) => (arg.entityKind === "Indeterminate" ? arg.type : arg))
|
|
930
927
|
.map((arg: any) => {
|
|
@@ -944,10 +941,7 @@ function getModelName(dpgContext: SdkContext, model: Model) {
|
|
|
944
941
|
})
|
|
945
942
|
.filter((arg) => arg !== "")
|
|
946
943
|
.join(" ");
|
|
947
|
-
name = normalizeName(
|
|
948
|
-
isPage ? `${templateTypeNames} List` : `${name} ${templateTypeNames}`,
|
|
949
|
-
NameType.Interface
|
|
950
|
-
);
|
|
944
|
+
name = normalizeName(`${name} ${templateTypeNames}`, NameType.Interface);
|
|
951
945
|
}
|
|
952
946
|
let fullNamespacePrefix = getModelNamespaceName(dpgContext, model.namespace!)
|
|
953
947
|
.map((nsName) => {
|
|
@@ -1714,14 +1708,6 @@ export function trimUsage(model: any) {
|
|
|
1714
1708
|
return ordered;
|
|
1715
1709
|
}
|
|
1716
1710
|
|
|
1717
|
-
export function buildCoreTypeInfo(program: Program, t?: Type) {
|
|
1718
|
-
return isAzureCoreErrorType(program, t)
|
|
1719
|
-
? "ErrorType"
|
|
1720
|
-
: isAzureCoreLroType(t)
|
|
1721
|
-
? "LroType"
|
|
1722
|
-
: undefined;
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
1711
|
export function isAzureCoreErrorType(program: Program, t?: Type): boolean {
|
|
1726
1712
|
if (!t || t.kind !== "Model") {
|
|
1727
1713
|
return false;
|
|
@@ -1737,26 +1723,6 @@ export function isAzureCoreErrorType(program: Program, t?: Type): boolean {
|
|
|
1737
1723
|
return isAzureCoreFoundationsNamespace(effective);
|
|
1738
1724
|
}
|
|
1739
1725
|
|
|
1740
|
-
// Check if the type in the Azure.Core.Foundations has an LRO type in core
|
|
1741
|
-
export function isAzureCoreLroType(t?: Type): boolean {
|
|
1742
|
-
if (
|
|
1743
|
-
!(
|
|
1744
|
-
((t?.kind === "Enum" || t?.kind === "Union") &&
|
|
1745
|
-
["operationstate"].includes((t.name ?? "").toLowerCase())) ||
|
|
1746
|
-
(t?.kind === "Model" &&
|
|
1747
|
-
["resourceoperationstatus", "operationstatus"].includes(
|
|
1748
|
-
t.name.toLowerCase()
|
|
1749
|
-
))
|
|
1750
|
-
)
|
|
1751
|
-
) {
|
|
1752
|
-
return false;
|
|
1753
|
-
}
|
|
1754
|
-
return (
|
|
1755
|
-
isAzureCoreFoundationsNamespace(t) ||
|
|
1756
|
-
isAzureCoreFoundationsNamespace(t, true)
|
|
1757
|
-
);
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
1726
|
function isAzureCoreFoundationsNamespace(
|
|
1761
1727
|
t?: Type,
|
|
1762
1728
|
skipFoundation: boolean = false
|