@azure-tools/typespec-ts 0.28.0 → 0.29.0-alpha.20240531.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 +12 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -18
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +14 -4
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +9 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +2 -0
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +3 -0
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +80 -83
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildLroFiles.d.ts +24 -0
- package/dist/src/modular/buildLroFiles.d.ts.map +1 -0
- package/dist/src/modular/buildLroFiles.js +399 -0
- package/dist/src/modular/buildLroFiles.js.map +1 -0
- package/dist/src/modular/buildOperations.d.ts +6 -0
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +64 -5
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildPagingFiles.js +3 -3
- package/dist/src/modular/buildPagingFiles.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts +0 -3
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +0 -399
- 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 +20 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +4 -3
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +2 -0
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +73 -11
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +5 -5
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +171 -55
- 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 -1
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/interfaces.d.ts +5 -0
- package/dist/src/modular/interfaces.d.ts.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +9 -1
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +1 -1
- package/dist/src/transform/transformParameters.js +2 -2
- 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/transformResponses.js +2 -2
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +23 -31
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +8 -1
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +12 -2
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +88 -49
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -18
- package/src/index.ts +36 -22
- package/src/lib.ts +10 -2
- package/src/modular/buildClassicalClient.ts +2 -0
- package/src/modular/buildClassicalOperationGroups.ts +4 -0
- package/src/modular/buildCodeModel.ts +100 -155
- package/src/modular/buildLroFiles.ts +433 -0
- package/src/modular/buildOperations.ts +91 -10
- package/src/modular/buildPagingFiles.ts +4 -4
- package/src/modular/buildProjectFiles.ts +0 -471
- package/src/modular/buildRootIndex.ts +49 -0
- package/src/modular/buildSubpathIndex.ts +4 -4
- package/src/modular/emitModels.ts +102 -15
- package/src/modular/helpers/operationHelpers.ts +207 -72
- package/src/modular/helpers/typeHelpers.ts +6 -2
- package/src/modular/interfaces.ts +6 -0
- package/src/modular/modularCodeModel.ts +10 -1
- package/src/transform/transformHelperFunctionDetails.ts +1 -1
- package/src/transform/transformParameters.ts +2 -2
- package/src/transform/transformPaths.ts +1 -1
- package/src/transform/transformResponses.ts +2 -2
- package/src/transform/transformSchemas.ts +22 -33
- package/src/transform/transfromRLCOptions.ts +10 -1
- package/src/utils/modelUtils.ts +107 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0-alpha.20240531.1",
|
|
4
4
|
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,40 +21,41 @@
|
|
|
21
21
|
"ts-node": "~10.9.1",
|
|
22
22
|
"typescript": "~5.4.5",
|
|
23
23
|
"prettier": "^3.1.0",
|
|
24
|
-
"@azure-tools/cadl-ranch-specs": "^0.
|
|
25
|
-
"@azure-tools/cadl-ranch-expect": "^0.13.
|
|
26
|
-
"@azure-tools/cadl-ranch": "^0.12.
|
|
24
|
+
"@azure-tools/cadl-ranch-specs": "^0.33.4",
|
|
25
|
+
"@azure-tools/cadl-ranch-expect": "^0.13.4",
|
|
26
|
+
"@azure-tools/cadl-ranch": "^0.12.8",
|
|
27
27
|
"chalk": "^4.0.0",
|
|
28
28
|
"@azure-rest/core-client": "^2.0.0",
|
|
29
29
|
"@azure/core-auth": "^1.6.0",
|
|
30
30
|
"cross-env": "^7.0.3",
|
|
31
31
|
"@azure/core-paging": "^1.5.0",
|
|
32
|
-
"@azure/core-lro": "
|
|
32
|
+
"@azure/core-lro": "3.0.0-beta.1",
|
|
33
33
|
"@azure/core-rest-pipeline": "^1.14.0",
|
|
34
|
+
"@azure/abort-controller": "^2.0.0",
|
|
34
35
|
"@azure/logger": "^1.0.4",
|
|
35
36
|
"@azure/core-util": "^1.4.0",
|
|
36
37
|
"eslint-plugin-require-extensions": "0.1.3",
|
|
37
38
|
"@typespec/ts-http-runtime": "1.0.0-alpha.20240314.2",
|
|
38
|
-
"@azure-tools/typespec-azure-core": ">=0.
|
|
39
|
-
"@azure-tools/typespec-client-generator-core": ">=0.
|
|
40
|
-
"@typespec/compiler": ">=0.
|
|
41
|
-
"@typespec/http": ">=0.
|
|
42
|
-
"@typespec/rest": ">=0.
|
|
43
|
-
"@typespec/versioning": ">=0.
|
|
39
|
+
"@azure-tools/typespec-azure-core": ">=0.42.0 <1.0.0",
|
|
40
|
+
"@azure-tools/typespec-client-generator-core": ">=0.42.2 <1.0.0",
|
|
41
|
+
"@typespec/compiler": ">=0.56.0 <1.0.0",
|
|
42
|
+
"@typespec/http": ">=0.56.0 <1.0.0",
|
|
43
|
+
"@typespec/rest": ">=0.56.0 <1.0.0",
|
|
44
|
+
"@typespec/versioning": ">=0.56.0 <1.0.0",
|
|
44
45
|
"npm-run-all": "~4.1.5"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"@azure-tools/typespec-azure-core": ">=0.
|
|
48
|
-
"@azure-tools/typespec-client-generator-core": ">=0.
|
|
49
|
-
"@typespec/compiler": ">=0.
|
|
50
|
-
"@typespec/http": ">=0.
|
|
51
|
-
"@typespec/rest": ">=0.
|
|
52
|
-
"@typespec/versioning": ">=0.
|
|
48
|
+
"@azure-tools/typespec-azure-core": ">=0.42.0 <1.0.0",
|
|
49
|
+
"@azure-tools/typespec-client-generator-core": ">=0.42.2 <1.0.0",
|
|
50
|
+
"@typespec/compiler": ">=0.56.0 <1.0.0",
|
|
51
|
+
"@typespec/http": ">=0.56.0 <1.0.0",
|
|
52
|
+
"@typespec/rest": ">=0.56.0 <1.0.0",
|
|
53
|
+
"@typespec/versioning": ">=0.56.0 <1.0.0"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
56
|
"prettier": "^3.1.0",
|
|
56
57
|
"tslib": "^2.3.1",
|
|
57
|
-
"@azure-tools/rlc-common": "^0.
|
|
58
|
+
"@azure-tools/rlc-common": "^0.29.0",
|
|
58
59
|
"ts-morph": "^15.1.0",
|
|
59
60
|
"fs-extra": "^11.1.0"
|
|
60
61
|
},
|
package/src/index.ts
CHANGED
|
@@ -62,6 +62,10 @@ import {
|
|
|
62
62
|
} from "./modular/buildPagingFiles.js";
|
|
63
63
|
import { EmitterOptions } from "./lib.js";
|
|
64
64
|
import { getModuleExports } from "./modular/buildProjectFiles.js";
|
|
65
|
+
import {
|
|
66
|
+
buildGetPollerHelper,
|
|
67
|
+
buildRestorePollerHelper
|
|
68
|
+
} from "./modular/buildLroFiles.js";
|
|
65
69
|
|
|
66
70
|
export * from "./lib.js";
|
|
67
71
|
|
|
@@ -124,28 +128,6 @@ export async function $onEmit(context: EmitContext) {
|
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
function createContextWithDefaultOptions(
|
|
128
|
-
context: EmitContext<Record<string, any>>
|
|
129
|
-
): SdkContext {
|
|
130
|
-
const tcgcSettings = {
|
|
131
|
-
"generate-protocol-methods": true,
|
|
132
|
-
"generate-convenience-methods": true,
|
|
133
|
-
"flatten-union-as-enum": false,
|
|
134
|
-
emitters: [
|
|
135
|
-
{
|
|
136
|
-
main: "@azure-tools/typespec-ts",
|
|
137
|
-
metadata: { name: "@azure-tools/typespec-ts" }
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
};
|
|
141
|
-
context.options = {
|
|
142
|
-
...context.options,
|
|
143
|
-
...tcgcSettings
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return createSdkContext(context) as SdkContext;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
131
|
async function clearSrcFolder() {
|
|
150
132
|
await fsextra.emptyDir(
|
|
151
133
|
dpgContext.generationPathDetail?.modularSourcesDir ??
|
|
@@ -216,6 +198,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
216
198
|
const hasClientUnexpectedHelper =
|
|
217
199
|
needUnexpectedHelper.get(subClient.rlcClientName) ?? false;
|
|
218
200
|
buildSerializeUtils(modularCodeModel);
|
|
201
|
+
// build paging files
|
|
219
202
|
buildPagingTypes(subClient, modularCodeModel);
|
|
220
203
|
buildModularPagingHelpers(
|
|
221
204
|
subClient,
|
|
@@ -223,6 +206,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
223
206
|
hasClientUnexpectedHelper,
|
|
224
207
|
isMultiClients
|
|
225
208
|
);
|
|
209
|
+
// build operation files
|
|
226
210
|
buildOperationFiles(
|
|
227
211
|
subClient,
|
|
228
212
|
dpgContext,
|
|
@@ -231,6 +215,14 @@ export async function $onEmit(context: EmitContext) {
|
|
|
231
215
|
);
|
|
232
216
|
buildClientContext(subClient, dpgContext, modularCodeModel);
|
|
233
217
|
buildSubpathIndexFile(subClient, modularCodeModel, "models");
|
|
218
|
+
// build lro files
|
|
219
|
+
buildGetPollerHelper(
|
|
220
|
+
modularCodeModel,
|
|
221
|
+
subClient,
|
|
222
|
+
hasClientUnexpectedHelper,
|
|
223
|
+
isMultiClients
|
|
224
|
+
);
|
|
225
|
+
buildRestorePollerHelper(modularCodeModel, subClient);
|
|
234
226
|
if (dpgContext.rlcOptions?.hierarchyClient) {
|
|
235
227
|
buildSubpathIndexFile(subClient, modularCodeModel, "api");
|
|
236
228
|
} else {
|
|
@@ -333,3 +325,25 @@ export async function $onEmit(context: EmitContext) {
|
|
|
333
325
|
}
|
|
334
326
|
}
|
|
335
327
|
}
|
|
328
|
+
|
|
329
|
+
export function createContextWithDefaultOptions(
|
|
330
|
+
context: EmitContext<Record<string, any>>
|
|
331
|
+
): SdkContext {
|
|
332
|
+
const tcgcSettings = {
|
|
333
|
+
"generate-protocol-methods": true,
|
|
334
|
+
"generate-convenience-methods": true,
|
|
335
|
+
"flatten-union-as-enum": false,
|
|
336
|
+
emitters: [
|
|
337
|
+
{
|
|
338
|
+
main: "@azure-tools/typespec-ts",
|
|
339
|
+
metadata: { name: "@azure-tools/typespec-ts" }
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
};
|
|
343
|
+
context.options = {
|
|
344
|
+
...context.options,
|
|
345
|
+
...tcgcSettings
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
return createSdkContext(context) as SdkContext;
|
|
349
|
+
}
|
package/src/lib.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Options } from "prettier";
|
|
|
11
11
|
|
|
12
12
|
export interface EmitterOptions extends RLCOptions {
|
|
13
13
|
branded?: boolean;
|
|
14
|
+
compatibilityMode?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
@@ -88,7 +89,8 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
88
89
|
nullable: true,
|
|
89
90
|
enum: ["esm", "cjs"],
|
|
90
91
|
default: "esm"
|
|
91
|
-
}
|
|
92
|
+
},
|
|
93
|
+
compatibilityMode: { type: "boolean", nullable: true }
|
|
92
94
|
},
|
|
93
95
|
required: []
|
|
94
96
|
};
|
|
@@ -150,7 +152,7 @@ const libDef = {
|
|
|
150
152
|
"invalid-schema": {
|
|
151
153
|
severity: "error",
|
|
152
154
|
messages: {
|
|
153
|
-
default: paramMessage`Couldn't get schema for type ${"type"}`
|
|
155
|
+
default: paramMessage`Couldn't get schema for type ${"type"} with property ${"property"}`
|
|
154
156
|
}
|
|
155
157
|
},
|
|
156
158
|
"union-null": {
|
|
@@ -221,6 +223,12 @@ const libDef = {
|
|
|
221
223
|
messages: {
|
|
222
224
|
default: paramMessage`Please note the header ${"type"} is not serializable.`
|
|
223
225
|
}
|
|
226
|
+
},
|
|
227
|
+
"compatible-additional-properties": {
|
|
228
|
+
severity: "warning",
|
|
229
|
+
messages: {
|
|
230
|
+
default: paramMessage`Please note that only compatible additional properties is supported for now. You can enable compatibilityMode to generate compatible additional properties for the model - ${"modelName"}.`
|
|
231
|
+
}
|
|
224
232
|
}
|
|
225
233
|
},
|
|
226
234
|
emitter: {
|
|
@@ -21,6 +21,7 @@ import { Imports as RuntimeImports } from "@azure-tools/rlc-common";
|
|
|
21
21
|
import { NameType, normalizeName } from "@azure-tools/rlc-common";
|
|
22
22
|
import { getOperationFunction } from "./helpers/operationHelpers.js";
|
|
23
23
|
import { getImportSpecifier } from "@azure-tools/rlc-common";
|
|
24
|
+
import { importLroCoreDependencies } from "./buildLroFiles.js";
|
|
24
25
|
|
|
25
26
|
export function buildClassicalClient(
|
|
26
27
|
client: Client,
|
|
@@ -89,6 +90,7 @@ export function buildClassicalClient(
|
|
|
89
90
|
.join(",")})`
|
|
90
91
|
]);
|
|
91
92
|
constructor.addStatements(`this.pipeline = this._client.pipeline`);
|
|
93
|
+
importLroCoreDependencies(clientFile);
|
|
92
94
|
importCredential(codeModel.runtimeImports, clientFile);
|
|
93
95
|
importPipeline(codeModel.runtimeImports, clientFile);
|
|
94
96
|
importAllModels(clientFile, srcPath, subfolder);
|
|
@@ -8,6 +8,7 @@ import { getClassicalOperation } from "./helpers/classicalOperationHelpers.js";
|
|
|
8
8
|
import { getClassicalLayerPrefix } from "./helpers/namingHelpers.js";
|
|
9
9
|
import { SourceFile } from "ts-morph";
|
|
10
10
|
import { importModels, importPagingDependencies } from "./buildOperations.js";
|
|
11
|
+
import { importLroCoreDependencies } from "./buildLroFiles.js";
|
|
11
12
|
|
|
12
13
|
export function buildClassicOperationFiles(
|
|
13
14
|
codeModel: ModularCodeModel,
|
|
@@ -60,6 +61,7 @@ export function buildClassicOperationFiles(
|
|
|
60
61
|
subfolder,
|
|
61
62
|
operationGroup.namespaceHierarchies.length
|
|
62
63
|
);
|
|
64
|
+
importLroCoreDependencies(classicFile);
|
|
63
65
|
classicFile.fixMissingImports();
|
|
64
66
|
classicFile.fixUnusedIdentifiers();
|
|
65
67
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
@@ -107,6 +109,8 @@ export function buildClassicOperationFiles(
|
|
|
107
109
|
subfolder,
|
|
108
110
|
operationGroup.namespaceHierarchies.length
|
|
109
111
|
);
|
|
112
|
+
importLroCoreDependencies(classicFile);
|
|
113
|
+
|
|
110
114
|
classicFile.fixMissingImports();
|
|
111
115
|
classicFile.fixUnusedIdentifiers();
|
|
112
116
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getPagedResult,
|
|
3
|
+
getLroMetadata
|
|
4
|
+
} from "@azure-tools/typespec-azure-core";
|
|
2
5
|
import {
|
|
3
6
|
Enum,
|
|
4
7
|
getDoc,
|
|
@@ -17,7 +20,6 @@ import {
|
|
|
17
20
|
ModelProperty,
|
|
18
21
|
Namespace,
|
|
19
22
|
Program,
|
|
20
|
-
getEffectiveModelType,
|
|
21
23
|
getDiscriminator,
|
|
22
24
|
Operation,
|
|
23
25
|
Scalar,
|
|
@@ -34,20 +36,17 @@ import {
|
|
|
34
36
|
isNullType,
|
|
35
37
|
getEncode,
|
|
36
38
|
isTemplateDeclarationOrInstance,
|
|
37
|
-
UsageFlags
|
|
39
|
+
UsageFlags,
|
|
40
|
+
isVoidType
|
|
38
41
|
} from "@typespec/compiler";
|
|
39
42
|
import {
|
|
40
43
|
getAuthentication,
|
|
41
|
-
getHeaderFieldName,
|
|
42
|
-
getPathParamName,
|
|
43
|
-
getQueryParamName,
|
|
44
44
|
getServers,
|
|
45
45
|
HttpAuth,
|
|
46
46
|
HttpOperationParameter,
|
|
47
47
|
HttpOperationResponse,
|
|
48
48
|
HttpOperationResponseContent,
|
|
49
49
|
HttpServer,
|
|
50
|
-
isStatusCode,
|
|
51
50
|
HttpOperation,
|
|
52
51
|
getHttpOperation,
|
|
53
52
|
isSharedRoute
|
|
@@ -81,9 +80,12 @@ import {
|
|
|
81
80
|
Property
|
|
82
81
|
} from "./modularCodeModel.js";
|
|
83
82
|
import {
|
|
83
|
+
buildCoreTypeInfo,
|
|
84
84
|
getBodyType,
|
|
85
85
|
getDefaultApiVersionString,
|
|
86
|
-
|
|
86
|
+
getEffectiveSchemaType,
|
|
87
|
+
isAzureCoreErrorType,
|
|
88
|
+
isSchemaProperty
|
|
87
89
|
} from "../utils/modelUtils.js";
|
|
88
90
|
import { camelToSnakeCase, toCamelCase } from "../utils/casingUtils.js";
|
|
89
91
|
import {
|
|
@@ -107,6 +109,7 @@ import { buildRuntimeImports } from "@azure-tools/rlc-common";
|
|
|
107
109
|
import { getModelNamespaceName } from "../utils/namespaceUtils.js";
|
|
108
110
|
import { reportDiagnostic } from "../lib.js";
|
|
109
111
|
import { getType as getTypeName } from "./helpers/typeHelpers.js";
|
|
112
|
+
import { isModelWithAdditionalProperties } from "./emitModels.js";
|
|
110
113
|
|
|
111
114
|
interface HttpServerParameter {
|
|
112
115
|
type: "endpointPath";
|
|
@@ -235,47 +238,6 @@ function handleDiscriminator(
|
|
|
235
238
|
return undefined;
|
|
236
239
|
}
|
|
237
240
|
|
|
238
|
-
function isSchemaProperty(program: Program, property: ModelProperty): boolean {
|
|
239
|
-
const headerInfo = getHeaderFieldName(program, property);
|
|
240
|
-
const queryInfo = getQueryParamName(program, property);
|
|
241
|
-
const pathInfo = getPathParamName(program, property);
|
|
242
|
-
const statusCodeinfo = isStatusCode(program, property);
|
|
243
|
-
return !(headerInfo || queryInfo || pathInfo || statusCodeinfo);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function getEffectiveSchemaType(program: Program, type: Model | Union): Model {
|
|
247
|
-
function isSchemaProperty(property: ModelProperty): boolean {
|
|
248
|
-
const headerInfo = getHeaderFieldName(program, property);
|
|
249
|
-
const queryInfo = getQueryParamName(program, property);
|
|
250
|
-
const pathInfo = getPathParamName(program, property);
|
|
251
|
-
const statusCodeinfo = isStatusCode(program, property);
|
|
252
|
-
return !(headerInfo || queryInfo || pathInfo || statusCodeinfo);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// If type is an anonymous model, tries to find a named model that has the same properties
|
|
256
|
-
let effective: Model | undefined = undefined;
|
|
257
|
-
if (type.kind === "Union") {
|
|
258
|
-
const nonNullOptions = [...type.variants.values()]
|
|
259
|
-
.map((x) => x.type)
|
|
260
|
-
.filter((t) => !isNullType(t));
|
|
261
|
-
if (
|
|
262
|
-
nonNullOptions.length === 1 &&
|
|
263
|
-
nonNullOptions[0]?.kind === "Model" &&
|
|
264
|
-
nonNullOptions[0]?.name === ""
|
|
265
|
-
) {
|
|
266
|
-
effective = getEffectiveModelType(program, nonNullOptions[0]);
|
|
267
|
-
}
|
|
268
|
-
return type as any;
|
|
269
|
-
} else if (type.name === "") {
|
|
270
|
-
effective = getEffectiveModelType(program, type, isSchemaProperty);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (effective?.name) {
|
|
274
|
-
return effective;
|
|
275
|
-
}
|
|
276
|
-
return type as Model;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
241
|
function processModelProperties(
|
|
280
242
|
context: SdkContext,
|
|
281
243
|
newValue: any,
|
|
@@ -381,6 +343,10 @@ function getType(
|
|
|
381
343
|
if (type.kind === "Model") {
|
|
382
344
|
// need to do properties after insertion to avoid infinite recursion
|
|
383
345
|
processModelProperties(context, newValue, type, options.usage!);
|
|
346
|
+
if (newValue.type === "dict") {
|
|
347
|
+
newValue = { ...emitModel(context, type, options.usage!), ...newValue };
|
|
348
|
+
typesMap.set(effectiveModel, newValue);
|
|
349
|
+
}
|
|
384
350
|
}
|
|
385
351
|
} else {
|
|
386
352
|
const key = JSON.stringify(newValue);
|
|
@@ -391,7 +357,19 @@ function getType(
|
|
|
391
357
|
simpleTypesMap.set(key, newValue);
|
|
392
358
|
}
|
|
393
359
|
}
|
|
394
|
-
|
|
360
|
+
if (
|
|
361
|
+
type.kind === "Model" &&
|
|
362
|
+
isModelWithAdditionalProperties(newValue) &&
|
|
363
|
+
!context.rlcOptions?.compatibilityMode
|
|
364
|
+
) {
|
|
365
|
+
reportDiagnostic(context.program, {
|
|
366
|
+
code: "compatible-additional-properties",
|
|
367
|
+
format: {
|
|
368
|
+
modelName: type?.name ?? ""
|
|
369
|
+
},
|
|
370
|
+
target: type
|
|
371
|
+
});
|
|
372
|
+
}
|
|
395
373
|
return newValue;
|
|
396
374
|
}
|
|
397
375
|
|
|
@@ -583,13 +561,14 @@ function emitResponseHeaders(
|
|
|
583
561
|
|
|
584
562
|
function emitResponse(
|
|
585
563
|
context: SdkContext,
|
|
564
|
+
operation: Operation,
|
|
586
565
|
response: HttpOperationResponse,
|
|
587
566
|
innerResponse: HttpOperationResponseContent
|
|
588
567
|
): Response {
|
|
589
568
|
let type = undefined;
|
|
590
569
|
if (
|
|
591
570
|
innerResponse.body?.type &&
|
|
592
|
-
!isAzureCoreErrorType(innerResponse.body?.type)
|
|
571
|
+
!isAzureCoreErrorType(context.program, innerResponse.body?.type)
|
|
593
572
|
) {
|
|
594
573
|
// temporary logic. It can be removed after compiler optimize the response
|
|
595
574
|
const candidate = [
|
|
@@ -604,10 +583,18 @@ function emitResponse(
|
|
|
604
583
|
) {
|
|
605
584
|
const modelType = getEffectiveSchemaType(context.program, originType);
|
|
606
585
|
type = getType(context, modelType, { usage: UsageFlags.Output });
|
|
586
|
+
} else if (isLroResponse()) {
|
|
587
|
+
const metadata = getLroMetadata(context.program, operation);
|
|
588
|
+
type =
|
|
589
|
+
metadata?.finalResult === "void" || metadata?.finalResult === undefined
|
|
590
|
+
? undefined
|
|
591
|
+
: getType(context, metadata.finalResult);
|
|
607
592
|
} else {
|
|
608
|
-
type =
|
|
609
|
-
|
|
610
|
-
|
|
593
|
+
type = isVoidType(innerResponse.body.type)
|
|
594
|
+
? undefined
|
|
595
|
+
: getType(context, innerResponse.body.type, {
|
|
596
|
+
usage: UsageFlags.Output
|
|
597
|
+
});
|
|
611
598
|
}
|
|
612
599
|
}
|
|
613
600
|
const statusCodes: (number | "default")[] = [];
|
|
@@ -630,6 +617,14 @@ function emitResponse(
|
|
|
630
617
|
)
|
|
631
618
|
: false
|
|
632
619
|
};
|
|
620
|
+
|
|
621
|
+
function isLroResponse() {
|
|
622
|
+
return (
|
|
623
|
+
typeof response.statusCodes === "number" &&
|
|
624
|
+
["200", "201", "202"]?.includes(`${response.statusCodes}`) &&
|
|
625
|
+
!!getLroMetadata(context.program, operation)
|
|
626
|
+
);
|
|
627
|
+
}
|
|
633
628
|
}
|
|
634
629
|
|
|
635
630
|
function emitOperation(
|
|
@@ -640,15 +635,16 @@ function emitOperation(
|
|
|
640
635
|
hierarchies: string[]
|
|
641
636
|
): HrlcOperation {
|
|
642
637
|
const isAzureFlavor = rlcModels.options?.flavor === "azure";
|
|
638
|
+
const emittedOperation = emitBasicOperation(
|
|
639
|
+
context,
|
|
640
|
+
operation,
|
|
641
|
+
operationGroupName,
|
|
642
|
+
rlcModels,
|
|
643
|
+
hierarchies
|
|
644
|
+
);
|
|
643
645
|
// Skip to extract paging and lro information for non-branded clients.
|
|
644
646
|
if (!isAzureFlavor) {
|
|
645
|
-
return
|
|
646
|
-
context,
|
|
647
|
-
operation,
|
|
648
|
-
operationGroupName,
|
|
649
|
-
rlcModels,
|
|
650
|
-
hierarchies
|
|
651
|
-
);
|
|
647
|
+
return emittedOperation;
|
|
652
648
|
}
|
|
653
649
|
const lro = isLongRunningOperation(
|
|
654
650
|
context.program,
|
|
@@ -673,51 +669,46 @@ function emitOperation(
|
|
|
673
669
|
});
|
|
674
670
|
}
|
|
675
671
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
)
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
rlcModels,
|
|
690
|
-
hierarchies
|
|
691
|
-
);
|
|
692
|
-
} else if (lro) {
|
|
693
|
-
return emitLroOperation(
|
|
694
|
-
context,
|
|
695
|
-
operation,
|
|
696
|
-
operationGroupName,
|
|
697
|
-
rlcModels,
|
|
698
|
-
hierarchies
|
|
699
|
-
);
|
|
672
|
+
emitExtraInfoForOperation(emittedOperation);
|
|
673
|
+
return emittedOperation;
|
|
674
|
+
|
|
675
|
+
function emitExtraInfoForOperation(emittedOperation: HrlcOperation) {
|
|
676
|
+
if (lro) {
|
|
677
|
+
addLroInformation(context, operation, emittedOperation);
|
|
678
|
+
}
|
|
679
|
+
if (paging) {
|
|
680
|
+
addPagingInformation(context, operation, emittedOperation);
|
|
681
|
+
}
|
|
682
|
+
if (lro && paging) {
|
|
683
|
+
emittedOperation["discriminator"] = "lropaging";
|
|
684
|
+
}
|
|
700
685
|
}
|
|
701
|
-
return emitBasicOperation(
|
|
702
|
-
context,
|
|
703
|
-
operation,
|
|
704
|
-
operationGroupName,
|
|
705
|
-
rlcModels,
|
|
706
|
-
hierarchies
|
|
707
|
-
);
|
|
708
686
|
}
|
|
709
687
|
|
|
710
|
-
function addLroInformation(
|
|
688
|
+
function addLroInformation(
|
|
689
|
+
context: SdkContext,
|
|
690
|
+
operation: Operation,
|
|
691
|
+
emittedOperation: HrlcOperation
|
|
692
|
+
) {
|
|
711
693
|
emittedOperation["discriminator"] = "lro";
|
|
694
|
+
const metadata = getLroMetadata(context.program, operation);
|
|
695
|
+
emittedOperation["lroMetadata"] = {
|
|
696
|
+
finalResult:
|
|
697
|
+
metadata?.finalResult === "void" || metadata?.finalResult === undefined
|
|
698
|
+
? undefined
|
|
699
|
+
: getType(context, metadata.finalResult),
|
|
700
|
+
finalStateVia: metadata?.finalStateVia,
|
|
701
|
+
finalResultPath: metadata?.finalResultPath
|
|
702
|
+
};
|
|
712
703
|
}
|
|
713
704
|
|
|
714
705
|
function addPagingInformation(
|
|
715
|
-
|
|
706
|
+
context: SdkContext,
|
|
716
707
|
operation: Operation,
|
|
717
708
|
emittedOperation: Record<string, any>
|
|
718
709
|
) {
|
|
719
710
|
emittedOperation["discriminator"] = "paging";
|
|
720
|
-
const pagedResult = getPagedResult(program, operation);
|
|
711
|
+
const pagedResult = getPagedResult(context.program, operation);
|
|
721
712
|
if (pagedResult === undefined) {
|
|
722
713
|
throw Error(
|
|
723
714
|
"Trying to add paging information, but not paging metadata for this operation"
|
|
@@ -727,62 +718,6 @@ function addPagingInformation(
|
|
|
727
718
|
emittedOperation["continuationTokenName"] = parseNextLinkName(pagedResult);
|
|
728
719
|
}
|
|
729
720
|
|
|
730
|
-
function emitLroPagingOperation(
|
|
731
|
-
context: SdkContext,
|
|
732
|
-
operation: Operation,
|
|
733
|
-
operationGroupName: string,
|
|
734
|
-
rlcModels: RLCModel,
|
|
735
|
-
hierarchies: string[]
|
|
736
|
-
): HrlcOperation {
|
|
737
|
-
const emittedOperation = emitBasicOperation(
|
|
738
|
-
context,
|
|
739
|
-
operation,
|
|
740
|
-
operationGroupName,
|
|
741
|
-
rlcModels,
|
|
742
|
-
hierarchies
|
|
743
|
-
);
|
|
744
|
-
addLroInformation(emittedOperation);
|
|
745
|
-
addPagingInformation(context.program, operation, emittedOperation);
|
|
746
|
-
emittedOperation["discriminator"] = "lropaging";
|
|
747
|
-
return emittedOperation;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
function emitLroOperation(
|
|
751
|
-
context: SdkContext,
|
|
752
|
-
operation: Operation,
|
|
753
|
-
operationGroupName: string,
|
|
754
|
-
rlcModels: RLCModel,
|
|
755
|
-
hierarchies: string[]
|
|
756
|
-
): HrlcOperation {
|
|
757
|
-
const emittedOperation = emitBasicOperation(
|
|
758
|
-
context,
|
|
759
|
-
operation,
|
|
760
|
-
operationGroupName,
|
|
761
|
-
rlcModels,
|
|
762
|
-
hierarchies
|
|
763
|
-
);
|
|
764
|
-
addLroInformation(emittedOperation);
|
|
765
|
-
return emittedOperation;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function emitPagingOperation(
|
|
769
|
-
context: SdkContext,
|
|
770
|
-
operation: Operation,
|
|
771
|
-
operationGroupName: string,
|
|
772
|
-
rlcModels: RLCModel,
|
|
773
|
-
hierarchies: string[]
|
|
774
|
-
): HrlcOperation {
|
|
775
|
-
const emittedOperation = emitBasicOperation(
|
|
776
|
-
context,
|
|
777
|
-
operation,
|
|
778
|
-
operationGroupName,
|
|
779
|
-
rlcModels,
|
|
780
|
-
hierarchies
|
|
781
|
-
);
|
|
782
|
-
addPagingInformation(context.program, operation, emittedOperation);
|
|
783
|
-
return emittedOperation;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
721
|
function emitBasicOperation(
|
|
787
722
|
context: SdkContext,
|
|
788
723
|
operation: Operation,
|
|
@@ -853,6 +788,7 @@ function emitBasicOperation(
|
|
|
853
788
|
for (const innerResponse of response.responses) {
|
|
854
789
|
const emittedResponse: Response = emitResponse(
|
|
855
790
|
context,
|
|
791
|
+
operation,
|
|
856
792
|
response,
|
|
857
793
|
innerResponse
|
|
858
794
|
);
|
|
@@ -868,7 +804,10 @@ function emitBasicOperation(
|
|
|
868
804
|
}
|
|
869
805
|
|
|
870
806
|
let bodyParameter: any | undefined;
|
|
871
|
-
if (
|
|
807
|
+
if (
|
|
808
|
+
httpOperation.parameters.body === undefined ||
|
|
809
|
+
isVoidType(httpOperation.parameters.body.type)
|
|
810
|
+
) {
|
|
872
811
|
bodyParameter = undefined;
|
|
873
812
|
} else {
|
|
874
813
|
bodyParameter = emitBodyParameter(context, httpOperation);
|
|
@@ -1080,7 +1019,7 @@ function emitModel(
|
|
|
1080
1019
|
? applyCasing(modelName, { casing: CASING })
|
|
1081
1020
|
: modelName,
|
|
1082
1021
|
base: modelName === "" ? "json" : "dpg",
|
|
1083
|
-
|
|
1022
|
+
coreTypeInfo: buildCoreTypeInfo(context.program, type),
|
|
1084
1023
|
usage
|
|
1085
1024
|
};
|
|
1086
1025
|
}
|
|
@@ -1116,7 +1055,8 @@ function emitEnum(context: SdkContext, type: Enum): Record<string, any> {
|
|
|
1116
1055
|
description: getDocStr(program, type),
|
|
1117
1056
|
valueType: { type: enumMemberType(type.members.values().next().value) },
|
|
1118
1057
|
values: enumValues,
|
|
1119
|
-
isFixed: true
|
|
1058
|
+
isFixed: true,
|
|
1059
|
+
coreTypeInfo: buildCoreTypeInfo(program, type)
|
|
1120
1060
|
};
|
|
1121
1061
|
}
|
|
1122
1062
|
|
|
@@ -1346,6 +1286,7 @@ function emitListOrDict(
|
|
|
1346
1286
|
if (name === "string") {
|
|
1347
1287
|
return {
|
|
1348
1288
|
type: "dict",
|
|
1289
|
+
name: type.name,
|
|
1349
1290
|
elementType: getType(context, type.indexer.value!, { usage })
|
|
1350
1291
|
};
|
|
1351
1292
|
} else if (name === "integer") {
|
|
@@ -1694,6 +1635,7 @@ function emitServerParams(
|
|
|
1694
1635
|
if (isApiVersion(context, serverParameter as any)) {
|
|
1695
1636
|
emittedParameter.isApiVersion = true;
|
|
1696
1637
|
serverApiVersionParam = emittedParameter;
|
|
1638
|
+
emittedParameter.isApiVersion = true;
|
|
1697
1639
|
}
|
|
1698
1640
|
params.push(emittedParameter);
|
|
1699
1641
|
}
|
|
@@ -1870,7 +1812,10 @@ export function emitCodeModel(
|
|
|
1870
1812
|
// Get types
|
|
1871
1813
|
const codeModel: ModularCodeModel = {
|
|
1872
1814
|
options: dpgContext.rlcOptions ?? {},
|
|
1873
|
-
modularOptions: {
|
|
1815
|
+
modularOptions: {
|
|
1816
|
+
sourceRoot: modularSourcesRoot,
|
|
1817
|
+
compatibilityMode: !!dpgContext.rlcOptions?.compatibilityMode
|
|
1818
|
+
},
|
|
1874
1819
|
namespace: clientNamespaceString,
|
|
1875
1820
|
subnamespaceToClients: {},
|
|
1876
1821
|
clients: [],
|