@azure-tools/typespec-ts 0.33.0 → 0.34.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 +37 -0
- package/dist/src/framework/declaration.js.map +1 -1
- package/dist/src/framework/dependency.d.ts +25 -0
- package/dist/src/framework/dependency.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.d.ts +1 -1
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +16 -12
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/hooks/sdkTypes.d.ts +4 -2
- package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -1
- package/dist/src/framework/hooks/sdkTypes.js +43 -8
- package/dist/src/framework/hooks/sdkTypes.js.map +1 -1
- package/dist/src/framework/refkey.js +1 -1
- package/dist/src/framework/refkey.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +81 -24
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +37 -3
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +26 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +2 -2
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +25 -61
- 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 +0 -7
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +7 -3
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +58 -38
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +18 -0
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +95 -42
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +3 -4
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +24 -45
- 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 +3 -1
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRestorePoller.js +1 -1
- package/dist/src/modular/buildRestorePoller.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +5 -0
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +62 -17
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +11 -10
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +13 -28
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +435 -240
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/emitModelsOptions.d.ts +26 -0
- package/dist/src/modular/emitModelsOptions.d.ts.map +1 -0
- package/dist/src/modular/emitModelsOptions.js +106 -0
- package/dist/src/modular/emitModelsOptions.js.map +1 -0
- package/dist/src/modular/emitSamples.d.ts +7 -0
- package/dist/src/modular/emitSamples.d.ts.map +1 -0
- package/dist/src/modular/emitSamples.js +354 -0
- package/dist/src/modular/emitSamples.js.map +1 -0
- package/dist/src/modular/external-dependencies.d.ts +7 -0
- package/dist/src/modular/external-dependencies.d.ts.map +1 -1
- package/dist/src/modular/external-dependencies.js +58 -1
- package/dist/src/modular/external-dependencies.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js +2 -2
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +117 -48
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +3 -2
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +3 -0
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +9 -11
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +255 -408
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +12 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +30 -6
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +2 -1
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts +5 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.js +327 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -0
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts +4 -3
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +285 -102
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.d.ts +15 -0
- package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializeUtils.js +102 -0
- package/dist/src/modular/serialization/serializeUtils.js.map +1 -0
- package/dist/src/modular/type-expressions/get-credential-expression.d.ts +3 -0
- package/dist/src/modular/type-expressions/get-credential-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-credential-expression.js +17 -0
- package/dist/src/modular/type-expressions/get-credential-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-enum-expression.d.ts +6 -0
- package/dist/src/modular/type-expressions/get-enum-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-enum-expression.js +18 -0
- package/dist/src/modular/type-expressions/get-enum-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-model-expression.d.ts +9 -0
- package/dist/src/modular/type-expressions/get-model-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-model-expression.js +42 -0
- package/dist/src/modular/type-expressions/get-model-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-type-expression.d.ts +8 -0
- package/dist/src/modular/type-expressions/get-type-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-type-expression.js +94 -0
- package/dist/src/modular/type-expressions/get-type-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-union-expression.d.ts +5 -0
- package/dist/src/modular/type-expressions/get-union-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-union-expression.js +13 -0
- package/dist/src/modular/type-expressions/get-union-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/utils.d.ts +5 -0
- package/dist/src/modular/type-expressions/utils.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/utils.js +9 -0
- package/dist/src/modular/type-expressions/utils.js.map +1 -0
- package/dist/src/transform/transform.js +1 -1
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +1 -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/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +3 -3
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/utils/clientUtils.d.ts.map +1 -1
- package/dist/src/utils/clientUtils.js +1 -4
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/credentialUtils.d.ts +5 -0
- package/dist/src/utils/credentialUtils.d.ts.map +1 -1
- package/dist/src/utils/credentialUtils.js +36 -4
- package/dist/src/utils/credentialUtils.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +28 -43
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/framework/declaration.ts +0 -1
- package/src/framework/dependency.ts +25 -0
- package/src/framework/hooks/binder.ts +19 -14
- package/src/framework/hooks/sdkTypes.ts +53 -13
- package/src/framework/refkey.ts +1 -1
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +96 -25
- package/src/lib.ts +26 -3
- package/src/modular/buildClassicalClient.ts +30 -97
- package/src/modular/buildClassicalOperationGroups.ts +0 -14
- package/src/modular/buildClientContext.ts +90 -50
- package/src/modular/buildCodeModel.ts +118 -47
- package/src/modular/buildOperations.ts +41 -76
- package/src/modular/buildProjectFiles.ts +4 -2
- package/src/modular/buildRestorePoller.ts +1 -1
- package/src/modular/buildRootIndex.ts +75 -35
- package/src/modular/buildSubpathIndex.ts +13 -11
- package/src/modular/emitModels.ts +588 -326
- package/src/modular/emitModelsOptions.ts +161 -0
- package/src/modular/emitSamples.ts +481 -0
- package/src/modular/external-dependencies.ts +59 -1
- package/src/modular/helpers/classicalOperationHelpers.ts +6 -2
- package/src/modular/helpers/clientHelpers.ts +182 -76
- package/src/modular/helpers/namingHelpers.ts +14 -2
- package/src/modular/helpers/operationHelpers.ts +356 -638
- package/src/modular/helpers/typeHelpers.ts +38 -6
- package/src/modular/modularCodeModel.ts +3 -0
- package/src/modular/serialization/buildDeserializerFunction.ts +492 -0
- package/src/modular/serialization/buildSerializerFunction.ts +434 -141
- package/src/modular/serialization/serializeUtils.ts +143 -0
- package/src/modular/type-expressions/get-credential-expression.ts +18 -0
- package/src/modular/type-expressions/get-enum-expression.ts +28 -0
- package/src/modular/type-expressions/get-model-expression.ts +63 -0
- package/src/modular/type-expressions/get-type-expression.ts +111 -0
- package/src/modular/type-expressions/get-union-expression.ts +20 -0
- package/src/modular/type-expressions/utils.ts +15 -0
- package/src/transform/transform.ts +2 -2
- package/src/transform/transformApiVersionInfo.ts +2 -2
- package/src/transform/transformParameters.ts +1 -1
- package/src/transform/transformSchemas.ts +9 -8
- package/src/utils/clientUtils.ts +2 -12
- package/src/utils/credentialUtils.ts +43 -3
- package/src/utils/modelUtils.ts +32 -41
- package/static/static-helpers/serialization/serializers.ts +60 -0
- package/dist/src/modular/buildSerializeUtils.d.ts +0 -14
- package/dist/src/modular/buildSerializeUtils.d.ts.map +0 -1
- package/dist/src/modular/buildSerializeUtils.js +0 -534
- package/dist/src/modular/buildSerializeUtils.js.map +0 -1
- package/src/modular/buildSerializeUtils.ts +0 -749
|
@@ -1,43 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { buildGetClientCredentialParam, buildGetClientEndpointParam, buildGetClientOptionsParam, getClientParameters, importCredential } from "./helpers/clientHelpers.js";
|
|
4
|
-
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
1
|
+
import { NameType, isAzurePackage, normalizeName } from "@azure-tools/rlc-common";
|
|
2
|
+
import { buildGetClientCredentialParam, buildGetClientEndpointParam, buildGetClientOptionsParam, getClientParameterName, getClientParameters, getClientParametersDeclaration } from "./helpers/clientHelpers.js";
|
|
5
3
|
import { getClientName } from "./helpers/namingHelpers.js";
|
|
6
|
-
import {
|
|
4
|
+
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
5
|
+
import { getTypeExpression } from "./type-expressions/get-type-expression.js";
|
|
6
|
+
import { resolveReference } from "../framework/reference.js";
|
|
7
|
+
import { useDependencies } from "../framework/hooks/useDependencies.js";
|
|
8
|
+
import { buildEnumTypes, getApiVersionEnum } from "./emitModels.js";
|
|
7
9
|
/**
|
|
8
|
-
* This function
|
|
10
|
+
* This function gets the path of the file containing the modular client context
|
|
9
11
|
*/
|
|
10
|
-
export function
|
|
11
|
-
const {
|
|
12
|
+
export function getClientContextPath(_client, codeModel) {
|
|
13
|
+
const { subfolder, tcgcClient: client } = _client;
|
|
12
14
|
const name = getClientName(client);
|
|
13
|
-
const params = getClientParameters(client, dpgContext);
|
|
14
15
|
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const contentPath = `${srcPath}/${subfolder && subfolder !== "" ? subfolder + "/" : ""}api/${normalizeName(name, NameType.File)}Context.ts`;
|
|
17
|
+
return contentPath;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* This function creates the file containing the modular client context
|
|
21
|
+
*/
|
|
22
|
+
export function buildClientContext(_client, dpgContext, codeModel) {
|
|
23
|
+
const { description, tcgcClient: client } = _client;
|
|
24
|
+
const dependencies = useDependencies();
|
|
25
|
+
const name = getClientName(client);
|
|
26
|
+
const requiredParams = getClientParametersDeclaration(_client, dpgContext, {
|
|
27
|
+
onClientOnly: false,
|
|
28
|
+
requiredOnly: true
|
|
21
29
|
});
|
|
30
|
+
const clientContextFile = codeModel.project.createSourceFile(getClientContextPath(_client, codeModel));
|
|
22
31
|
clientContextFile.addInterface({
|
|
23
32
|
isExported: true,
|
|
24
|
-
name: `${
|
|
25
|
-
extends: [
|
|
33
|
+
name: `${_client.rlcClientName}`,
|
|
34
|
+
extends: [resolveReference(dependencies.Client)],
|
|
35
|
+
docs: getDocsFromDescription(description)
|
|
26
36
|
});
|
|
27
37
|
clientContextFile.addInterface({
|
|
28
38
|
name: `${name}ClientOptionalParams`,
|
|
29
39
|
isExported: true,
|
|
30
|
-
extends: [
|
|
31
|
-
properties:
|
|
32
|
-
|
|
33
|
-
return (p.optional || (p.type.type !== "constant" && p.clientDefaultValue));
|
|
40
|
+
extends: [resolveReference(dependencies.ClientOptions)],
|
|
41
|
+
properties: getClientParameters(_client, dpgContext, {
|
|
42
|
+
optionalOnly: true
|
|
34
43
|
})
|
|
44
|
+
.filter((p) => p.name !== "endpoint")
|
|
35
45
|
.map((p) => {
|
|
36
46
|
return {
|
|
37
|
-
name: p.
|
|
38
|
-
type:
|
|
47
|
+
name: normalizeName(p.name, NameType.Parameter),
|
|
48
|
+
type: p.name.toLowerCase() === "apiversion"
|
|
49
|
+
? "string"
|
|
50
|
+
: getTypeExpression(dpgContext, p.type),
|
|
39
51
|
hasQuestionToken: true,
|
|
40
|
-
docs:
|
|
52
|
+
docs: getDocsWithKnownVersion(dpgContext, p)
|
|
41
53
|
};
|
|
42
54
|
}),
|
|
43
55
|
docs: ["Optional parameters for the client."]
|
|
@@ -53,22 +65,18 @@ export function buildClientContext(client, dpgContext, codeModel) {
|
|
|
53
65
|
const factoryFunction = clientContextFile.addFunction({
|
|
54
66
|
docs: getDocsFromDescription(description),
|
|
55
67
|
name: `create${name}`,
|
|
56
|
-
returnType: `${
|
|
57
|
-
parameters:
|
|
68
|
+
returnType: `${_client.rlcClientName}`,
|
|
69
|
+
parameters: requiredParams,
|
|
58
70
|
isExported: true
|
|
59
71
|
});
|
|
60
|
-
const endpointParam = buildGetClientEndpointParam(factoryFunction,
|
|
61
|
-
const credentialParam = buildGetClientCredentialParam(
|
|
72
|
+
const endpointParam = buildGetClientEndpointParam(factoryFunction, dpgContext, _client);
|
|
73
|
+
const credentialParam = buildGetClientCredentialParam(_client, codeModel);
|
|
62
74
|
const optionsParam = buildGetClientOptionsParam(factoryFunction, codeModel, endpointParam);
|
|
63
|
-
factoryFunction.addStatements(`const clientContext = getClient(${endpointParam}, ${credentialParam}, ${optionsParam});`);
|
|
75
|
+
factoryFunction.addStatements(`const clientContext = ${resolveReference(dependencies.getClient)}(${endpointParam}, ${credentialParam}, ${optionsParam});`);
|
|
64
76
|
const { customHttpAuthHeaderName, customHttpAuthSharedKeyPrefix } = codeModel.options;
|
|
65
77
|
if (customHttpAuthHeaderName && customHttpAuthSharedKeyPrefix) {
|
|
66
|
-
clientContextFile.addImportDeclaration({
|
|
67
|
-
moduleSpecifier: getImportSpecifier("coreAuth", codeModel.runtimeImports),
|
|
68
|
-
namedImports: ["isKeyCredential"]
|
|
69
|
-
});
|
|
70
78
|
factoryFunction.addStatements(`
|
|
71
|
-
if(isKeyCredential(credential)) {
|
|
79
|
+
if(${resolveReference(dependencies.isKeyCredential)}(credential)) {
|
|
72
80
|
clientContext.pipeline.addPolicy({
|
|
73
81
|
name: "customKeyCredentialPolicy",
|
|
74
82
|
sendRequest(request, next) {
|
|
@@ -81,10 +89,10 @@ export function buildClientContext(client, dpgContext, codeModel) {
|
|
|
81
89
|
}
|
|
82
90
|
let apiVersionPolicyStatement = `clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" });`;
|
|
83
91
|
if (dpgContext.hasApiVersionInClient) {
|
|
84
|
-
const apiVersionParam =
|
|
85
|
-
if (
|
|
92
|
+
const apiVersionParam = getClientParameters(_client, dpgContext).find((x) => x.isApiVersionParam && x.kind === "method");
|
|
93
|
+
if (apiVersionParam) {
|
|
86
94
|
if (apiVersionParam.clientDefaultValue) {
|
|
87
|
-
apiVersionPolicyStatement += `const
|
|
95
|
+
apiVersionPolicyStatement += `const apiVersion = options.apiVersion ?? "${apiVersionParam.clientDefaultValue}";`;
|
|
88
96
|
}
|
|
89
97
|
apiVersionPolicyStatement += `
|
|
90
98
|
clientContext.pipeline.addPolicy({
|
|
@@ -96,7 +104,7 @@ export function buildClientContext(client, dpgContext, codeModel) {
|
|
|
96
104
|
if (!url.searchParams.get("api-version")) {
|
|
97
105
|
req.url = \`\${req.url}\${
|
|
98
106
|
Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"
|
|
99
|
-
}api-version=\${${apiVersionParam
|
|
107
|
+
}api-version=\${${getClientParameterName(apiVersionParam)}}\`;
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
return next(req);
|
|
@@ -122,4 +130,16 @@ export function buildClientContext(client, dpgContext, codeModel) {
|
|
|
122
130
|
clientContextFile.fixUnusedIdentifiers();
|
|
123
131
|
return clientContextFile;
|
|
124
132
|
}
|
|
133
|
+
function getDocsWithKnownVersion(dpgContext, param) {
|
|
134
|
+
const docs = getDocsFromDescription(param.doc);
|
|
135
|
+
if (param.name.toLowerCase() !== "apiversion") {
|
|
136
|
+
return docs;
|
|
137
|
+
}
|
|
138
|
+
const apiVersionEnum = getApiVersionEnum(dpgContext);
|
|
139
|
+
if (apiVersionEnum) {
|
|
140
|
+
const [_, knownValuesEnum] = buildEnumTypes(dpgContext, apiVersionEnum);
|
|
141
|
+
docs.push(`Known values of {@link ${knownValuesEnum.name}} that the service accepts.`);
|
|
142
|
+
}
|
|
143
|
+
return docs;
|
|
144
|
+
}
|
|
125
145
|
//# sourceMappingURL=buildClientContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildClientContext.js","sourceRoot":"","sources":["../../../src/modular/buildClientContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildClientContext.js","sourceRoot":"","sources":["../../../src/modular/buildClientContext.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,cAAc,EACd,aAAa,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,8BAA8B,EAC/B,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,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|
3
|
+
import { HttpAuth } from "@typespec/http";
|
|
2
4
|
import { RLCModel } from "@azure-tools/rlc-common";
|
|
3
5
|
import { Project } from "ts-morph";
|
|
4
6
|
import { SdkContext } from "../utils/interfaces.js";
|
|
7
|
+
interface CredentialType {
|
|
8
|
+
kind: "Credential";
|
|
9
|
+
scheme: HttpAuth;
|
|
10
|
+
}
|
|
11
|
+
interface CredentialTypeUnion {
|
|
12
|
+
kind: "CredentialTypeUnion";
|
|
13
|
+
types: CredentialType[];
|
|
14
|
+
}
|
|
15
|
+
type EmitterType = Type | CredentialType | CredentialTypeUnion;
|
|
5
16
|
export interface EmitterOptions {
|
|
6
17
|
"basic-setup-py"?: boolean;
|
|
7
18
|
"package-version"?: string;
|
|
@@ -10,7 +21,14 @@ export interface EmitterOptions {
|
|
|
10
21
|
"package-mode"?: string;
|
|
11
22
|
debug?: boolean;
|
|
12
23
|
}
|
|
24
|
+
interface EmitTypeOptions {
|
|
25
|
+
disableEffectiveModel?: boolean;
|
|
26
|
+
usage?: UsageFlags;
|
|
27
|
+
}
|
|
28
|
+
export declare function getType(context: SdkContext, type: EmitterType, options?: EmitTypeOptions): any;
|
|
29
|
+
export declare function emitModel(context: SdkContext, type: Model, options?: EmitTypeOptions): Record<string, any>;
|
|
13
30
|
export declare function emitCodeModel(dpgContext: SdkContext, rlcModelsMap: Map<string, RLCModel>, modularSourcesRoot: string, project: Project, options?: {
|
|
14
31
|
casing: "snake" | "camel";
|
|
15
32
|
}): ModularCodeModel;
|
|
33
|
+
export {};
|
|
16
34
|
//# sourceMappingURL=buildCodeModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCodeModel.d.ts","sourceRoot":"","sources":["../../../src/modular/buildCodeModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildCodeModel.d.ts","sourceRoot":"","sources":["../../../src/modular/buildCodeModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,EAOL,IAAI,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AC,MAAM,EAAE,QAAQ,CAAC,EACnC,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAA;CAAwB,GAC3D,gBAAgB,CA6ClB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { UsageFlags, getDiscriminator, getDoc, getEncode, getFriendlyName, getMaxItems, getMaxLength, getMaxValue, getMinItems, getMinLength, getMinValue, getPattern, getPropertyType, getSummary, getVisibility, isErrorModel, isNeverType, isNullType, isNumericType, isStringType, isTemplateDeclarationOrInstance, isType, isVoidType, listServices } from "@typespec/compiler";
|
|
1
|
+
import { NoTarget, UsageFlags, getDiscriminator, getDoc, getEncode, getFriendlyName, getMaxItems, getMaxLength, getMaxValue, getMinItems, getMinLength, getMinValue, getPattern, getPropertyType, getSummary, getVisibility, isErrorModel, isNeverType, isNullType, isNumericType, isStringType, isTemplateDeclarationOrInstance, isType, isVoidType, listServices } from "@typespec/compiler";
|
|
2
2
|
import { getAuthentication, getServers, isSharedRoute } from "@typespec/http";
|
|
3
|
-
import { NameType, buildRuntimeImports,
|
|
3
|
+
import { NameType, buildRuntimeImports, isAzurePackage, normalizeName } from "@azure-tools/rlc-common";
|
|
4
4
|
import { getAllModels, getClientNamespaceString, getClientType, getDefaultApiVersion, getHttpOperationWithCache, getLibraryName, getSdkUnion, getWireName, isApiVersion, listClients, listOperationGroups, listOperationsInOperationGroup } from "@azure-tools/typespec-client-generator-core";
|
|
5
|
-
import { buildCoreTypeInfo, getBodyType, getDefaultApiVersionString, getEffectiveSchemaType, isAzureCoreErrorType, isSchemaProperty } from "../utils/modelUtils.js";
|
|
5
|
+
import { buildCoreTypeInfo, getBodyType, getDefaultApiVersionString, getEffectiveSchemaType, isAzureCoreErrorType, isBodyRequired, isSchemaProperty } from "../utils/modelUtils.js";
|
|
6
6
|
import { camelToSnakeCase, toCamelCase } from "../utils/casingUtils.js";
|
|
7
7
|
import { extractPagedMetadataNested, getOperationGroupName, getOperationName, isBinaryPayload, isIgnoredHeaderParam, isLongRunningOperation, parseItemName, parseNextLinkName } from "../utils/operationUtil.js";
|
|
8
8
|
import { getLroMetadata, getPagedResult } from "@azure-tools/typespec-azure-core";
|
|
@@ -10,9 +10,9 @@ import { getAddedOnVersions } from "@typespec/versioning";
|
|
|
10
10
|
import { getModelNamespaceName } from "../utils/namespaceUtils.js";
|
|
11
11
|
import { getSupportedHttpAuth } from "../utils/credentialUtils.js";
|
|
12
12
|
import { getType as getTypeName } from "./helpers/typeHelpers.js";
|
|
13
|
-
import { isModelWithAdditionalProperties } from "./emitModels.js";
|
|
14
13
|
import { reportDiagnostic } from "../lib.js";
|
|
15
14
|
import { useContext } from "../contextManager.js";
|
|
15
|
+
import { normalizeModelName } from "./emitModels.js";
|
|
16
16
|
let CASING = "snake";
|
|
17
17
|
function applyCasing(name, options = { casing: "snake" }) {
|
|
18
18
|
if (options.casing === "camel") {
|
|
@@ -61,6 +61,7 @@ function handleDiscriminator(context, type, usage) {
|
|
|
61
61
|
const discriminatorValues = [];
|
|
62
62
|
const aliases = [];
|
|
63
63
|
const discriminatedSubtypes = [];
|
|
64
|
+
let discriminatorTcgcType = undefined;
|
|
64
65
|
for (const childModel of type.derivedModels) {
|
|
65
66
|
const modelType = getType(context, childModel, { usage });
|
|
66
67
|
aliases.push(modelType.name);
|
|
@@ -68,6 +69,7 @@ function handleDiscriminator(context, type, usage) {
|
|
|
68
69
|
if (property.restApiName === discriminator.propertyName) {
|
|
69
70
|
modelType.discriminatorValue = property.type.value;
|
|
70
71
|
discriminatorValues.push(modelType.discriminatorValue);
|
|
72
|
+
discriminatorTcgcType = getClientType(context, property.type);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
discriminatedSubtypes.push(modelType);
|
|
@@ -76,7 +78,7 @@ function handleDiscriminator(context, type, usage) {
|
|
|
76
78
|
description: discriminatorValues.length > 0
|
|
77
79
|
? `the discriminator possible values: ${discriminatorValues.join(", ")}`
|
|
78
80
|
: "discriminator property",
|
|
79
|
-
type: { type: "string" },
|
|
81
|
+
type: { type: "string", tcgcType: discriminatorTcgcType },
|
|
80
82
|
restApiName: discriminator.propertyName,
|
|
81
83
|
clientName: discriminator.propertyName,
|
|
82
84
|
name: discriminator.propertyName,
|
|
@@ -109,7 +111,8 @@ function processModelProperties(context, newValue, model, usage) {
|
|
|
109
111
|
newProperty = {
|
|
110
112
|
...newProperty,
|
|
111
113
|
...discriminatorInfo,
|
|
112
|
-
type: newProperty["type"]
|
|
114
|
+
type: newProperty["type"],
|
|
115
|
+
tcgcType: getClientType(context, property)
|
|
113
116
|
};
|
|
114
117
|
}
|
|
115
118
|
newValue.properties.push(newProperty);
|
|
@@ -124,8 +127,8 @@ function processModelProperties(context, newValue, model, usage) {
|
|
|
124
127
|
if (newValue.name) {
|
|
125
128
|
newValue.name = normalizeName(newValue.name, NameType.Interface);
|
|
126
129
|
discriminatorInfo === null || discriminatorInfo === void 0 ? void 0 : discriminatorInfo.aliases.push(`${newValue.name}`);
|
|
127
|
-
newValue.alias = `${newValue.name}`;
|
|
128
|
-
newValue.name = `${newValue.name}
|
|
130
|
+
newValue.alias = `${newValue.name.replace(/Union$/g, "")}`;
|
|
131
|
+
newValue.name = `${newValue.name}`;
|
|
129
132
|
newValue.aliasType = discriminatorInfo === null || discriminatorInfo === void 0 ? void 0 : discriminatorInfo.aliases.join(" | ");
|
|
130
133
|
newValue.types = discriminatorInfo === null || discriminatorInfo === void 0 ? void 0 : discriminatorInfo.discriminatedSubtypes;
|
|
131
134
|
newValue.isPolymorphicBaseModel = true;
|
|
@@ -142,7 +145,7 @@ function isEmptyAnonymousModel(type) {
|
|
|
142
145
|
type.derivedModels.length === 0 &&
|
|
143
146
|
!type.indexer);
|
|
144
147
|
}
|
|
145
|
-
function getType(context, type, options = {}) {
|
|
148
|
+
export function getType(context, type, options = {}) {
|
|
146
149
|
var _a, _b;
|
|
147
150
|
const modularMetatree = useContext("modularMetaTree");
|
|
148
151
|
// don't cache simple type(string, int, etc) since decorators may change the result
|
|
@@ -157,24 +160,30 @@ function getType(context, type, options = {}) {
|
|
|
157
160
|
return cached;
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
|
-
let newValue;
|
|
163
|
+
let newValue = { __raw: type };
|
|
161
164
|
if (isEmptyAnonymousModel(type)) {
|
|
162
165
|
// do not generate model for empty model, treat it as any
|
|
163
166
|
newValue = { type: "any" };
|
|
164
167
|
}
|
|
165
168
|
else {
|
|
166
|
-
newValue = emitType(context, type, options
|
|
169
|
+
newValue = emitType(context, type, options);
|
|
167
170
|
}
|
|
168
171
|
if (type.kind === "ModelProperty" || type.kind === "Scalar") {
|
|
169
172
|
newValue = applyEncoding(context.program, type, newValue);
|
|
170
173
|
}
|
|
171
174
|
if (isTypespecType(type)) {
|
|
172
|
-
newValue.tcgcType = getClientType(context,
|
|
175
|
+
newValue.tcgcType = getClientType(context, effectiveModel);
|
|
176
|
+
newValue.name = !newValue.tcgcType.isGeneratedName
|
|
177
|
+
? normalizeModelName(context, newValue.tcgcType)
|
|
178
|
+
: newValue.name;
|
|
173
179
|
newValue.__raw = type;
|
|
174
180
|
modularMetatree.set(type, newValue);
|
|
175
181
|
}
|
|
176
182
|
if (enableCache) {
|
|
177
183
|
if (!options.disableEffectiveModel) {
|
|
184
|
+
if (newValue.__raw === undefined) {
|
|
185
|
+
newValue.__raw = type;
|
|
186
|
+
}
|
|
178
187
|
typesMap.set(effectiveModel, newValue);
|
|
179
188
|
}
|
|
180
189
|
if (type.kind === "Union") {
|
|
@@ -188,7 +197,7 @@ function getType(context, type, options = {}) {
|
|
|
188
197
|
// need to do properties after insertion to avoid infinite recursion
|
|
189
198
|
processModelProperties(context, newValue, type, options.usage);
|
|
190
199
|
if (newValue.type === "dict") {
|
|
191
|
-
newValue = { ...emitModel(context, type, options
|
|
200
|
+
newValue = { ...emitModel(context, type, options), ...newValue };
|
|
192
201
|
typesMap.set(effectiveModel, newValue);
|
|
193
202
|
}
|
|
194
203
|
}
|
|
@@ -205,7 +214,7 @@ function getType(context, type, options = {}) {
|
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
if (type.kind === "Model" &&
|
|
208
|
-
|
|
217
|
+
newValue.tcgcType.additionalProperties &&
|
|
209
218
|
!((_a = context.rlcOptions) === null || _a === void 0 ? void 0 : _a.compatibilityMode)) {
|
|
210
219
|
reportDiagnostic(context.program, {
|
|
211
220
|
code: "compatible-additional-properties",
|
|
@@ -215,6 +224,7 @@ function getType(context, type, options = {}) {
|
|
|
215
224
|
target: type
|
|
216
225
|
});
|
|
217
226
|
}
|
|
227
|
+
typesMap.set(effectiveModel, newValue);
|
|
218
228
|
return newValue;
|
|
219
229
|
}
|
|
220
230
|
function isTypespecType(type) {
|
|
@@ -277,7 +287,8 @@ function emitBodyParameter(context, httpOperation) {
|
|
|
277
287
|
type,
|
|
278
288
|
location: "body",
|
|
279
289
|
...base,
|
|
280
|
-
isBinaryPayload: isBinaryPayload(context, body.type, contentTypes)
|
|
290
|
+
isBinaryPayload: isBinaryPayload(context, body.type, contentTypes),
|
|
291
|
+
optional: !isBodyRequired(httpOperation.parameters)
|
|
281
292
|
};
|
|
282
293
|
}
|
|
283
294
|
return undefined;
|
|
@@ -294,15 +305,22 @@ function emitParameter(context, parameter, implementation) {
|
|
|
294
305
|
/// We don't want constant types for content types, so we make sure if it's
|
|
295
306
|
/// a constant, we make it not constant
|
|
296
307
|
clientDefaultValue = type["value"];
|
|
297
|
-
type =
|
|
308
|
+
type = {
|
|
309
|
+
...type["valueType"],
|
|
310
|
+
tcgcType: base.tcgcType.kind === "constant"
|
|
311
|
+
? base.tcgcType.valueType
|
|
312
|
+
: base.tcgcType
|
|
313
|
+
};
|
|
298
314
|
}
|
|
299
315
|
const paramMap = {
|
|
300
316
|
restApiName: parameter.name,
|
|
301
317
|
location: parameter.type,
|
|
302
318
|
type: base.format ? { ...type, format: base.format } : type,
|
|
303
319
|
implementation: implementation,
|
|
304
|
-
skipUrlEncoding: parameter.type === "endpointPath"
|
|
305
|
-
|
|
320
|
+
skipUrlEncoding: parameter.type === "endpointPath" ||
|
|
321
|
+
(parameter.type === "path" && parameter.allowReserved),
|
|
322
|
+
format: (_a = parameter.format) !== null && _a !== void 0 ? _a : base.format,
|
|
323
|
+
tcgcType: base.tcgcType
|
|
306
324
|
};
|
|
307
325
|
if (paramMap.type.type === "constant") {
|
|
308
326
|
clientDefaultValue = paramMap.type.value;
|
|
@@ -464,10 +482,31 @@ function addLroInformation(context, operation, emittedOperation) {
|
|
|
464
482
|
finalResult: (metadata === null || metadata === void 0 ? void 0 : metadata.finalResult) === "void" || (metadata === null || metadata === void 0 ? void 0 : metadata.finalResult) === undefined
|
|
465
483
|
? undefined
|
|
466
484
|
: getType(context, metadata.finalResult),
|
|
467
|
-
finalStateVia:
|
|
485
|
+
finalStateVia: getFinalStateVia(context, operation, metadata),
|
|
468
486
|
finalResultPath: metadata === null || metadata === void 0 ? void 0 : metadata.finalResultPath
|
|
469
487
|
};
|
|
470
488
|
}
|
|
489
|
+
function getFinalStateVia(context, operation, metadata) {
|
|
490
|
+
if (!metadata) {
|
|
491
|
+
return undefined;
|
|
492
|
+
}
|
|
493
|
+
switch (metadata.finalStateVia) {
|
|
494
|
+
case "azure-async-operation":
|
|
495
|
+
case "location":
|
|
496
|
+
case "operation-location":
|
|
497
|
+
case "original-uri":
|
|
498
|
+
return metadata.finalStateVia;
|
|
499
|
+
default:
|
|
500
|
+
reportDiagnostic(context.program, {
|
|
501
|
+
code: "un-supported-finalStateVia",
|
|
502
|
+
format: {
|
|
503
|
+
finalStateVia: metadata.finalStateVia
|
|
504
|
+
},
|
|
505
|
+
target: operation
|
|
506
|
+
});
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
471
510
|
function addPagingInformation(context, operation, emittedOperation) {
|
|
472
511
|
emittedOperation["discriminator"] = "paging";
|
|
473
512
|
const pagedResult = getPagedResult(context.program, operation);
|
|
@@ -624,7 +663,7 @@ function isReadOnly(program, type) {
|
|
|
624
663
|
}
|
|
625
664
|
}
|
|
626
665
|
function emitProperty(context, property, usage) {
|
|
627
|
-
var _a, _b;
|
|
666
|
+
var _a, _b, _c;
|
|
628
667
|
const newProperty = applyEncoding(context.program, property, property);
|
|
629
668
|
let clientDefaultValue = undefined;
|
|
630
669
|
const propertyDefaultKind = (_a = property.default) === null || _a === void 0 ? void 0 : _a.kind;
|
|
@@ -645,7 +684,9 @@ function emitProperty(context, property, usage) {
|
|
|
645
684
|
}
|
|
646
685
|
const type = getType(context, property.type, { usage });
|
|
647
686
|
return {
|
|
648
|
-
clientName:
|
|
687
|
+
clientName: ((_c = context.rlcOptions) === null || _c === void 0 ? void 0 : _c.ignorePropertyNameNormalize)
|
|
688
|
+
? clientName
|
|
689
|
+
: normalizeName(clientName, NameType.Property),
|
|
649
690
|
restApiName: jsonName,
|
|
650
691
|
type: newProperty.format ? { ...type, format: newProperty.format } : type,
|
|
651
692
|
optional: property.optional,
|
|
@@ -676,15 +717,17 @@ function getName(program, type) {
|
|
|
676
717
|
}
|
|
677
718
|
}
|
|
678
719
|
}
|
|
679
|
-
function emitModel(context, type,
|
|
720
|
+
export function emitModel(context, type, options = {}) {
|
|
680
721
|
var _a, _b;
|
|
681
722
|
// Now we know it's a defined model
|
|
682
723
|
const properties = [];
|
|
683
724
|
let baseModel = undefined;
|
|
684
725
|
if (type.baseModel) {
|
|
685
|
-
baseModel = getType(context, type.baseModel,
|
|
726
|
+
baseModel = getType(context, type.baseModel, options);
|
|
686
727
|
}
|
|
687
|
-
const effectiveName =
|
|
728
|
+
const effectiveName = !options.disableEffectiveModel
|
|
729
|
+
? getEffectiveSchemaType(context.program, type).name
|
|
730
|
+
: undefined;
|
|
688
731
|
const overridedModelName = normalizeName((_a = getLibraryName(context, type)) !== null && _a !== void 0 ? _a : getFriendlyName(context.program, type), NameType.Interface, true);
|
|
689
732
|
const fullNamespaceName = getModelNamespaceName(context, type.namespace)
|
|
690
733
|
.map((nsName) => {
|
|
@@ -733,7 +776,7 @@ function emitModel(context, type, usage) {
|
|
|
733
776
|
: modelName,
|
|
734
777
|
base: modelName === "" ? "json" : "dpg",
|
|
735
778
|
coreTypeInfo: buildCoreTypeInfo(context.program, type),
|
|
736
|
-
usage
|
|
779
|
+
usage: options.usage
|
|
737
780
|
};
|
|
738
781
|
}
|
|
739
782
|
function intOrFloat(value) {
|
|
@@ -753,6 +796,9 @@ function emitEnum(context, type) {
|
|
|
753
796
|
description: getDocStr(program, m)
|
|
754
797
|
});
|
|
755
798
|
}
|
|
799
|
+
if (enumValues.length === 0) {
|
|
800
|
+
throw new Error(`Expecting enum values but got none`);
|
|
801
|
+
}
|
|
756
802
|
const name = normalizeName(getLibraryName(context, type) ? getLibraryName(context, type) : type.name, NameType.Interface);
|
|
757
803
|
return {
|
|
758
804
|
type: "enum",
|
|
@@ -867,7 +913,7 @@ function emitStdScalar(program, scalar) {
|
|
|
867
913
|
format: {
|
|
868
914
|
propertyName: (_c = newScalar === null || newScalar === void 0 ? void 0 : newScalar.name) !== null && _c !== void 0 ? _c : ""
|
|
869
915
|
},
|
|
870
|
-
target:
|
|
916
|
+
target: NoTarget
|
|
871
917
|
});
|
|
872
918
|
return { type: "integer", format: newScalar.format };
|
|
873
919
|
default:
|
|
@@ -997,7 +1043,7 @@ function emitUnion(context, type, usage) {
|
|
|
997
1043
|
? getLibraryName(context, type)
|
|
998
1044
|
: type.name;
|
|
999
1045
|
const discriminatorPropertyName = (_a = getDiscriminator(context.program, type)) === null || _a === void 0 ? void 0 : _a.propertyName;
|
|
1000
|
-
const variantTypes = sdkType.
|
|
1046
|
+
const variantTypes = sdkType.variantTypes.map((x) => {
|
|
1001
1047
|
const valueType = getType(context, x.__raw, { usage });
|
|
1002
1048
|
if (valueType.properties && discriminatorPropertyName) {
|
|
1003
1049
|
valueType.discriminatorValue = valueType.properties.filter((p) => p.clientName === discriminatorPropertyName)[0].type.value;
|
|
@@ -1036,7 +1082,7 @@ function emitUnion(context, type, usage) {
|
|
|
1036
1082
|
return {
|
|
1037
1083
|
name: typeName,
|
|
1038
1084
|
nullable: isNull,
|
|
1039
|
-
description: sdkType.
|
|
1085
|
+
description: sdkType.doc || `Type of ${typeName}`,
|
|
1040
1086
|
internal: true,
|
|
1041
1087
|
type: sdkType.kind,
|
|
1042
1088
|
valueType: emitSimpleType(sdkType.valueType),
|
|
@@ -1049,13 +1095,13 @@ function emitUnion(context, type, usage) {
|
|
|
1049
1095
|
}
|
|
1050
1096
|
else if (nonNullOptions.length === 1 && nonNullOptions[0]) {
|
|
1051
1097
|
return {
|
|
1052
|
-
...emitType(context, nonNullOptions[0], usage),
|
|
1098
|
+
...emitType(context, nonNullOptions[0], { usage }),
|
|
1053
1099
|
nullable: isNull
|
|
1054
1100
|
};
|
|
1055
1101
|
}
|
|
1056
1102
|
else {
|
|
1057
1103
|
return {
|
|
1058
|
-
...emitType(context, sdkType.__raw, usage),
|
|
1104
|
+
...emitType(context, sdkType.__raw, { usage }),
|
|
1059
1105
|
nullable: isNull
|
|
1060
1106
|
};
|
|
1061
1107
|
}
|
|
@@ -1089,14 +1135,14 @@ function emitSimpleType(type) {
|
|
|
1089
1135
|
format: undefined
|
|
1090
1136
|
};
|
|
1091
1137
|
}
|
|
1092
|
-
function emitType(context, type,
|
|
1138
|
+
function emitType(context, type, options = {}) {
|
|
1093
1139
|
if (type.kind === "Credential") {
|
|
1094
1140
|
return emitCredential(type.scheme);
|
|
1095
1141
|
}
|
|
1096
1142
|
if (type.kind === "CredentialTypeUnion") {
|
|
1097
1143
|
return emitCredentialUnion(type);
|
|
1098
1144
|
}
|
|
1099
|
-
const builtinType = mapTypeSpecType(context, type, usage);
|
|
1145
|
+
const builtinType = mapTypeSpecType(context, type, options.usage);
|
|
1100
1146
|
if (builtinType !== undefined) {
|
|
1101
1147
|
// add in description elements for types derived from primitive types (SecureString, etc.)
|
|
1102
1148
|
const doc = getDoc(context.program, type);
|
|
@@ -1109,13 +1155,13 @@ function emitType(context, type, usage) {
|
|
|
1109
1155
|
case "Intrinsic":
|
|
1110
1156
|
return { type: type.name };
|
|
1111
1157
|
case "Model":
|
|
1112
|
-
return emitModel(context, type,
|
|
1158
|
+
return emitModel(context, type, options);
|
|
1113
1159
|
case "Scalar":
|
|
1114
1160
|
return emitScalar(context.program, type);
|
|
1115
1161
|
case "Union":
|
|
1116
|
-
return emitUnion(context, type, usage);
|
|
1162
|
+
return emitUnion(context, type, options.usage);
|
|
1117
1163
|
case "UnionVariant":
|
|
1118
|
-
return emitType(context, type.type,
|
|
1164
|
+
return emitType(context, type.type, options);
|
|
1119
1165
|
case "Enum":
|
|
1120
1166
|
return emitEnum(context, type);
|
|
1121
1167
|
case "EnumMember":
|
|
@@ -1140,7 +1186,7 @@ function emitOperationGroups(context, client, rlcModels) {
|
|
|
1140
1186
|
const overrideName = getLibraryName(context, operationGroup.type);
|
|
1141
1187
|
const name = ((_a = context.rlcOptions) === null || _a === void 0 ? void 0 : _a.hierarchyClient) ||
|
|
1142
1188
|
((_b = context.rlcOptions) === null || _b === void 0 ? void 0 : _b.enableOperationGroup)
|
|
1143
|
-
? overrideName !== null && overrideName !== void 0 ? overrideName : operationGroup.type.name
|
|
1189
|
+
? (overrideName !== null && overrideName !== void 0 ? overrideName : operationGroup.type.name)
|
|
1144
1190
|
: "";
|
|
1145
1191
|
const hierarchies = ((_c = context.rlcOptions) === null || _c === void 0 ? void 0 : _c.hierarchyClient) ||
|
|
1146
1192
|
((_d = context.rlcOptions) === null || _d === void 0 ? void 0 : _d.enableOperationGroup)
|
|
@@ -1205,14 +1251,14 @@ function getServerHelper(program, namespace) {
|
|
|
1205
1251
|
}
|
|
1206
1252
|
function emitServerParams(context, namespace) {
|
|
1207
1253
|
const server = getServerHelper(context.program, namespace);
|
|
1208
|
-
if (server === undefined) {
|
|
1254
|
+
if (server === undefined || server.parameters.size === 0) {
|
|
1209
1255
|
return [
|
|
1210
1256
|
{
|
|
1211
1257
|
optional: false,
|
|
1212
1258
|
description: "Service host",
|
|
1213
|
-
clientName: "
|
|
1259
|
+
clientName: "endpointParam",
|
|
1214
1260
|
clientDefaultValue: null,
|
|
1215
|
-
restApiName: "
|
|
1261
|
+
restApiName: "endpoint",
|
|
1216
1262
|
location: "endpointPath",
|
|
1217
1263
|
type: { type: "string" },
|
|
1218
1264
|
implementation: "Client",
|
|
@@ -1244,9 +1290,9 @@ function emitServerParams(context, namespace) {
|
|
|
1244
1290
|
{
|
|
1245
1291
|
optional: false,
|
|
1246
1292
|
description: "Service host",
|
|
1247
|
-
clientName: "
|
|
1293
|
+
clientName: "endpointParam",
|
|
1248
1294
|
clientDefaultValue: server.url,
|
|
1249
|
-
restApiName: "
|
|
1295
|
+
restApiName: "endpoint",
|
|
1250
1296
|
location: "path",
|
|
1251
1297
|
type: { type: "string" },
|
|
1252
1298
|
implementation: "Client",
|
|
@@ -1317,6 +1363,12 @@ function emitClients(context, rlcModelsMap) {
|
|
|
1317
1363
|
const retval = [];
|
|
1318
1364
|
methodApiVersionParam = undefined;
|
|
1319
1365
|
for (const client of clients) {
|
|
1366
|
+
const sdkPackageClient = context.sdkPackage.clients.find((p) => {
|
|
1367
|
+
return p.name === client.name;
|
|
1368
|
+
});
|
|
1369
|
+
if (!sdkPackageClient) {
|
|
1370
|
+
throw new Error(`Client ${client.name} not found in the SDK package`);
|
|
1371
|
+
}
|
|
1320
1372
|
const clientName = client.name.replace("Client", "");
|
|
1321
1373
|
const server = getServerHelper(program, client.service);
|
|
1322
1374
|
const rlcModels = rlcModelsMap.get(client.service.name);
|
|
@@ -1328,9 +1380,10 @@ function emitClients(context, rlcModelsMap) {
|
|
|
1328
1380
|
description: getDocStr(program, client.type),
|
|
1329
1381
|
parameters: emitGlobalParameters(context, client.service),
|
|
1330
1382
|
operationGroups: emitOperationGroups(context, client, rlcModels),
|
|
1383
|
+
tcgcClient: sdkPackageClient,
|
|
1331
1384
|
url: server ? server.url : "",
|
|
1332
1385
|
apiVersions: [],
|
|
1333
|
-
rlcClientName:
|
|
1386
|
+
rlcClientName: `${client.name.replace("Client", "")}Context`,
|
|
1334
1387
|
subfolder: "",
|
|
1335
1388
|
rlcHelperDetails: rlcModels && rlcModels.helperDetails ? rlcModels.helperDetails : {}
|
|
1336
1389
|
};
|