@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,47 +1,55 @@
|
|
|
1
|
-
import { NameType, addImportToSpecifier } from "@azure-tools/rlc-common";
|
|
2
1
|
import { NoTarget } from "@typespec/compiler";
|
|
3
2
|
import { PagingHelpers, PollingHelpers } from "../static-helpers-metadata.js";
|
|
4
|
-
import {
|
|
3
|
+
import { getType, isTypeNullable } from "./typeHelpers.js";
|
|
5
4
|
import { getClassicalLayerPrefix, getOperationName } from "./namingHelpers.js";
|
|
6
5
|
import { getCollectionFormatHelper, hasCollectionFormatInfo } from "../../utils/operationUtil.js";
|
|
7
|
-
import {
|
|
6
|
+
import { isNormalUnion, isSpecialHandledUnion } from "../serialization/serializeUtils.js";
|
|
8
7
|
import { getDocsFromDescription, getFixmeForMultilineDocs } from "./docsHelpers.js";
|
|
9
|
-
import {
|
|
8
|
+
import { toPascalCase } from "../../utils/casingUtils.js";
|
|
10
9
|
import { AzurePollingDependencies } from "../external-dependencies.js";
|
|
10
|
+
import { NameType } from "@azure-tools/rlc-common";
|
|
11
|
+
import { buildModelDeserializer } from "../serialization/buildDeserializerFunction.js";
|
|
12
|
+
import { buildModelSerializer } from "../serialization/buildSerializerFunction.js";
|
|
13
|
+
import { refkey } from "../../framework/refkey.js";
|
|
11
14
|
import { reportDiagnostic } from "../../lib.js";
|
|
12
15
|
import { resolveReference } from "../../framework/reference.js";
|
|
13
16
|
import { useDependencies } from "../../framework/hooks/useDependencies.js";
|
|
14
|
-
|
|
17
|
+
import { useSdkTypes } from "../../framework/hooks/sdkTypes.js";
|
|
18
|
+
import { isAzureCoreErrorType } from "../../utils/modelUtils.js";
|
|
19
|
+
import { getTypeExpression } from "../type-expressions/get-type-expression.js";
|
|
20
|
+
export function getSendPrivateFunction(dpgContext, operation, clientType) {
|
|
15
21
|
var _a;
|
|
16
|
-
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
22
|
+
const parameters = getOperationSignatureParameters(dpgContext, operation, clientType);
|
|
17
23
|
const { name } = getOperationName(operation);
|
|
24
|
+
const dependencies = useDependencies();
|
|
18
25
|
const functionStatement = {
|
|
19
26
|
isAsync: false,
|
|
20
27
|
isExported: true,
|
|
21
28
|
name: `_${name}Send`,
|
|
22
29
|
parameters,
|
|
23
|
-
returnType:
|
|
30
|
+
returnType: resolveReference(dependencies.StreamableMethod)
|
|
24
31
|
};
|
|
25
32
|
const operationPath = operation.url;
|
|
26
33
|
const operationMethod = operation.method.toLowerCase();
|
|
27
34
|
const optionalParamName = (_a = parameters.filter((p) => { var _a; return (_a = p.type) === null || _a === void 0 ? void 0 : _a.toString().endsWith("OptionalParams"); })[0]) === null || _a === void 0 ? void 0 : _a.name;
|
|
28
35
|
const statements = [];
|
|
29
|
-
statements.push(`return context.path("${operationPath}", ${getPathParameters(operation)}).${operationMethod}({
|
|
36
|
+
statements.push(`return context.path("${operationPath}", ${getPathParameters(dpgContext, operation)}).${operationMethod}({...${resolveReference(dependencies.operationOptionsToRequestParameters)}(${optionalParamName}), ${getRequestParameters(dpgContext, operation)}});`);
|
|
30
37
|
return {
|
|
31
38
|
...functionStatement,
|
|
32
39
|
statements
|
|
33
40
|
};
|
|
34
41
|
}
|
|
35
|
-
export function getDeserializePrivateFunction(
|
|
42
|
+
export function getDeserializePrivateFunction(context, operation) {
|
|
36
43
|
var _a, _b, _c, _d;
|
|
37
44
|
const { name } = getOperationName(operation);
|
|
45
|
+
const dependencies = useDependencies();
|
|
46
|
+
const PathUncheckedResponseReference = resolveReference(dependencies.PathUncheckedResponse);
|
|
38
47
|
const parameters = [
|
|
39
48
|
{
|
|
40
49
|
name: "result",
|
|
41
|
-
type:
|
|
50
|
+
type: PathUncheckedResponseReference
|
|
42
51
|
}
|
|
43
52
|
];
|
|
44
|
-
addImportToSpecifier("restClient", runtimeImports, "PathUncheckedResponse");
|
|
45
53
|
// TODO: Support LRO + paging operation
|
|
46
54
|
// https://github.com/Azure/autorest.typescript/issues/2313
|
|
47
55
|
const isLroOnly = isLroOnlyOperation(operation);
|
|
@@ -50,10 +58,13 @@ export function getDeserializePrivateFunction(operation, runtimeImports) {
|
|
|
50
58
|
const response = operation.responses[0];
|
|
51
59
|
let returnType;
|
|
52
60
|
if (isLroOnly && operation.method.toLowerCase() !== "patch") {
|
|
53
|
-
returnType = buildLroReturnType(operation);
|
|
61
|
+
returnType = buildLroReturnType(context, operation);
|
|
54
62
|
}
|
|
55
63
|
else if ((_a = response === null || response === void 0 ? void 0 : response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
56
|
-
returnType =
|
|
64
|
+
returnType = {
|
|
65
|
+
name: response.type.name,
|
|
66
|
+
type: getTypeExpression(context, response.type.tcgcType)
|
|
67
|
+
};
|
|
57
68
|
}
|
|
58
69
|
else {
|
|
59
70
|
returnType = { name: "", type: "void" };
|
|
@@ -66,9 +77,9 @@ export function getDeserializePrivateFunction(operation, runtimeImports) {
|
|
|
66
77
|
returnType: `Promise<${returnType.type}>`
|
|
67
78
|
};
|
|
68
79
|
const statements = [];
|
|
80
|
+
const createRestErrorReference = resolveReference(dependencies.createRestError);
|
|
69
81
|
statements.push(`const expectedStatuses = ${getExpectedStatuses(operation)};`);
|
|
70
|
-
statements.push(`if(!expectedStatuses.includes(result.status)){`, `throw
|
|
71
|
-
addImportToSpecifier("restClient", runtimeImports, "createRestError");
|
|
82
|
+
statements.push(`if(!expectedStatuses.includes(result.status)){`, `throw ${createRestErrorReference}(result);`, "}");
|
|
72
83
|
const deserializedType = isLroOnly
|
|
73
84
|
? (_b = operation === null || operation === void 0 ? void 0 : operation.lroMetadata) === null || _b === void 0 ? void 0 : _b.finalResult
|
|
74
85
|
: response.type;
|
|
@@ -83,36 +94,33 @@ export function getDeserializePrivateFunction(operation, runtimeImports) {
|
|
|
83
94
|
}
|
|
84
95
|
`);
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
else if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
else if (returnType.type === "void" || deserializedType === undefined) {
|
|
104
|
-
statements.push(`return;`);
|
|
97
|
+
if (deserializedType === null || deserializedType === void 0 ? void 0 : deserializedType.tcgcType) {
|
|
98
|
+
const deserializeFunctionName = buildModelDeserializer(context, deserializedType.tcgcType, false, true);
|
|
99
|
+
if (deserializeFunctionName) {
|
|
100
|
+
statements.push(`return ${deserializeFunctionName}(${deserializedRoot})`);
|
|
101
|
+
}
|
|
102
|
+
else if (isAzureCoreErrorType(context.program, deserializedType.__raw)) {
|
|
103
|
+
statements.push(`return ${deserializedRoot}`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
statements.push(`return ${deserializeResponseValue(context, deserializedType, deserializedRoot, response.isBinaryPayload ? "binary" : deserializedType.format)}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (returnType.type === "void") {
|
|
110
|
+
statements.push("return;");
|
|
111
|
+
}
|
|
112
|
+
else if (deserializedType) {
|
|
113
|
+
statements.push(`return ${deserializeResponseValue(context, deserializedType, deserializedRoot, response.isBinaryPayload ? "binary" : deserializedType.format)}`);
|
|
105
114
|
}
|
|
106
115
|
else {
|
|
107
|
-
statements.push(
|
|
108
|
-
[deserializedType], deserializedType.format)}`);
|
|
116
|
+
statements.push("return;");
|
|
109
117
|
}
|
|
110
118
|
return {
|
|
111
119
|
...functionStatement,
|
|
112
120
|
statements
|
|
113
121
|
};
|
|
114
122
|
}
|
|
115
|
-
function getOperationSignatureParameters(operation, clientType) {
|
|
123
|
+
function getOperationSignatureParameters(context, operation, clientType) {
|
|
116
124
|
var _a;
|
|
117
125
|
const optionsType = getOperationOptionsName(operation, true);
|
|
118
126
|
const parameters = new Map();
|
|
@@ -121,14 +129,23 @@ function getOperationSignatureParameters(operation, clientType) {
|
|
|
121
129
|
p.type.type !== "constant" &&
|
|
122
130
|
p.clientDefaultValue === undefined &&
|
|
123
131
|
!p.optional)
|
|
124
|
-
.map((p) =>
|
|
132
|
+
.map((p) => {
|
|
133
|
+
var _a;
|
|
134
|
+
return {
|
|
135
|
+
name: p.clientName,
|
|
136
|
+
type: getTypeExpression(context, (_a = p.tcgcType) !== null && _a !== void 0 ? _a : p.type.tcgcType)
|
|
137
|
+
};
|
|
138
|
+
})
|
|
125
139
|
.forEach((p) => {
|
|
126
140
|
parameters.set(p.name, p);
|
|
127
141
|
});
|
|
128
|
-
if (operation.bodyParameter) {
|
|
142
|
+
if (operation.bodyParameter && operation.bodyParameter.optional === false) {
|
|
129
143
|
parameters.set((_a = operation.bodyParameter) === null || _a === void 0 ? void 0 : _a.clientName, {
|
|
130
144
|
hasQuestionToken: operation.bodyParameter.optional,
|
|
131
|
-
...
|
|
145
|
+
...{
|
|
146
|
+
name: operation.bodyParameter.clientName,
|
|
147
|
+
type: getTypeExpression(context, operation.bodyParameter.type.tcgcType)
|
|
148
|
+
}
|
|
132
149
|
});
|
|
133
150
|
}
|
|
134
151
|
// Add context as the first parameter
|
|
@@ -145,28 +162,34 @@ function getOperationSignatureParameters(operation, clientType) {
|
|
|
145
162
|
/**
|
|
146
163
|
* This operation builds and returns the function declaration for an operation.
|
|
147
164
|
*/
|
|
148
|
-
export function getOperationFunction(operation, clientType) {
|
|
149
|
-
var _a, _b;
|
|
165
|
+
export function getOperationFunction(context, operation, clientType) {
|
|
166
|
+
var _a, _b, _c;
|
|
150
167
|
if (isPagingOnlyOperation(operation)) {
|
|
151
168
|
// Case 1: paging-only operation
|
|
152
|
-
return getPagingOnlyOperationFunction(operation, clientType);
|
|
169
|
+
return getPagingOnlyOperationFunction(context, operation, clientType);
|
|
153
170
|
}
|
|
154
171
|
else if (isLroOnlyOperation(operation)) {
|
|
155
172
|
// Case 2: lro-only operation
|
|
156
|
-
return getLroOnlyOperationFunction(operation, clientType);
|
|
173
|
+
return getLroOnlyOperationFunction(context, operation, clientType);
|
|
157
174
|
}
|
|
158
175
|
else if (isLroAndPagingOperation(operation)) {
|
|
159
176
|
// Case 3: both paging + lro operation is not supported yet so handle them as normal operation and customization may be needed
|
|
160
177
|
// https://github.com/Azure/autorest.typescript/issues/2313
|
|
161
178
|
}
|
|
179
|
+
if (operation.name === "floatSeconds") {
|
|
180
|
+
operation;
|
|
181
|
+
}
|
|
162
182
|
// Extract required parameters
|
|
163
|
-
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
183
|
+
const parameters = getOperationSignatureParameters(context, operation, clientType);
|
|
164
184
|
// TODO: Support operation overloads
|
|
165
185
|
const response = operation.responses[0];
|
|
166
186
|
let returnType = { name: "", type: "void" };
|
|
167
187
|
if ((_a = response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
168
188
|
const type = (_b = extractPagingType(response.type, operation.itemName)) !== null && _b !== void 0 ? _b : response.type;
|
|
169
|
-
returnType =
|
|
189
|
+
returnType = {
|
|
190
|
+
name: (_c = type.name) !== null && _c !== void 0 ? _c : "",
|
|
191
|
+
type: getTypeExpression(context, type.tcgcType)
|
|
192
|
+
};
|
|
170
193
|
}
|
|
171
194
|
const { name, fixme = [] } = getOperationName(operation);
|
|
172
195
|
const functionStatement = {
|
|
@@ -191,10 +214,11 @@ export function getOperationFunction(operation, clientType) {
|
|
|
191
214
|
statements
|
|
192
215
|
};
|
|
193
216
|
}
|
|
194
|
-
function getLroOnlyOperationFunction(operation, clientType) {
|
|
217
|
+
function getLroOnlyOperationFunction(context, operation, clientType) {
|
|
218
|
+
var _a, _b;
|
|
195
219
|
// Extract required parameters
|
|
196
|
-
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
197
|
-
const returnType = buildLroReturnType(operation);
|
|
220
|
+
const parameters = getOperationSignatureParameters(context, operation, clientType);
|
|
221
|
+
const returnType = buildLroReturnType(context, operation);
|
|
198
222
|
const { name, fixme = [] } = getOperationName(operation);
|
|
199
223
|
const pollerLikeReference = resolveReference(AzurePollingDependencies.PollerLike);
|
|
200
224
|
const operationStateReference = resolveReference(AzurePollingDependencies.OperationState);
|
|
@@ -211,6 +235,9 @@ function getLroOnlyOperationFunction(operation, clientType) {
|
|
|
211
235
|
returnType: `${pollerLikeReference}<${operationStateReference}<${returnType.type}>, ${returnType.type}>`
|
|
212
236
|
};
|
|
213
237
|
const getLongRunningPollerReference = resolveReference(PollingHelpers.GetLongRunningPoller);
|
|
238
|
+
const resourceLocationConfig = ((_a = operation.lroMetadata) === null || _a === void 0 ? void 0 : _a.finalStateVia)
|
|
239
|
+
? `resourceLocationConfig: "${(_b = operation.lroMetadata) === null || _b === void 0 ? void 0 : _b.finalStateVia}"`
|
|
240
|
+
: "";
|
|
214
241
|
const statements = [];
|
|
215
242
|
statements.push(`
|
|
216
243
|
|
|
@@ -219,7 +246,8 @@ function getLroOnlyOperationFunction(operation, clientType) {
|
|
|
219
246
|
abortSignal: options?.abortSignal,
|
|
220
247
|
getInitialResponse: () => _${name}Send(${parameters
|
|
221
248
|
.map((p) => p.name)
|
|
222
|
-
.join(", ")})
|
|
249
|
+
.join(", ")}),
|
|
250
|
+
${resourceLocationConfig}
|
|
223
251
|
}) as ${pollerLikeReference}<${operationStateReference}<${returnType.type}>, ${returnType.type}>;
|
|
224
252
|
`);
|
|
225
253
|
return {
|
|
@@ -227,24 +255,30 @@ function getLroOnlyOperationFunction(operation, clientType) {
|
|
|
227
255
|
statements
|
|
228
256
|
};
|
|
229
257
|
}
|
|
230
|
-
function buildLroReturnType(operation) {
|
|
258
|
+
function buildLroReturnType(context, operation) {
|
|
231
259
|
const metadata = operation.lroMetadata;
|
|
232
260
|
if (metadata !== undefined && metadata.finalResult !== undefined) {
|
|
233
261
|
const type = metadata.finalResult;
|
|
234
|
-
return
|
|
262
|
+
return {
|
|
263
|
+
name: type.name,
|
|
264
|
+
type: getTypeExpression(context, type.tcgcType)
|
|
265
|
+
};
|
|
235
266
|
}
|
|
236
267
|
return { name: "", type: "void" };
|
|
237
268
|
}
|
|
238
|
-
function getPagingOnlyOperationFunction(operation, clientType) {
|
|
239
|
-
var _a, _b;
|
|
269
|
+
function getPagingOnlyOperationFunction(context, operation, clientType) {
|
|
270
|
+
var _a, _b, _c;
|
|
240
271
|
// Extract required parameters
|
|
241
|
-
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
272
|
+
const parameters = getOperationSignatureParameters(context, operation, clientType);
|
|
242
273
|
// TODO: Support operation overloads
|
|
243
274
|
const response = operation.responses[0];
|
|
244
275
|
let returnType = { name: "", type: "void" };
|
|
245
276
|
if ((_a = response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
246
277
|
const type = (_b = extractPagingType(response.type, operation.itemName)) !== null && _b !== void 0 ? _b : response.type;
|
|
247
|
-
returnType =
|
|
278
|
+
returnType = {
|
|
279
|
+
name: (_c = type.name) !== null && _c !== void 0 ? _c : "",
|
|
280
|
+
type: getTypeExpression(context, type.tcgcType)
|
|
281
|
+
};
|
|
248
282
|
}
|
|
249
283
|
const { name, fixme = [] } = getOperationName(operation);
|
|
250
284
|
const pagedAsyncIterableIteratorReference = resolveReference(PagingHelpers.PagedAsyncIterableIterator);
|
|
@@ -312,7 +346,7 @@ export function getOperationOptionsName(operation, includeGroupName = false) {
|
|
|
312
346
|
* RLC internally. This will translate High Level parameters into the RLC ones.
|
|
313
347
|
* Figuring out what goes in headers, body, path and qsp.
|
|
314
348
|
*/
|
|
315
|
-
function getRequestParameters(dpgContext, operation
|
|
349
|
+
function getRequestParameters(dpgContext, operation) {
|
|
316
350
|
if (!operation.parameters) {
|
|
317
351
|
return "";
|
|
318
352
|
}
|
|
@@ -328,7 +362,7 @@ function getRequestParameters(dpgContext, operation, runtimeImports) {
|
|
|
328
362
|
param.location === "query" ||
|
|
329
363
|
param.location === "body") {
|
|
330
364
|
parametersImplementation[param.location].push({
|
|
331
|
-
paramMap: getParameterMap(
|
|
365
|
+
paramMap: getParameterMap(dpgContext, param),
|
|
332
366
|
param
|
|
333
367
|
});
|
|
334
368
|
}
|
|
@@ -354,7 +388,7 @@ function getRequestParameters(dpgContext, operation, runtimeImports) {
|
|
|
354
388
|
.join(",\n")}}`;
|
|
355
389
|
}
|
|
356
390
|
else if (operation.bodyParameter !== undefined) {
|
|
357
|
-
paramStr = `${paramStr}${buildBodyParameter(operation.bodyParameter
|
|
391
|
+
paramStr = `${paramStr}${buildBodyParameter(dpgContext, operation.bodyParameter)}`;
|
|
358
392
|
}
|
|
359
393
|
return paramStr;
|
|
360
394
|
}
|
|
@@ -378,86 +412,23 @@ function buildHeaderParameter(program, paramMap, param) {
|
|
|
378
412
|
? `...(${conditions.join(" && ")} ? {${paramMap}} : {})`
|
|
379
413
|
: paramMap;
|
|
380
414
|
}
|
|
381
|
-
function buildBodyParameter(
|
|
382
|
-
|
|
383
|
-
if (!bodyParameter) {
|
|
415
|
+
function buildBodyParameter(context, bodyParameter) {
|
|
416
|
+
if (!bodyParameter || !bodyParameter.type.tcgcType) {
|
|
384
417
|
return "";
|
|
385
418
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
? `${bodyParameter.clientName} === undefined ? ${bodyParameter.clientName} : `
|
|
394
|
-
: "";
|
|
395
|
-
return `\nbody: ${optionalBody}{${bodyParts.join(",\n")}},`;
|
|
396
|
-
}
|
|
397
|
-
else if (bodyParameter && bodyParts.length === 0) {
|
|
398
|
-
return `\nbody: ${bodyParameter.clientName},`;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else if (isDiscriminatedUnion(bodyParameter.type.tcgcType)) {
|
|
402
|
-
const serializerName = toCamelCase(`${bodyParameter.type.name}Serializer`);
|
|
403
|
-
addImportToSpecifier("modularModel", runtimeImports, serializerName);
|
|
404
|
-
return `\nbody: ${serializerName}(${bodyParameter.clientName}),`;
|
|
405
|
-
}
|
|
406
|
-
else if ((bodyParameter.type.type === "model" &&
|
|
407
|
-
(bodyParameter.type.aliasType ||
|
|
408
|
-
allParents.some((p) => p.type === "dict"))) ||
|
|
409
|
-
bodyParameter.type.type === "dict") {
|
|
410
|
-
const elementSerializerName = ((_a = bodyParameter.type.elementType) === null || _a === void 0 ? void 0 : _a.type) === "model"
|
|
411
|
-
? toCamelCase(`${bodyParameter.type.elementType.name}Serializer`)
|
|
412
|
-
: "";
|
|
413
|
-
let modelSerializerName = "";
|
|
414
|
-
if (bodyParameter.type.type !== "dict") {
|
|
415
|
-
modelSerializerName = toCamelCase(`${bodyParameter.type.name}Serializer`);
|
|
416
|
-
}
|
|
417
|
-
if (modelSerializerName) {
|
|
418
|
-
return `\nbody: ${modelSerializerName}(${bodyParameter.clientName}),`;
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
// Need to do this so that Records are compatible with additional properties of other types
|
|
422
|
-
// this should check for compatibility mode once we support the additionalProperties property
|
|
423
|
-
return `\nbody: serializeRecord(${bodyParameter.clientName} as any, ${elementSerializerName}) as any,`;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (bodyParameter.type.type === "list") {
|
|
427
|
-
if (((_b = bodyParameter.type.elementType) === null || _b === void 0 ? void 0 : _b.type) === "model" &&
|
|
428
|
-
!bodyParameter.type.elementType.aliasType) {
|
|
429
|
-
const { propertiesStr: bodyParts, directAssignment } = getRequestModelMapping(bodyParameter.type.elementType, "p", runtimeImports, [bodyParameter.type.elementType]);
|
|
430
|
-
const mapBody = directAssignment === true
|
|
431
|
-
? bodyParts.join(", ")
|
|
432
|
-
: `{ ${bodyParts.join(", ")} }`;
|
|
433
|
-
let bodyElementStatement = "";
|
|
434
|
-
if (isTypeNullable(bodyParameter.type.elementType) ||
|
|
435
|
-
bodyParameter.type.elementType.optional) {
|
|
436
|
-
bodyElementStatement = `!p ? p : `;
|
|
437
|
-
}
|
|
438
|
-
return `\nbody: (${bodyParameter.clientName} ?? []).map((p) => {
|
|
439
|
-
return ${bodyElementStatement}${mapBody};
|
|
440
|
-
}),`;
|
|
441
|
-
}
|
|
442
|
-
return `\nbody: ${bodyParameter.clientName},`;
|
|
419
|
+
const serializerFunctionName = buildModelSerializer(context, bodyParameter.type.tcgcType, false, true);
|
|
420
|
+
const bodyNameExpression = bodyParameter.optional
|
|
421
|
+
? `options["${bodyParameter.clientName}"]`
|
|
422
|
+
: bodyParameter.clientName;
|
|
423
|
+
const nullOrUndefinedPrefix = getPropertySerializationPrefix(bodyParameter, bodyParameter.optional ? "options" : undefined);
|
|
424
|
+
if (serializerFunctionName) {
|
|
425
|
+
return `\nbody: ${nullOrUndefinedPrefix}${serializerFunctionName}(${bodyNameExpression}),`;
|
|
443
426
|
}
|
|
444
|
-
if (bodyParameter.type.
|
|
445
|
-
|
|
446
|
-
const dependencies = useDependencies();
|
|
447
|
-
const uint8ArrayToStringReference = resolveReference(dependencies.uint8ArrayToString);
|
|
448
|
-
return bodyParameter.optional
|
|
449
|
-
? `body: typeof ${bodyParameter.clientName} === 'string'
|
|
450
|
-
? ${uint8ArrayToStringReference}(${bodyParameter.clientName}, "${getEncodingFormat(bodyParameter)}")
|
|
451
|
-
: ${bodyParameter.clientName}`
|
|
452
|
-
: `body: ${uint8ArrayToStringReference}(${bodyParameter.clientName}, "${getEncodingFormat(bodyParameter)}")`;
|
|
427
|
+
else if (isAzureCoreErrorType(context.program, bodyParameter.type.__raw)) {
|
|
428
|
+
return `\nbody: ${nullOrUndefinedPrefix}${bodyNameExpression},`;
|
|
453
429
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
if (bodyParameter) {
|
|
458
|
-
return `\nbody: ${bodyParameter.clientName},`;
|
|
459
|
-
}
|
|
460
|
-
return "";
|
|
430
|
+
const serializedBody = serializeRequestValue(context, bodyParameter.type, bodyNameExpression, !bodyParameter.optional, bodyParameter.isBinaryPayload ? "binary" : bodyParameter.format);
|
|
431
|
+
return `\nbody: ${serializedBody === bodyNameExpression ? "" : nullOrUndefinedPrefix}${serializedBody},`;
|
|
461
432
|
}
|
|
462
433
|
function getEncodingFormat(type) {
|
|
463
434
|
var _a;
|
|
@@ -470,23 +441,23 @@ function getEncodingFormat(type) {
|
|
|
470
441
|
/**
|
|
471
442
|
* This function helps with renames, translating client names to rest api names
|
|
472
443
|
*/
|
|
473
|
-
export function getParameterMap(
|
|
444
|
+
export function getParameterMap(context, param) {
|
|
474
445
|
if (isConstant(param)) {
|
|
475
446
|
return getConstantValue(param);
|
|
476
447
|
}
|
|
477
448
|
if (hasCollectionFormatInfo(param.location, param.format)) {
|
|
478
|
-
return getCollectionFormat(
|
|
449
|
+
return getCollectionFormat(context, param);
|
|
479
450
|
}
|
|
480
451
|
// if the parameter or property is optional, we don't need to handle the default value
|
|
481
452
|
if (isOptional(param)) {
|
|
482
|
-
return getOptional(
|
|
453
|
+
return getOptional(context, param);
|
|
483
454
|
}
|
|
484
455
|
if (isRequired(param)) {
|
|
485
|
-
return getRequired(
|
|
456
|
+
return getRequired(context, param);
|
|
486
457
|
}
|
|
487
458
|
throw new Error(`Parameter ${param.clientName} is not supported`);
|
|
488
459
|
}
|
|
489
|
-
function getCollectionFormat(
|
|
460
|
+
function getCollectionFormat(context, param) {
|
|
490
461
|
var _a, _b;
|
|
491
462
|
const collectionInfo = getCollectionFormatHelper(param.location, (_a = param.format) !== null && _a !== void 0 ? _a : "");
|
|
492
463
|
if (!collectionInfo) {
|
|
@@ -495,9 +466,9 @@ function getCollectionFormat(param, runtimeImports) {
|
|
|
495
466
|
const isMulti = ((_b = param.format) !== null && _b !== void 0 ? _b : "").toLowerCase() === "multi";
|
|
496
467
|
const additionalParam = isMulti ? `, "${param.restApiName}"` : "";
|
|
497
468
|
if (!param.optional) {
|
|
498
|
-
return `"${param.restApiName}": ${collectionInfo}(${serializeRequestValue(param.type, param.clientName,
|
|
469
|
+
return `"${param.restApiName}": ${collectionInfo}(${serializeRequestValue(context, param.type, param.clientName, true, param.format)}${additionalParam})`;
|
|
499
470
|
}
|
|
500
|
-
return `"${param.restApiName}": options?.${param.clientName} !== undefined ? ${collectionInfo}(${serializeRequestValue(param.type, "options?." + param.clientName,
|
|
471
|
+
return `"${param.restApiName}": options?.${param.clientName} !== undefined ? ${collectionInfo}(${serializeRequestValue(context, param.type, "options?." + param.clientName, false, param.format)}${additionalParam}): undefined`;
|
|
501
472
|
}
|
|
502
473
|
function isContentType(param) {
|
|
503
474
|
return (param.location === "header" &&
|
|
@@ -518,12 +489,12 @@ function getContentTypeValue(param) {
|
|
|
518
489
|
function isRequired(param) {
|
|
519
490
|
return !param.optional;
|
|
520
491
|
}
|
|
521
|
-
function getRequired(
|
|
492
|
+
function getRequired(context, param) {
|
|
522
493
|
if (param.type.type === "model") {
|
|
523
|
-
const { propertiesStr } = getRequestModelMapping(param.type, param.clientName
|
|
494
|
+
const { propertiesStr } = getRequestModelMapping(context, param.type, param.clientName);
|
|
524
495
|
return `"${param.restApiName}": { ${propertiesStr.join(",")} }`;
|
|
525
496
|
}
|
|
526
|
-
return `"${param.restApiName}": ${serializeRequestValue(param.type, param.clientName,
|
|
497
|
+
return `"${param.restApiName}": ${serializeRequestValue(context, param.type, param.clientName, true, param.format === undefined &&
|
|
527
498
|
param.location === "header" &&
|
|
528
499
|
param.type.type === "datetime"
|
|
529
500
|
? "headerDefault"
|
|
@@ -543,9 +514,9 @@ function isConstant(param) {
|
|
|
543
514
|
function isOptional(param) {
|
|
544
515
|
return Boolean(param.optional);
|
|
545
516
|
}
|
|
546
|
-
function getOptional(
|
|
517
|
+
function getOptional(context, param) {
|
|
547
518
|
if (param.type.type === "model") {
|
|
548
|
-
const { propertiesStr, directAssignment } = getRequestModelMapping(param.type, "options?." + param.clientName + "
|
|
519
|
+
const { propertiesStr, directAssignment } = getRequestModelMapping(context, param.type, "options?." + param.clientName + "?.");
|
|
549
520
|
const serializeContent = directAssignment === true
|
|
550
521
|
? propertiesStr.join(",")
|
|
551
522
|
: `{${propertiesStr.join(",")}}`;
|
|
@@ -557,7 +528,7 @@ function getOptional(param, runtimeImports) {
|
|
|
557
528
|
? `options?.${param.clientName} ?? "${param.clientDefaultValue}"`
|
|
558
529
|
: `options?.${param.clientName}`}`;
|
|
559
530
|
}
|
|
560
|
-
return `"${param.restApiName}": ${serializeRequestValue(param.type, `options?.${param.clientName}`,
|
|
531
|
+
return `"${param.restApiName}": ${serializeRequestValue(context, param.type, `options?.${param.clientName}`, false, param.format === undefined &&
|
|
561
532
|
param.location === "header" &&
|
|
562
533
|
param.type.type === "datetime"
|
|
563
534
|
? "headerDefault"
|
|
@@ -567,124 +538,77 @@ function getOptional(param, runtimeImports) {
|
|
|
567
538
|
* Builds the assignment for when a property or parameter has a default value
|
|
568
539
|
*/
|
|
569
540
|
function getDefaultValue(param) {
|
|
570
|
-
var _a
|
|
571
|
-
return (
|
|
572
|
-
undefined
|
|
573
|
-
? `${param.optional ? "??" : ""} "${(_b = param.clientDefaultValue) !== null && _b !== void 0 ? _b : param.type.clientDefaultValue}"`
|
|
574
|
-
: "";
|
|
541
|
+
var _a;
|
|
542
|
+
return (_a = param.clientDefaultValue) !== null && _a !== void 0 ? _a : param.type.clientDefaultValue;
|
|
575
543
|
}
|
|
576
544
|
/**
|
|
577
545
|
* Extracts the path parameters
|
|
578
546
|
*/
|
|
579
|
-
function getPathParameters(operation) {
|
|
547
|
+
function getPathParameters(dpgContext, operation) {
|
|
580
548
|
if (!operation.parameters) {
|
|
581
549
|
return "";
|
|
582
550
|
}
|
|
583
551
|
let pathParams = "";
|
|
584
552
|
for (const param of operation.parameters) {
|
|
585
553
|
if (param.location === "path") {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
554
|
+
// Path parameters cannot be optional
|
|
555
|
+
if (param.optional) {
|
|
556
|
+
reportDiagnostic(dpgContext.program, {
|
|
557
|
+
code: "optional-path-param",
|
|
558
|
+
target: NoTarget,
|
|
559
|
+
format: {
|
|
560
|
+
paramName: param.clientName
|
|
561
|
+
}
|
|
562
|
+
});
|
|
594
563
|
}
|
|
564
|
+
pathParams += `${pathParams !== "" ? "," : ""} ${getPathParamExpr(param, getDefaultValue(param))}`;
|
|
595
565
|
}
|
|
596
566
|
}
|
|
597
567
|
return pathParams;
|
|
598
568
|
}
|
|
569
|
+
function getPathParamExpr(param, defaultValue) {
|
|
570
|
+
const value = defaultValue
|
|
571
|
+
? typeof defaultValue === "string"
|
|
572
|
+
? `options[${param.clientName}] ?? "${defaultValue}"`
|
|
573
|
+
: `options[${param.clientName}] ?? ${defaultValue}`
|
|
574
|
+
: param.clientName;
|
|
575
|
+
if (param.skipUrlEncoding === true) {
|
|
576
|
+
return `{value: ${value}, allowReserved: true}`;
|
|
577
|
+
}
|
|
578
|
+
return value;
|
|
579
|
+
}
|
|
599
580
|
function getNullableCheck(name, type) {
|
|
600
581
|
if (!isTypeNullable(type)) {
|
|
601
582
|
return "";
|
|
602
583
|
}
|
|
603
584
|
return `${name} === null ? null :`;
|
|
604
585
|
}
|
|
605
|
-
export function getRequestModelMapping(modelPropertyType, propertyPath = "body"
|
|
606
|
-
var _a
|
|
586
|
+
export function getRequestModelMapping(context, modelPropertyType, propertyPath = "body") {
|
|
587
|
+
var _a;
|
|
607
588
|
const props = [];
|
|
608
589
|
const allParents = getAllAncestors(modelPropertyType);
|
|
609
590
|
const properties = (_a = getAllProperties(modelPropertyType, allParents)) !== null && _a !== void 0 ? _a : [];
|
|
610
591
|
if (properties.length <= 0) {
|
|
611
592
|
return { propertiesStr: [] };
|
|
612
593
|
}
|
|
613
|
-
let serializerName = "name" in modelPropertyType && modelPropertyType.name
|
|
614
|
-
? `${toCamelCase(modelPropertyType.name)}Serializer`
|
|
615
|
-
: undefined;
|
|
616
|
-
if (isSpecialHandledUnion(modelPropertyType)) {
|
|
617
|
-
serializerName =
|
|
618
|
-
serializerName !== null && serializerName !== void 0 ? serializerName : getDeserializeFunctionName(modelPropertyType, "serialize");
|
|
619
|
-
const definition = `${serializerName}(${propertyPath.replace(/\?$/, "")})`;
|
|
620
|
-
props.push(definition);
|
|
621
|
-
return { propertiesStr: props, directAssignment: true };
|
|
622
|
-
}
|
|
623
594
|
for (const property of properties) {
|
|
624
595
|
if (property.readonly) {
|
|
625
596
|
continue;
|
|
626
597
|
}
|
|
598
|
+
const dot = propertyPath.endsWith("?") ? "." : "";
|
|
599
|
+
const propertyPathWithDot = `${propertyPath ? `${propertyPath}${dot}` : `${dot}`}`;
|
|
627
600
|
const nullOrUndefinedPrefix = getPropertySerializationPrefix(property, propertyPath);
|
|
628
|
-
const propertyFullName = getPropertyFullName(property,
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
|
|
633
|
-
}
|
|
634
|
-
else if (typeStack.includes(property.type)) {
|
|
635
|
-
const isSpecialModel = isSpecialUnionVariant(property.type);
|
|
636
|
-
definition = `"${property.restApiName}": ${!property.optional
|
|
637
|
-
? `${propertyFullName}${isSpecialModel ? " as any" : ""}`
|
|
638
|
-
: `!${propertyFullName} ? undefined : ${propertyFullName}${isSpecialModel ? " as any" : ""}`}`;
|
|
639
|
-
}
|
|
640
|
-
else if (isPolymorphicUnion(property.type)) {
|
|
641
|
-
const deserializeFunctionName = property.type.name
|
|
642
|
-
? `${toCamelCase(property.type.name)}Serializer`
|
|
643
|
-
: getDeserializeFunctionName(property.type, "serialize");
|
|
644
|
-
definition = `"${property.restApiName}": ${nullOrUndefinedPrefix}${deserializeFunctionName}(${propertyFullName})`;
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
if (property.type.name) {
|
|
648
|
-
serializerName = `${toCamelCase(property.type.name)}Serializer`;
|
|
649
|
-
definition = `"${property.restApiName}": ${nullOrUndefinedPrefix}${serializerName}(${propertyPath}.${property.clientName})`;
|
|
650
|
-
}
|
|
651
|
-
else {
|
|
652
|
-
const { propertiesStr, directAssignment } = getRequestModelMapping(property.type, `${propertyPath}.${property.clientName}${property.optional ? "?" : ""}`, runtimeImports, [...typeStack, property.type]);
|
|
653
|
-
const serializeContent = directAssignment === true
|
|
654
|
-
? propertiesStr.join(",")
|
|
655
|
-
: `{${propertiesStr.join(",")}}`;
|
|
656
|
-
definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${serializeContent}`;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
props.push(definition);
|
|
660
|
-
}
|
|
661
|
-
else if (typeStack.includes(property.type)) {
|
|
662
|
-
const isSpecialModel = isSpecialUnionVariant(property.type);
|
|
663
|
-
const definition = `"${property.restApiName}": ${!property.optional
|
|
664
|
-
? `${propertyFullName}${isSpecialModel ? " as any" : ""}`
|
|
665
|
-
: `!${propertyFullName} ? undefined : ${propertyFullName}${isSpecialModel ? " as any" : ""}`}`;
|
|
666
|
-
props.push(definition);
|
|
667
|
-
}
|
|
668
|
-
else if (property.type.type === "dict") {
|
|
669
|
-
const modelName = (_b = property.type.elementType) === null || _b === void 0 ? void 0 : _b.name;
|
|
670
|
-
serializerName = modelName ? `${toCamelCase(modelName)}Serializer` : "";
|
|
671
|
-
// definition = `"${property.restApiName}": ${nullOrUndefinedPrefix}${serializerName}(${propertyPath}.${property.clientName})`;
|
|
672
|
-
const statement = `"${property.restApiName}": ${nullOrUndefinedPrefix} serializeRecord(${propertyFullName} as any, ${serializerName}) as any`;
|
|
673
|
-
// addImportToSpecifier(
|
|
674
|
-
// "serializerHelpers",
|
|
675
|
-
// runtimeImports,
|
|
676
|
-
// "serializeRecord"
|
|
677
|
-
// );
|
|
678
|
-
addImportToSpecifier("modularModel", runtimeImports, serializerName);
|
|
679
|
-
props.push(statement);
|
|
601
|
+
const propertyFullName = getPropertyFullName(property, propertyPathWithDot);
|
|
602
|
+
const serializeFunctionName = buildModelSerializer(context, property.type.tcgcType, false, true);
|
|
603
|
+
if (serializeFunctionName) {
|
|
604
|
+
props.push(`"${property.restApiName}": ${nullOrUndefinedPrefix}${serializeFunctionName}(${propertyFullName})`);
|
|
680
605
|
}
|
|
681
|
-
else if (
|
|
682
|
-
props.push(`"${property.restApiName}": ${nullOrUndefinedPrefix}${
|
|
606
|
+
else if (isAzureCoreErrorType(context.program, property.type.__raw)) {
|
|
607
|
+
props.push(`"${property.restApiName}": ${nullOrUndefinedPrefix}${propertyFullName}`);
|
|
683
608
|
}
|
|
684
609
|
else {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
props.push(`"${property.restApiName}": ${serializeRequestValue(property.type, clientValue, runtimeImports, !property.optional, [...typeStack, property.type], property.format)}`);
|
|
610
|
+
const serializedValue = serializeRequestValue(context, property.type, propertyFullName, !property.optional, property.format);
|
|
611
|
+
props.push(`"${property.restApiName}": ${serializedValue}`);
|
|
688
612
|
}
|
|
689
613
|
}
|
|
690
614
|
return { propertiesStr: props };
|
|
@@ -693,53 +617,29 @@ export function getRequestModelMapping(modelPropertyType, propertyPath = "body",
|
|
|
693
617
|
* This function helps translating an RLC response to an HLC response,
|
|
694
618
|
* extracting properties from body and headers and building the HLC response object
|
|
695
619
|
*/
|
|
696
|
-
export function getResponseMapping(type, propertyPath = "result.body"
|
|
620
|
+
export function getResponseMapping(context, type, propertyPath = "result.body") {
|
|
697
621
|
var _a;
|
|
698
622
|
const allParents = getAllAncestors(type);
|
|
699
623
|
const properties = (_a = getAllProperties(type, allParents)) !== null && _a !== void 0 ? _a : [];
|
|
700
|
-
if (typeStack.length <= 0) {
|
|
701
|
-
typeStack.push(type);
|
|
702
|
-
}
|
|
703
624
|
const props = [];
|
|
704
625
|
for (const property of properties) {
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
: `!${propertyFullName} ? undefined : ${propertyFullName}${isSpecialModel ? " as any" : ""}`}`;
|
|
717
|
-
}
|
|
718
|
-
else if (isSpecialHandledUnion(property.type)) {
|
|
719
|
-
const nullOrUndefinedPrefix = getPropertySerializationPrefix(property, propertyPath);
|
|
720
|
-
const deserializeFunctionName = getDeserializeFunctionName(property.type, "deserialize");
|
|
721
|
-
definition = `"${property.clientName}": ${nullOrUndefinedPrefix}${deserializeFunctionName}(${propertyFullName})`;
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
definition = `"${property.clientName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} {${getResponseMapping(property.type, `${propertyPath}.${property.restApiName}${property.optional ? "?" : ""}`, runtimeImports, [...typeStack, property.type])}}`;
|
|
725
|
-
}
|
|
726
|
-
props.push(definition);
|
|
626
|
+
const dot = propertyPath.endsWith("?") ? "." : "";
|
|
627
|
+
const restValue = `${propertyPath ? `${propertyPath}${dot}` : `${dot}`}["${property.restApiName}"]`;
|
|
628
|
+
const nullOrUndefinedPrefix = property.optional || isTypeNullable(property.type)
|
|
629
|
+
? `!${restValue}? ${restValue}: `
|
|
630
|
+
: "";
|
|
631
|
+
const deserializeFunctionName = buildModelDeserializer(context, property.type.tcgcType, false, true);
|
|
632
|
+
if (deserializeFunctionName) {
|
|
633
|
+
props.push(`"${property.clientName}": ${nullOrUndefinedPrefix}${deserializeFunctionName}(${restValue})`);
|
|
634
|
+
}
|
|
635
|
+
else if (isAzureCoreErrorType(context.program, property.type.__raw)) {
|
|
636
|
+
props.push(`"${property.clientName}": ${nullOrUndefinedPrefix}${restValue}`);
|
|
727
637
|
}
|
|
728
638
|
else {
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
if (typeStack.includes(property.type)) {
|
|
732
|
-
const isSpecialModel = isSpecialUnionVariant(property.type);
|
|
733
|
-
props.push(`"${property.clientName}": ${!property.optional
|
|
734
|
-
? `${propertyFullName}${isSpecialModel ? " as any" : ""}`
|
|
735
|
-
: `!${propertyFullName} ? undefined : ${propertyFullName}${isSpecialModel ? " as any" : ""}`}`);
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
props.push(`"${property.clientName}": ${deserializeResponseValue(property.type, restValue, runtimeImports, property.optional !== undefined ? !property.optional : false, [...typeStack, property.type], property.format)}`);
|
|
739
|
-
}
|
|
639
|
+
const deserializeValue = deserializeResponseValue(context, property.type, `${propertyPath}${dot}["${property.restApiName}"]`, property.format);
|
|
640
|
+
props.push(`"${property.clientName}": ${deserializeValue === `${propertyPath}${dot}["${property.restApiName}"]` ? "" : nullOrUndefinedPrefix}${deserializeValue}`);
|
|
740
641
|
}
|
|
741
642
|
}
|
|
742
|
-
typeStack.pop();
|
|
743
643
|
return props;
|
|
744
644
|
}
|
|
745
645
|
/**
|
|
@@ -747,86 +647,70 @@ export function getResponseMapping(type, propertyPath = "result.body", runtimeIm
|
|
|
747
647
|
* We need to drill down into Array elements to make sure that the element type is
|
|
748
648
|
* deserialized correctly
|
|
749
649
|
*/
|
|
750
|
-
export function
|
|
751
|
-
var _a, _b, _c, _d
|
|
752
|
-
const
|
|
753
|
-
const nullablePrefix = isTypeNullable(type) ? `${restValue} === null` : "";
|
|
650
|
+
export function serializeRequestValue(context, type, clientValue, required, format) {
|
|
651
|
+
var _a, _b, _c, _d;
|
|
652
|
+
const getSdkType = useSdkTypes();
|
|
754
653
|
const dependencies = useDependencies();
|
|
755
|
-
const
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
: `${requiredPrefix}${nullablePrefix}`;
|
|
654
|
+
const nullOrUndefinedPrefix = isTypeNullable(type) || type.optional || !required
|
|
655
|
+
? `!${clientValue}? ${clientValue}: `
|
|
656
|
+
: "";
|
|
759
657
|
switch (type.type) {
|
|
760
658
|
case "datetime":
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
659
|
+
switch ((_a = type.format) !== null && _a !== void 0 ? _a : format) {
|
|
660
|
+
case "rfc7231":
|
|
661
|
+
case "headerDefault":
|
|
662
|
+
return `${nullOrUndefinedPrefix}${clientValue}.toUTCString()`;
|
|
663
|
+
case "unixTimestamp":
|
|
664
|
+
return `${nullOrUndefinedPrefix}${clientValue}.getTime()`;
|
|
665
|
+
case "rfc3339":
|
|
666
|
+
default:
|
|
667
|
+
return `${getNullableCheck(clientValue, type)} ${clientValue}${required ? "" : "?"}.toISOString()`;
|
|
668
|
+
}
|
|
766
669
|
case "list": {
|
|
767
|
-
const prefix =
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}{${getResponseMapping(type.elementType, "p", runtimeImports, [...typeStack, type.elementType])}}})`;
|
|
670
|
+
const prefix = nullOrUndefinedPrefix + clientValue;
|
|
671
|
+
if (type.elementType) {
|
|
672
|
+
const elementNullOrUndefinedPrefix = isTypeNullable(type.elementType) || type.elementType.optional
|
|
673
|
+
? "!p ? p : "
|
|
674
|
+
: "";
|
|
675
|
+
const serializeFunctionName = buildModelSerializer(context, type.elementType.tcgcType, false, true);
|
|
676
|
+
if (serializeFunctionName) {
|
|
677
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}${serializeFunctionName}(p)})`;
|
|
776
678
|
}
|
|
777
|
-
else if (
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
}
|
|
782
|
-
const deserializeFunctionName = getDeserializeFunctionName(type.elementType, "deserialize");
|
|
783
|
-
return `${prefix}.map((p: any) => ${nullOrUndefinedPrefix}${deserializeFunctionName}(p))`;
|
|
679
|
+
else if (isAzureCoreErrorType(context.program, type.elementType.__raw)) {
|
|
680
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}p})`;
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}${serializeRequestValue(context, type.elementType, "p", true, (_b = type.elementType) === null || _b === void 0 ? void 0 : _b.format)}})`;
|
|
784
684
|
}
|
|
785
|
-
return `${prefix}`;
|
|
786
|
-
}
|
|
787
|
-
else if (needsDeserialize(type.elementType) &&
|
|
788
|
-
!((_b = type.elementType) === null || _b === void 0 ? void 0 : _b.aliasType)) {
|
|
789
|
-
return `${prefix}.map((p: any) => ${deserializeResponseValue(type.elementType, "p", runtimeImports, true, [...typeStack, type.elementType], (_c = type.elementType) === null || _c === void 0 ? void 0 : _c.format)})`;
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
return restValue;
|
|
793
685
|
}
|
|
686
|
+
return clientValue;
|
|
794
687
|
}
|
|
795
688
|
case "byte-array":
|
|
796
689
|
if (format !== "binary") {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
690
|
+
const uint8ArrayToStringReference = resolveReference(dependencies.uint8ArrayToString);
|
|
691
|
+
return required
|
|
692
|
+
? `${getNullableCheck(clientValue, type)} ${uint8ArrayToStringReference}(${clientValue}, "${(_c = getEncodingFormat({ format })) !== null && _c !== void 0 ? _c : "base64"}")`
|
|
693
|
+
: `${nullOrUndefinedPrefix} ${uint8ArrayToStringReference}(${clientValue}, "${(_d = getEncodingFormat({ format })) !== null && _d !== void 0 ? _d : "base64"}")`;
|
|
800
694
|
}
|
|
801
|
-
return
|
|
695
|
+
return clientValue;
|
|
802
696
|
case "combined":
|
|
803
697
|
if (isNormalUnion(type)) {
|
|
804
|
-
return `${
|
|
698
|
+
return `${clientValue}`;
|
|
805
699
|
}
|
|
806
700
|
else if (isSpecialHandledUnion(type)) {
|
|
807
|
-
const
|
|
808
|
-
|
|
701
|
+
const sdkType = getSdkType(type.__raw);
|
|
702
|
+
const serializerRefkey = refkey(sdkType, "serializer");
|
|
703
|
+
const serializeFunctionName = resolveReference(serializerRefkey);
|
|
704
|
+
return `${serializeFunctionName}(${clientValue})`;
|
|
809
705
|
}
|
|
810
706
|
else {
|
|
811
|
-
return `${
|
|
812
|
-
}
|
|
813
|
-
case "enum":
|
|
814
|
-
if (!type.isFixed && !type.isNonExhaustive) {
|
|
815
|
-
return `${restValue} as ${type.name}`;
|
|
816
|
-
}
|
|
817
|
-
return restValue;
|
|
818
|
-
case "model":
|
|
819
|
-
if (type.discriminator) {
|
|
820
|
-
const discriminatorProp = (_d = type.properties) === null || _d === void 0 ? void 0 : _d.filter((p) => p.restApiName === type.discriminator);
|
|
821
|
-
if ((discriminatorProp === null || discriminatorProp === void 0 ? void 0 : discriminatorProp.length) === 1 &&
|
|
822
|
-
((_e = discriminatorProp[0]) === null || _e === void 0 ? void 0 : _e.type.isFixed) === false &&
|
|
823
|
-
discriminatorProp[0].type.isNonExhaustive === false) {
|
|
824
|
-
return `${restValue} as ${type.name}`;
|
|
825
|
-
}
|
|
707
|
+
return `${clientValue} as any`;
|
|
826
708
|
}
|
|
827
|
-
return restValue;
|
|
828
709
|
default:
|
|
829
|
-
|
|
710
|
+
if (clientValue === "constructorParam") {
|
|
711
|
+
return `${clientValue} as any`;
|
|
712
|
+
}
|
|
713
|
+
return clientValue;
|
|
830
714
|
}
|
|
831
715
|
}
|
|
832
716
|
/**
|
|
@@ -834,97 +718,68 @@ export function deserializeResponseValue(type, restValue, runtimeImports, requir
|
|
|
834
718
|
* We need to drill down into Array elements to make sure that the element type is
|
|
835
719
|
* deserialized correctly
|
|
836
720
|
*/
|
|
837
|
-
export function
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
: `${requiredPrefix}${nullablePrefix}`;
|
|
721
|
+
export function deserializeResponseValue(context, type, restValue, format) {
|
|
722
|
+
const dependencies = useDependencies();
|
|
723
|
+
const stringToUint8ArrayReference = resolveReference(dependencies.stringToUint8Array);
|
|
724
|
+
const nullOrUndefinedPrefix = isTypeNullable(type) || type.optional
|
|
725
|
+
? `!${restValue}? ${restValue}: `
|
|
726
|
+
: "";
|
|
844
727
|
switch (type.type) {
|
|
845
728
|
case "datetime":
|
|
846
|
-
|
|
847
|
-
case "rfc7231":
|
|
848
|
-
case "headerDefault":
|
|
849
|
-
return `${clientValue}${required ? "" : "?"}.toUTCString()`;
|
|
850
|
-
case "unixTimestamp":
|
|
851
|
-
return `${clientValue}${required ? "" : "?"}.getTime()`;
|
|
852
|
-
case "rfc3339":
|
|
853
|
-
default:
|
|
854
|
-
return `${getNullableCheck(clientValue, type)} ${clientValue}${required ? "" : "?"}.toISOString()`;
|
|
855
|
-
}
|
|
729
|
+
return `${nullOrUndefinedPrefix} new Date(${restValue})`;
|
|
856
730
|
case "list": {
|
|
857
|
-
const prefix =
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
? "!p ? p :"
|
|
863
|
-
: "";
|
|
864
|
-
if (!type.elementType.name) {
|
|
865
|
-
// If it is an anonymous model we need to serialize inline
|
|
866
|
-
const { propertiesStr } = getRequestModelMapping(type.elementType, "p", runtimeImports, [...typeStack, type.elementType]);
|
|
867
|
-
return `${prefix}.map(p => { return ${elementNullOrUndefinedPrefix}{${propertiesStr}}})`;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
// When it is not anonymous we can hand it off to the serializer function
|
|
871
|
-
return `${prefix}.map(${toCamelCase(type.elementType.name + "Serializer")})`;
|
|
872
|
-
}
|
|
731
|
+
const prefix = nullOrUndefinedPrefix + restValue;
|
|
732
|
+
let elementNullOrUndefinedPrefix = "";
|
|
733
|
+
if (type.elementType &&
|
|
734
|
+
(isTypeNullable(type.elementType) || type.elementType.optional)) {
|
|
735
|
+
elementNullOrUndefinedPrefix = "!p ? p :";
|
|
873
736
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
737
|
+
const deserializeFunctionName = type.elementType
|
|
738
|
+
? buildModelDeserializer(context, type.elementType.tcgcType, false, true)
|
|
739
|
+
: undefined;
|
|
740
|
+
if (deserializeFunctionName) {
|
|
741
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}${deserializeFunctionName}(p)})`;
|
|
877
742
|
}
|
|
878
|
-
else if (
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
const serializeFunctionName = ((_f = type.elementType) === null || _f === void 0 ? void 0 : _f.name)
|
|
885
|
-
? `${toCamelCase(type.elementType.name)}Serializer`
|
|
886
|
-
: getDeserializeFunctionName(type.elementType, "serialize");
|
|
887
|
-
return `${prefix}.map(p => ${nullOrUndefinedPrefix}${serializeFunctionName}(p))`;
|
|
743
|
+
else if (type.elementType &&
|
|
744
|
+
isAzureCoreErrorType(context.program, type.elementType.__raw)) {
|
|
745
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}p})`;
|
|
746
|
+
}
|
|
747
|
+
else if (type.elementType) {
|
|
748
|
+
return `${prefix}.map((p: any) => { return ${elementNullOrUndefinedPrefix}${deserializeResponseValue(context, type.elementType, "p", type.format)}})`;
|
|
888
749
|
}
|
|
889
750
|
else {
|
|
890
|
-
return
|
|
751
|
+
return restValue;
|
|
891
752
|
}
|
|
892
753
|
}
|
|
893
754
|
case "byte-array":
|
|
894
755
|
if (format !== "binary") {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
? `${getNullableCheck(clientValue, type)} ${uint8ArrayToStringReference}(${clientValue}, "${(_g = getEncodingFormat({ format })) !== null && _g !== void 0 ? _g : "base64"}")`
|
|
899
|
-
: `${clientValue} !== undefined ? ${uint8ArrayToStringReference}(${clientValue}, "${(_h = getEncodingFormat({ format })) !== null && _h !== void 0 ? _h : "base64"}"): undefined`;
|
|
756
|
+
return `typeof ${restValue} === 'string'
|
|
757
|
+
? ${stringToUint8ArrayReference}(${restValue}, "${format !== null && format !== void 0 ? format : "base64"}")
|
|
758
|
+
: ${restValue}`;
|
|
900
759
|
}
|
|
901
|
-
return
|
|
760
|
+
return restValue;
|
|
902
761
|
case "combined":
|
|
903
762
|
if (isNormalUnion(type)) {
|
|
904
|
-
return `${
|
|
763
|
+
return `${restValue}`;
|
|
905
764
|
}
|
|
906
765
|
else if (isSpecialHandledUnion(type)) {
|
|
907
|
-
const
|
|
908
|
-
?
|
|
909
|
-
:
|
|
910
|
-
|
|
766
|
+
const deserializeFunctionName = type
|
|
767
|
+
? buildModelDeserializer(context, type.tcgcType, false, true)
|
|
768
|
+
: undefined;
|
|
769
|
+
if (deserializeFunctionName) {
|
|
770
|
+
return `${deserializeFunctionName}(${restValue})`;
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
return `${restValue} as any`;
|
|
774
|
+
}
|
|
911
775
|
}
|
|
912
776
|
else {
|
|
913
|
-
return `${
|
|
777
|
+
return `${restValue} as any`;
|
|
914
778
|
}
|
|
915
779
|
default:
|
|
916
|
-
|
|
917
|
-
return `${clientValue} as any`;
|
|
918
|
-
}
|
|
919
|
-
return clientValue;
|
|
780
|
+
return restValue;
|
|
920
781
|
}
|
|
921
782
|
}
|
|
922
|
-
function needsDeserialize(type) {
|
|
923
|
-
return ((type === null || type === void 0 ? void 0 : type.type) === "datetime" ||
|
|
924
|
-
(type === null || type === void 0 ? void 0 : type.type) === "model" ||
|
|
925
|
-
(type === null || type === void 0 ? void 0 : type.type) === "list" ||
|
|
926
|
-
(type === null || type === void 0 ? void 0 : type.type) === "byte-array");
|
|
927
|
-
}
|
|
928
783
|
export function isLroAndPagingOperation(op) {
|
|
929
784
|
return op.discriminator === "lropaging";
|
|
930
785
|
}
|
|
@@ -983,18 +838,10 @@ export function getPropertySerializationPrefix(modularType, propertyPath) {
|
|
|
983
838
|
export function getPropertyFullName(modularType, propertyPath) {
|
|
984
839
|
let fullName = `${modularType.clientName}`;
|
|
985
840
|
if (propertyPath) {
|
|
986
|
-
fullName = `${propertyPath}
|
|
841
|
+
fullName = `${propertyPath}["${modularType.clientName}"]`;
|
|
987
842
|
}
|
|
988
843
|
return fullName;
|
|
989
844
|
}
|
|
990
|
-
export function isDiscriminatedUnion(type) {
|
|
991
|
-
if (!type) {
|
|
992
|
-
return false;
|
|
993
|
-
}
|
|
994
|
-
return Boolean(type.kind === "model" &&
|
|
995
|
-
type.discriminatorProperty &&
|
|
996
|
-
type.discriminatedSubtypes);
|
|
997
|
-
}
|
|
998
845
|
/**
|
|
999
846
|
* Get an expression representing an array of expected status codes for the operation
|
|
1000
847
|
* @param operation The operation
|