@azure-tools/typespec-ts 0.15.0 → 0.16.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 +10 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -17
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +3 -3
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +2 -3
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +26 -12
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +3 -3
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +5 -4
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +3 -2
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +141 -54
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +2 -2
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +15 -8
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +2 -2
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +4 -4
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +12 -5
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +2 -2
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +7 -4
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +3 -3
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +28 -18
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +1 -1
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +140 -77
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +2 -2
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +13 -7
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +11 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +3 -4
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +0 -10
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +7 -51
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformResponses.js +3 -4
- 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 +4 -8
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +3 -10
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +48 -9
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +2 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +83 -73
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +15 -1
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +82 -3
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -11
- package/src/index.ts +24 -51
- package/src/lib.ts +3 -3
- package/src/modular/buildClassicalClient.ts +29 -16
- package/src/modular/buildClientContext.ts +8 -9
- package/src/modular/buildCodeModel.ts +183 -60
- package/src/modular/buildOperations.ts +16 -11
- package/src/modular/buildProjectFiles.ts +2 -2
- package/src/modular/buildRootIndex.ts +19 -12
- package/src/modular/buildSubpathIndex.ts +10 -8
- package/src/modular/emitModels.ts +35 -24
- package/src/modular/helpers/clientHelpers.ts +1 -1
- package/src/modular/helpers/operationHelpers.ts +231 -118
- package/src/modular/helpers/typeHelpers.ts +14 -7
- package/src/modular/modularCodeModel.ts +11 -0
- package/src/transform/transformHelperFunctionDetails.ts +10 -4
- package/src/transform/transformParameters.ts +15 -57
- package/src/transform/transformResponses.ts +2 -4
- package/src/transform/transformSchemas.ts +5 -9
- package/src/transform/transformTelemetryInfo.ts +4 -18
- package/src/transform/transfromRLCOptions.ts +67 -9
- package/src/utils/modelUtils.ts +81 -72
- package/src/utils/operationUtil.ts +121 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "An experimental
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Jose Heredia <joheredi@microsoft.com>",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"mkdirp": "^2.1.2",
|
|
19
19
|
"eslint": "^8.9.0",
|
|
20
20
|
"mocha": "^9.2.2",
|
|
21
|
-
"rimraf": "^
|
|
21
|
+
"rimraf": "^5.0.0",
|
|
22
22
|
"ts-node": "^10.9.1",
|
|
23
23
|
"typescript": "~5.0.0",
|
|
24
24
|
"prettier": "~2.7.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"prettier": "^2.6.1",
|
|
48
48
|
"tslib": "^2.3.1",
|
|
49
|
-
"@azure-tools/rlc-common": "^0.
|
|
49
|
+
"@azure-tools/rlc-common": "^0.16.0",
|
|
50
50
|
"ts-morph": "^15.1.0",
|
|
51
51
|
"fs-extra": "^11.1.0"
|
|
52
52
|
},
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"homepage": "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts/",
|
|
70
70
|
"scripts": {
|
|
71
|
-
"clean": "rimraf ./dist ./
|
|
71
|
+
"clean": "rimraf ./dist ./typespec-output",
|
|
72
72
|
"build": "tsc -p .",
|
|
73
73
|
"test": "npm run unit-test && npm run integration-test-ci",
|
|
74
74
|
"lint": "eslint src --ext .ts --max-warnings=0",
|
|
@@ -84,15 +84,17 @@
|
|
|
84
84
|
"start-test-server:rlc": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-rlc.json",
|
|
85
85
|
"start-test-server:modular": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-modular.json",
|
|
86
86
|
"copy:typespec": "rm -rf temp && mkdirp -p temp && cp -r ./node_modules/@azure-tools/cadl-ranch-specs/http ./temp && cp -r ./test/integration/typespec/* ./temp/http",
|
|
87
|
-
"generate-and-run:rlc": "npm run generate-
|
|
88
|
-
"generate-and-run:modular": "npm run generate-
|
|
89
|
-
"generate-
|
|
90
|
-
"generate-
|
|
91
|
-
"generate-
|
|
87
|
+
"generate-and-run:rlc": "npm run generate-tsp-only:rlc && npm run integration-test:alone:rlc && npm run stop-test-server",
|
|
88
|
+
"generate-and-run:modular": "npm run generate-tsp-only:modular && npm run integration-test:alone:modular && npm run stop-test-server",
|
|
89
|
+
"generate-tsp-only": "npm run generate-tsp-only:rlc && npm run generate-tsp-only:modular",
|
|
90
|
+
"generate-tsp-only:rlc": "ts-node ./test/commands/gen-cadl-ranch.ts --tag=rlc",
|
|
91
|
+
"generate-tsp-only:modular": "ts-node ./test/commands/gen-cadl-ranch.ts --tag=modular",
|
|
92
92
|
"integration-test:alone": "npm run integration-test:alone:rlc && npm run integration-test:alone:modular",
|
|
93
93
|
"integration-test:alone:rlc": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 4000 ./test/integration/*.spec.ts",
|
|
94
94
|
"integration-test:alone:modular": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 4000 ./test/modularIntegration/*.spec.ts",
|
|
95
95
|
"stop-test-server": "npx cadl-ranch server stop",
|
|
96
|
-
"unit-test": "
|
|
96
|
+
"unit-test": "npm run unit-test:rlc && npm run unit-test:modular",
|
|
97
|
+
"unit-test:rlc": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --timeout 4000 './test/unit/**/*.spec.ts'",
|
|
98
|
+
"unit-test:modular": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --no-timeout './test/modularUnit/**/*.spec.ts'"
|
|
97
99
|
}
|
|
98
100
|
}
|
package/src/index.ts
CHANGED
|
@@ -28,8 +28,6 @@ import {
|
|
|
28
28
|
buildSerializeHelper,
|
|
29
29
|
buildLogger,
|
|
30
30
|
RLCOptions,
|
|
31
|
-
normalizeName,
|
|
32
|
-
NameType,
|
|
33
31
|
hasUnexpectedHelper,
|
|
34
32
|
RLCModel
|
|
35
33
|
} from "@azure-tools/rlc-common";
|
|
@@ -53,6 +51,7 @@ import { join } from "path";
|
|
|
53
51
|
import { GenerationDirDetail, SdkContext } from "./utils/interfaces.js";
|
|
54
52
|
import { transformRLCOptions } from "./transform/transfromRLCOptions.js";
|
|
55
53
|
import { ModularCodeModel } from "./modular/modularCodeModel.js";
|
|
54
|
+
import { getClientName } from "@azure-tools/rlc-common";
|
|
56
55
|
|
|
57
56
|
export * from "./lib.js";
|
|
58
57
|
|
|
@@ -121,7 +120,10 @@ export async function $onEmit(context: EmitContext) {
|
|
|
121
120
|
const rlcModels = await transformRLCModel(client, dpgContext);
|
|
122
121
|
rlcCodeModels.push(rlcModels);
|
|
123
122
|
serviceNameToRlcModelsMap.set(client.service.name, rlcModels);
|
|
124
|
-
needUnexpectedHelper.set(
|
|
123
|
+
needUnexpectedHelper.set(
|
|
124
|
+
getClientName(rlcModels),
|
|
125
|
+
hasUnexpectedHelper(rlcModels)
|
|
126
|
+
);
|
|
125
127
|
|
|
126
128
|
await emitModels(rlcModels, program);
|
|
127
129
|
await emitContentByBuilder(program, buildClientDefinitions, rlcModels);
|
|
@@ -144,9 +146,15 @@ export async function $onEmit(context: EmitContext) {
|
|
|
144
146
|
const modularSourcesRoot =
|
|
145
147
|
dpgContext.generationPathDetail?.modularSourcesDir ?? "src";
|
|
146
148
|
const project = new Project();
|
|
147
|
-
modularCodeModel = emitCodeModel(
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
modularCodeModel = emitCodeModel(
|
|
150
|
+
dpgContext,
|
|
151
|
+
serviceNameToRlcModelsMap,
|
|
152
|
+
modularSourcesRoot,
|
|
153
|
+
project,
|
|
154
|
+
{
|
|
155
|
+
casing: "camel"
|
|
156
|
+
}
|
|
157
|
+
);
|
|
150
158
|
const rootIndexFile = project.createSourceFile(
|
|
151
159
|
`${modularSourcesRoot}/index.ts`,
|
|
152
160
|
"",
|
|
@@ -155,59 +163,24 @@ export async function $onEmit(context: EmitContext) {
|
|
|
155
163
|
}
|
|
156
164
|
);
|
|
157
165
|
for (const subClient of modularCodeModel.clients) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
subfolder = normalizeName(
|
|
161
|
-
subClient.name.replace("Client", ""),
|
|
162
|
-
NameType.File
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
buildModels(modularCodeModel, project, modularSourcesRoot, subfolder);
|
|
167
|
-
buildModelsOptions(subClient, project, modularSourcesRoot, subfolder);
|
|
166
|
+
buildModels(modularCodeModel, subClient);
|
|
167
|
+
buildModelsOptions(modularCodeModel, subClient);
|
|
168
168
|
const hasClientUnexpectedHelper =
|
|
169
|
-
needUnexpectedHelper.get(
|
|
170
|
-
subClient.rlcClientName.replace("Context", "Client")
|
|
171
|
-
) ?? false;
|
|
169
|
+
needUnexpectedHelper.get(subClient.rlcClientName) ?? false;
|
|
172
170
|
buildOperationFiles(
|
|
173
171
|
dpgContext,
|
|
172
|
+
modularCodeModel,
|
|
174
173
|
subClient,
|
|
175
|
-
project,
|
|
176
|
-
modularSourcesRoot,
|
|
177
|
-
subfolder,
|
|
178
174
|
hasClientUnexpectedHelper
|
|
179
175
|
);
|
|
180
|
-
buildClientContext(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
modularSourcesRoot,
|
|
185
|
-
subfolder
|
|
186
|
-
);
|
|
187
|
-
buildSubpathIndexFile(project, modularSourcesRoot, "models", subfolder);
|
|
188
|
-
buildSubpathIndexFile(project, modularSourcesRoot, "api", subfolder);
|
|
189
|
-
buildClassicalClient(
|
|
190
|
-
dpgContext,
|
|
191
|
-
subClient,
|
|
192
|
-
project,
|
|
193
|
-
modularSourcesRoot,
|
|
194
|
-
subfolder
|
|
195
|
-
);
|
|
176
|
+
buildClientContext(dpgContext, modularCodeModel, subClient);
|
|
177
|
+
buildSubpathIndexFile(modularCodeModel, subClient, "models");
|
|
178
|
+
buildSubpathIndexFile(modularCodeModel, subClient, "api");
|
|
179
|
+
buildClassicalClient(dpgContext, modularCodeModel, subClient);
|
|
196
180
|
if (modularCodeModel.clients.length > 1) {
|
|
197
|
-
buildSubClientIndexFile(
|
|
198
|
-
subClient,
|
|
199
|
-
project,
|
|
200
|
-
modularSourcesRoot,
|
|
201
|
-
subfolder
|
|
202
|
-
);
|
|
181
|
+
buildSubClientIndexFile(modularCodeModel, subClient);
|
|
203
182
|
}
|
|
204
|
-
buildRootIndex(
|
|
205
|
-
subClient,
|
|
206
|
-
project,
|
|
207
|
-
rootIndexFile,
|
|
208
|
-
modularSourcesRoot,
|
|
209
|
-
subfolder
|
|
210
|
-
);
|
|
183
|
+
buildRootIndex(modularCodeModel, subClient, rootIndexFile);
|
|
211
184
|
}
|
|
212
185
|
|
|
213
186
|
removeUnusedInterfaces(project);
|
package/src/lib.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
paramMessage,
|
|
6
|
-
|
|
6
|
+
createTypeSpecLibrary,
|
|
7
7
|
JSONSchemaType
|
|
8
8
|
} from "@typespec/compiler";
|
|
9
9
|
import { RLCOptions } from "@azure-tools/rlc-common";
|
|
@@ -49,7 +49,7 @@ export const RLCOptionsSchema: JSONSchemaType<RLCOptions> = {
|
|
|
49
49
|
generateSample: { type: "boolean", nullable: true },
|
|
50
50
|
azureSdkForJs: { type: "boolean", nullable: true },
|
|
51
51
|
azureOutputDirectory: { type: "string", nullable: true },
|
|
52
|
-
|
|
52
|
+
isTypeSpecTest: { type: "boolean", nullable: true },
|
|
53
53
|
title: { type: "string", nullable: true },
|
|
54
54
|
dependencyInfo: {
|
|
55
55
|
type: "object",
|
|
@@ -189,7 +189,7 @@ const libDef = {
|
|
|
189
189
|
}
|
|
190
190
|
} as const;
|
|
191
191
|
|
|
192
|
-
export const $lib =
|
|
192
|
+
export const $lib = createTypeSpecLibrary(libDef);
|
|
193
193
|
export const { reportDiagnostic } = $lib;
|
|
194
194
|
|
|
195
195
|
export const prettierTypeScriptOptions: Options = {
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
FunctionDeclarationStructure,
|
|
4
4
|
MethodDeclarationStructure,
|
|
5
5
|
OptionalKind,
|
|
6
|
-
Project,
|
|
7
6
|
Scope,
|
|
8
7
|
SourceFile,
|
|
9
8
|
StructureKind
|
|
@@ -12,24 +11,24 @@ import { toCamelCase } from "../utils/casingUtils.js";
|
|
|
12
11
|
import { getClientParameters } from "./helpers/clientHelpers.js";
|
|
13
12
|
import { getClientName } from "./helpers/namingHelpers.js";
|
|
14
13
|
import { getOperationFunction } from "./helpers/operationHelpers.js";
|
|
15
|
-
import { Client } from "./modularCodeModel.js";
|
|
14
|
+
import { Client, ModularCodeModel } from "./modularCodeModel.js";
|
|
16
15
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
17
16
|
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
18
17
|
import { SdkContext } from "../utils/interfaces.js";
|
|
19
18
|
|
|
20
19
|
export function buildClassicalClient(
|
|
21
20
|
dpgContext: SdkContext,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
srcPath: string,
|
|
25
|
-
subfolder: string
|
|
21
|
+
codeModel: ModularCodeModel,
|
|
22
|
+
client: Client
|
|
26
23
|
) {
|
|
27
24
|
const { description } = client;
|
|
28
25
|
const modularClientName = getClientName(client);
|
|
29
26
|
const classicalClientname = `${getClientName(client)}Client`;
|
|
30
27
|
const params = getClientParameters(client);
|
|
28
|
+
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
29
|
+
const subfolder = client.subfolder ?? "";
|
|
31
30
|
|
|
32
|
-
const clientFile = project.createSourceFile(
|
|
31
|
+
const clientFile = codeModel.project.createSourceFile(
|
|
33
32
|
`${srcPath}/${
|
|
34
33
|
subfolder !== "" ? subfolder + "/" : ""
|
|
35
34
|
}${classicalClientname}.ts`
|
|
@@ -116,10 +115,12 @@ function importAllModels(
|
|
|
116
115
|
|
|
117
116
|
const exported = [...apiModels.getExportedDeclarations().keys()];
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
if (exported.length > 0) {
|
|
119
|
+
clientFile.addImportDeclaration({
|
|
120
|
+
moduleSpecifier: `./models/models.js`,
|
|
121
|
+
namedImports: exported
|
|
122
|
+
});
|
|
123
|
+
}
|
|
123
124
|
|
|
124
125
|
const apiModelsOptions = project.getSourceFile(
|
|
125
126
|
`${srcPath}/${subfolder !== "" ? subfolder + "/" : ""}models/options.ts`
|
|
@@ -151,6 +152,10 @@ function buildClientOperationGroups(
|
|
|
151
152
|
clientClass: ClassDeclaration,
|
|
152
153
|
subfolder: string
|
|
153
154
|
) {
|
|
155
|
+
const operationMap = new Map<
|
|
156
|
+
OptionalKind<FunctionDeclarationStructure>,
|
|
157
|
+
string | undefined
|
|
158
|
+
>();
|
|
154
159
|
for (const operationGroup of client.operationGroups) {
|
|
155
160
|
const operationGroupName = toCamelCase(operationGroup.propertyName);
|
|
156
161
|
let clientType = "Client";
|
|
@@ -158,9 +163,11 @@ function buildClientOperationGroups(
|
|
|
158
163
|
clientType = `Client.${clientClass.getName()}`;
|
|
159
164
|
}
|
|
160
165
|
const operationDeclarations: OptionalKind<FunctionDeclarationStructure>[] =
|
|
161
|
-
operationGroup.operations.map((operation) =>
|
|
162
|
-
getOperationFunction(operation, clientType)
|
|
163
|
-
|
|
166
|
+
operationGroup.operations.map((operation) => {
|
|
167
|
+
const declarations = getOperationFunction(operation, clientType);
|
|
168
|
+
operationMap.set(declarations, operation.oriName);
|
|
169
|
+
return declarations;
|
|
170
|
+
});
|
|
164
171
|
|
|
165
172
|
if (operationGroupName && operationGroupName !== "") {
|
|
166
173
|
clientClass.addProperty({
|
|
@@ -168,7 +175,7 @@ function buildClientOperationGroups(
|
|
|
168
175
|
initializer: `
|
|
169
176
|
{
|
|
170
177
|
${operationDeclarations.map((d) => {
|
|
171
|
-
return `${d
|
|
178
|
+
return `${getClassicalMethodName(d)}: (${d.parameters
|
|
172
179
|
?.filter((p) => p.name !== "context")
|
|
173
180
|
.map(
|
|
174
181
|
(p) => p.name + (p.name === "options" ? "?" : "") + ": " + p.type
|
|
@@ -186,7 +193,7 @@ function buildClientOperationGroups(
|
|
|
186
193
|
operationDeclarations.map((d) => {
|
|
187
194
|
const method: MethodDeclarationStructure = {
|
|
188
195
|
docs: d.docs,
|
|
189
|
-
name: d
|
|
196
|
+
name: getClassicalMethodName(d),
|
|
190
197
|
kind: StructureKind.Method,
|
|
191
198
|
returnType: d.returnType,
|
|
192
199
|
parameters: d.parameters?.filter((p) => p.name !== "context"),
|
|
@@ -203,4 +210,10 @@ function buildClientOperationGroups(
|
|
|
203
210
|
);
|
|
204
211
|
}
|
|
205
212
|
}
|
|
213
|
+
|
|
214
|
+
function getClassicalMethodName(
|
|
215
|
+
declaration: OptionalKind<FunctionDeclarationStructure>
|
|
216
|
+
) {
|
|
217
|
+
return operationMap.get(declaration) ?? declaration.name ?? "FIXME";
|
|
218
|
+
}
|
|
206
219
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FunctionDeclaration,
|
|
1
|
+
import { FunctionDeclaration, SourceFile } from "ts-morph";
|
|
2
2
|
import { getClientParameters } from "./helpers/clientHelpers.js";
|
|
3
3
|
import { importCredential } from "./helpers/credentialHelpers.js";
|
|
4
4
|
import { getClientName } from "./helpers/namingHelpers.js";
|
|
5
|
-
import { Client, Parameter } from "./modularCodeModel.js";
|
|
5
|
+
import { Client, ModularCodeModel, Parameter } from "./modularCodeModel.js";
|
|
6
6
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
7
7
|
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
8
8
|
import { importModels } from "./buildOperations.js";
|
|
@@ -13,21 +13,20 @@ import { SdkContext } from "../utils/interfaces.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export function buildClientContext(
|
|
15
15
|
dpgContext: SdkContext,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
srcPath: string = "src",
|
|
19
|
-
subfolder: string = ""
|
|
16
|
+
codeModel: ModularCodeModel,
|
|
17
|
+
client: Client
|
|
20
18
|
): SourceFile {
|
|
21
|
-
const { description, parameters } = client;
|
|
19
|
+
const { description, parameters, subfolder } = client;
|
|
22
20
|
const name = getClientName(client);
|
|
23
|
-
const
|
|
21
|
+
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
22
|
+
const clientContextFile = codeModel.project.createSourceFile(
|
|
24
23
|
`${srcPath}/${
|
|
25
24
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
26
25
|
}/api/${name}Context.ts`
|
|
27
26
|
);
|
|
28
27
|
|
|
29
28
|
let factoryFunction;
|
|
30
|
-
importModels(srcPath, clientContextFile, project, subfolder);
|
|
29
|
+
importModels(srcPath, clientContextFile, codeModel.project, subfolder);
|
|
31
30
|
clientContextFile.addImportDeclaration({
|
|
32
31
|
moduleSpecifier: "@azure-rest/core-client",
|
|
33
32
|
namedImports: ["ClientOptions"]
|