@azure-tools/typespec-ts 0.29.0 → 0.30.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 +15 -0
- package/dist/src/contextManager.d.ts +70 -0
- package/dist/src/contextManager.d.ts.map +1 -0
- package/dist/src/contextManager.js +59 -0
- package/dist/src/contextManager.js.map +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -28
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +2 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +3 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/metaTree.d.ts +12 -0
- package/dist/src/metaTree.d.ts.map +1 -0
- package/dist/src/metaTree.js +2 -0
- package/dist/src/metaTree.js.map +1 -0
- package/dist/src/modular/buildClassicalClient.d.ts +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +22 -16
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts +3 -2
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +5 -5
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +5 -5
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +2 -2
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +69 -43
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildHelperSerializers.d.ts +3 -0
- package/dist/src/modular/buildHelperSerializers.d.ts.map +1 -0
- package/dist/src/modular/buildHelperSerializers.js +60 -0
- package/dist/src/modular/buildHelperSerializers.js.map +1 -0
- package/dist/src/modular/buildLroFiles.d.ts +1 -1
- package/dist/src/modular/buildLroFiles.d.ts.map +1 -1
- package/dist/src/modular/buildLroFiles.js +25 -31
- package/dist/src/modular/buildLroFiles.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +3 -2
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +23 -11
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildPagingFiles.d.ts.map +1 -1
- package/dist/src/modular/buildPagingFiles.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +1 -1
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSerializeUtils.d.ts +2 -2
- package/dist/src/modular/buildSerializeUtils.d.ts.map +1 -1
- package/dist/src/modular/buildSerializeUtils.js +15 -8
- package/dist/src/modular/buildSerializeUtils.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +6 -0
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +5 -5
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +52 -21
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts +3 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js +26 -12
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +3 -2
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +14 -5
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +5 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +25 -1
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +11 -3
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +160 -66
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +3 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +50 -19
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +9 -5
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts +4 -0
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -0
- package/dist/src/modular/serialization/buildSerializerFunction.js +160 -0
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -0
- package/dist/src/modular/serialization/collectionUtils.d.ts +3 -0
- package/dist/src/modular/serialization/collectionUtils.d.ts.map +1 -0
- package/dist/src/modular/serialization/collectionUtils.js +17 -0
- package/dist/src/modular/serialization/collectionUtils.js.map +1 -0
- package/dist/src/modular/serialization/index.d.ts +5 -0
- package/dist/src/modular/serialization/index.d.ts.map +1 -0
- package/dist/src/modular/serialization/index.js +156 -0
- package/dist/src/modular/serialization/index.js.map +1 -0
- package/dist/src/modular/serialization/operationHelpers.d.ts +37 -0
- package/dist/src/modular/serialization/operationHelpers.d.ts.map +1 -0
- package/dist/src/modular/serialization/operationHelpers.js +457 -0
- package/dist/src/modular/serialization/operationHelpers.js.map +1 -0
- package/dist/src/modular/serialization/serializeArray.d.ts +5 -0
- package/dist/src/modular/serialization/serializeArray.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializeArray.js +33 -0
- package/dist/src/modular/serialization/serializeArray.js.map +1 -0
- package/dist/src/modular/serialization/serializeDateTime.d.ts +4 -0
- package/dist/src/modular/serialization/serializeDateTime.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializeDateTime.js +19 -0
- package/dist/src/modular/serialization/serializeDateTime.js.map +1 -0
- package/dist/src/modular/serialization/serializeHeaders.d.ts +7 -0
- package/dist/src/modular/serialization/serializeHeaders.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializeHeaders.js +44 -0
- package/dist/src/modular/serialization/serializeHeaders.js.map +1 -0
- package/dist/src/modular/serialization/serializers.d.ts +17 -0
- package/dist/src/modular/serialization/serializers.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializers.js +176 -0
- package/dist/src/modular/serialization/serializers.js.map +1 -0
- package/dist/src/modular/serialization/util.d.ts +26 -0
- package/dist/src/modular/serialization/util.d.ts.map +1 -0
- package/dist/src/modular/serialization/util.js +112 -0
- package/dist/src/modular/serialization/util.js.map +1 -0
- package/dist/src/reify/index.d.ts +12 -0
- package/dist/src/reify/index.d.ts.map +1 -0
- package/dist/src/reify/index.js +22 -0
- package/dist/src/reify/index.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +7 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/transform/transform.d.ts +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +11 -11
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +16 -6
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +1 -1
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +3 -3
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts +1 -1
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js +3 -4
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts +1 -1
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +12 -9
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +10 -4
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +1 -1
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +11 -5
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/emitUtil.d.ts +1 -2
- package/dist/src/utils/emitUtil.d.ts.map +1 -1
- package/dist/src/utils/emitUtil.js.map +1 -1
- package/dist/src/utils/importHelper.d.ts +10 -0
- package/dist/src/utils/importHelper.d.ts.map +1 -0
- package/dist/src/utils/importHelper.js +54 -0
- package/dist/src/utils/importHelper.js.map +1 -0
- package/dist/src/utils/modelUtils.d.ts +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +41 -25
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/namespaceUtils.d.ts.map +1 -1
- package/dist/src/utils/namespaceUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +3 -4
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +4 -5
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +55 -35
- package/src/contextManager.ts +99 -0
- package/src/index.ts +66 -55
- package/src/lib.ts +6 -4
- package/src/metaTree.ts +14 -0
- package/src/modular/buildClassicalClient.ts +36 -18
- package/src/modular/buildClassicalOperationGroups.ts +16 -8
- package/src/modular/buildClientContext.ts +11 -11
- package/src/modular/buildCodeModel.ts +141 -99
- package/src/modular/buildHelperSerializers.ts +71 -0
- package/src/modular/buildLroFiles.ts +29 -33
- package/src/modular/buildOperations.ts +68 -31
- package/src/modular/buildPagingFiles.ts +1 -1
- package/src/modular/buildProjectFiles.ts +1 -1
- package/src/modular/buildRootIndex.ts +1 -1
- package/src/modular/buildSerializeUtils.ts +33 -25
- package/src/modular/buildSubpathIndex.ts +10 -0
- package/src/modular/emitModels.ts +86 -32
- package/src/modular/helpers/classicalOperationHelpers.ts +41 -7
- package/src/modular/helpers/clientHelpers.ts +19 -6
- package/src/modular/helpers/namingHelpers.ts +59 -4
- package/src/modular/helpers/operationHelpers.ts +247 -111
- package/src/modular/helpers/typeHelpers.ts +54 -17
- package/src/modular/modularCodeModel.ts +17 -5
- package/src/modular/serialization/buildSerializerFunction.ts +224 -0
- package/src/modular/serialization/collectionUtils.ts +20 -0
- package/src/modular/serialization/index.ts +263 -0
- package/src/modular/serialization/operationHelpers.ts +660 -0
- package/src/modular/serialization/serializeArray.ts +51 -0
- package/src/modular/serialization/serializeDateTime.ts +22 -0
- package/src/modular/serialization/serializeHeaders.ts +64 -0
- package/src/modular/serialization/serializers.ts +304 -0
- package/src/modular/serialization/util.ts +167 -0
- package/src/reify/index.ts +41 -0
- package/src/testing/index.ts +10 -0
- package/src/transform/transform.ts +15 -15
- package/src/transform/transformApiVersionInfo.ts +29 -16
- package/src/transform/transformHelperFunctionDetails.ts +8 -8
- package/src/transform/transformParameters.ts +15 -15
- package/src/transform/transformPaths.ts +12 -12
- package/src/transform/transformResponses.ts +21 -18
- package/src/transform/transformSchemas.ts +17 -8
- package/src/transform/transformTelemetryInfo.ts +4 -4
- package/src/transform/transfromRLCOptions.ts +14 -7
- package/src/utils/clientUtils.ts +2 -2
- package/src/utils/emitUtil.ts +6 -3
- package/src/utils/importHelper.ts +64 -0
- package/src/utils/modelUtils.ts +79 -47
- package/src/utils/namespaceUtils.ts +1 -1
- package/src/utils/operationUtil.ts +22 -24
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getImportSpecifier,
|
|
3
|
+
NameType,
|
|
4
|
+
normalizeName
|
|
5
|
+
} from "@azure-tools/rlc-common";
|
|
1
6
|
import { SourceFile } from "ts-morph";
|
|
7
|
+
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
8
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
9
|
+
import { importModels } from "./buildOperations.js";
|
|
2
10
|
import {
|
|
3
11
|
getClientParameters,
|
|
4
12
|
importCredential
|
|
5
13
|
} from "./helpers/clientHelpers.js";
|
|
6
|
-
import { getClientName } from "./helpers/namingHelpers.js";
|
|
7
|
-
import { Client, ModularCodeModel } from "./modularCodeModel.js";
|
|
8
|
-
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
9
14
|
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
10
|
-
import {
|
|
11
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
12
|
-
import {
|
|
13
|
-
getImportSpecifier,
|
|
14
|
-
normalizeName,
|
|
15
|
-
NameType
|
|
16
|
-
} from "@azure-tools/rlc-common";
|
|
15
|
+
import { getClientName } from "./helpers/namingHelpers.js";
|
|
17
16
|
import { getType } from "./helpers/typeHelpers.js";
|
|
17
|
+
import { Client, ModularCodeModel } from "./modularCodeModel.js";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* This function creates the file containing the modular client context
|
|
@@ -26,7 +26,7 @@ export function buildClientContext(
|
|
|
26
26
|
): SourceFile {
|
|
27
27
|
const { description, subfolder } = client;
|
|
28
28
|
const name = getClientName(client);
|
|
29
|
-
const params = getClientParameters(client);
|
|
29
|
+
const params = getClientParameters(client, dpgContext);
|
|
30
30
|
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
31
31
|
const clientContextFile = codeModel.project.createSourceFile(
|
|
32
32
|
`${srcPath}/${
|
|
@@ -1,84 +1,87 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
buildRuntimeImports,
|
|
3
|
+
getClientName,
|
|
4
|
+
NameType,
|
|
5
|
+
normalizeName,
|
|
6
|
+
RLCModel
|
|
7
|
+
} from "@azure-tools/rlc-common";
|
|
8
|
+
import {
|
|
9
|
+
getLroMetadata,
|
|
10
|
+
getPagedResult
|
|
4
11
|
} from "@azure-tools/typespec-azure-core";
|
|
12
|
+
import {
|
|
13
|
+
getAllModels,
|
|
14
|
+
getClientNamespaceString,
|
|
15
|
+
getClientType,
|
|
16
|
+
getDefaultApiVersion,
|
|
17
|
+
getLibraryName,
|
|
18
|
+
getSdkBuiltInType,
|
|
19
|
+
getSdkUnion,
|
|
20
|
+
getWireName,
|
|
21
|
+
isApiVersion,
|
|
22
|
+
listClients,
|
|
23
|
+
listOperationGroups,
|
|
24
|
+
listOperationsInOperationGroup,
|
|
25
|
+
SdkBuiltInType,
|
|
26
|
+
SdkClient,
|
|
27
|
+
SdkEnumValueType,
|
|
28
|
+
SdkType
|
|
29
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
5
30
|
import {
|
|
6
31
|
Enum,
|
|
32
|
+
getDiscriminator,
|
|
7
33
|
getDoc,
|
|
34
|
+
getEncode,
|
|
8
35
|
getFriendlyName,
|
|
36
|
+
getMaxItems,
|
|
9
37
|
getMaxLength,
|
|
10
38
|
getMaxValue,
|
|
39
|
+
getMinItems,
|
|
11
40
|
getMinLength,
|
|
12
41
|
getMinValue,
|
|
13
42
|
getPattern,
|
|
43
|
+
getPropertyType,
|
|
14
44
|
getSummary,
|
|
15
45
|
getVisibility,
|
|
16
46
|
ignoreDiagnostics,
|
|
47
|
+
IntrinsicScalarName,
|
|
48
|
+
IntrinsicType,
|
|
17
49
|
isErrorModel,
|
|
18
50
|
isNeverType,
|
|
51
|
+
isNullType,
|
|
52
|
+
isNumericType,
|
|
53
|
+
isStringType,
|
|
54
|
+
isTemplateDeclarationOrInstance,
|
|
55
|
+
isType,
|
|
56
|
+
isVoidType,
|
|
57
|
+
listServices,
|
|
19
58
|
Model,
|
|
20
59
|
ModelProperty,
|
|
21
60
|
Namespace,
|
|
22
|
-
Program,
|
|
23
|
-
getDiscriminator,
|
|
24
61
|
Operation,
|
|
62
|
+
Program,
|
|
25
63
|
Scalar,
|
|
26
|
-
IntrinsicScalarName,
|
|
27
|
-
isStringType,
|
|
28
|
-
getPropertyType,
|
|
29
|
-
isNumericType,
|
|
30
|
-
getMinItems,
|
|
31
|
-
getMaxItems,
|
|
32
|
-
listServices,
|
|
33
|
-
Union,
|
|
34
64
|
Type,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
getEncode,
|
|
38
|
-
isTemplateDeclarationOrInstance,
|
|
39
|
-
UsageFlags,
|
|
40
|
-
isVoidType
|
|
65
|
+
Union,
|
|
66
|
+
UsageFlags
|
|
41
67
|
} from "@typespec/compiler";
|
|
42
68
|
import {
|
|
43
69
|
getAuthentication,
|
|
70
|
+
getHttpOperation,
|
|
44
71
|
getServers,
|
|
45
72
|
HttpAuth,
|
|
73
|
+
HttpOperation,
|
|
46
74
|
HttpOperationParameter,
|
|
47
75
|
HttpOperationResponse,
|
|
48
76
|
HttpOperationResponseContent,
|
|
49
77
|
HttpServer,
|
|
50
|
-
HttpOperation,
|
|
51
|
-
getHttpOperation,
|
|
52
78
|
isSharedRoute
|
|
53
79
|
} from "@typespec/http";
|
|
54
80
|
import { getAddedOnVersions } from "@typespec/versioning";
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
listOperationsInOperationGroup,
|
|
60
|
-
isApiVersion,
|
|
61
|
-
getDefaultApiVersion,
|
|
62
|
-
getClientNamespaceString,
|
|
63
|
-
getSdkUnion,
|
|
64
|
-
getAllModels,
|
|
65
|
-
SdkBuiltInType,
|
|
66
|
-
getSdkBuiltInType,
|
|
67
|
-
SdkEnumValueType,
|
|
68
|
-
getLibraryName,
|
|
69
|
-
getWireName
|
|
70
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
71
|
-
import {
|
|
72
|
-
ModularCodeModel,
|
|
73
|
-
Client as HrlcClient,
|
|
74
|
-
Parameter,
|
|
75
|
-
Operation as HrlcOperation,
|
|
76
|
-
OperationGroup,
|
|
77
|
-
Response,
|
|
78
|
-
Type as HrlcType,
|
|
79
|
-
Header,
|
|
80
|
-
Property
|
|
81
|
-
} from "./modularCodeModel.js";
|
|
81
|
+
import { Project } from "ts-morph";
|
|
82
|
+
import { reportDiagnostic } from "../lib.js";
|
|
83
|
+
import { camelToSnakeCase, toCamelCase } from "../utils/casingUtils.js";
|
|
84
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
82
85
|
import {
|
|
83
86
|
buildCoreTypeInfo,
|
|
84
87
|
getBodyType,
|
|
@@ -87,14 +90,9 @@ import {
|
|
|
87
90
|
isAzureCoreErrorType,
|
|
88
91
|
isSchemaProperty
|
|
89
92
|
} from "../utils/modelUtils.js";
|
|
90
|
-
import {
|
|
91
|
-
import {
|
|
92
|
-
RLCModel,
|
|
93
|
-
getClientName,
|
|
94
|
-
NameType,
|
|
95
|
-
normalizeName
|
|
96
|
-
} from "@azure-tools/rlc-common";
|
|
93
|
+
import { getModelNamespaceName } from "../utils/namespaceUtils.js";
|
|
97
94
|
import {
|
|
95
|
+
extractPagedMetadataNested,
|
|
98
96
|
getOperationGroupName,
|
|
99
97
|
getOperationName,
|
|
100
98
|
isBinaryPayload,
|
|
@@ -103,13 +101,20 @@ import {
|
|
|
103
101
|
parseItemName,
|
|
104
102
|
parseNextLinkName
|
|
105
103
|
} from "../utils/operationUtil.js";
|
|
106
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
107
|
-
import { Project } from "ts-morph";
|
|
108
|
-
import { buildRuntimeImports } from "@azure-tools/rlc-common";
|
|
109
|
-
import { getModelNamespaceName } from "../utils/namespaceUtils.js";
|
|
110
|
-
import { reportDiagnostic } from "../lib.js";
|
|
111
|
-
import { getType as getTypeName } from "./helpers/typeHelpers.js";
|
|
112
104
|
import { isModelWithAdditionalProperties } from "./emitModels.js";
|
|
105
|
+
import { getType as getTypeName } from "./helpers/typeHelpers.js";
|
|
106
|
+
import {
|
|
107
|
+
Client as HrlcClient,
|
|
108
|
+
Header,
|
|
109
|
+
ModularCodeModel,
|
|
110
|
+
Operation as HrlcOperation,
|
|
111
|
+
OperationGroup,
|
|
112
|
+
Parameter,
|
|
113
|
+
Property,
|
|
114
|
+
Response,
|
|
115
|
+
Type as HrlcType
|
|
116
|
+
} from "./modularCodeModel.js";
|
|
117
|
+
import { useContext } from "../contextManager.js";
|
|
113
118
|
|
|
114
119
|
interface HttpServerParameter {
|
|
115
120
|
type: "endpointPath";
|
|
@@ -305,6 +310,8 @@ function getType(
|
|
|
305
310
|
type: EmitterType,
|
|
306
311
|
options: { disableEffectiveModel?: boolean; usage?: UsageFlags } = {}
|
|
307
312
|
): any {
|
|
313
|
+
const modularMetatree = useContext("modularMetaTree");
|
|
314
|
+
|
|
308
315
|
// don't cache simple type(string, int, etc) since decorators may change the result
|
|
309
316
|
const enableCache = !isSimpleType(context.program, type);
|
|
310
317
|
const effectiveModel =
|
|
@@ -319,6 +326,7 @@ function getType(
|
|
|
319
326
|
}
|
|
320
327
|
}
|
|
321
328
|
let newValue: any;
|
|
329
|
+
|
|
322
330
|
if (isEmptyAnonymousModel(type)) {
|
|
323
331
|
// do not generate model for empty model, treat it as any
|
|
324
332
|
newValue = { type: "any" };
|
|
@@ -329,6 +337,12 @@ function getType(
|
|
|
329
337
|
newValue = applyEncoding(context.program, type, newValue);
|
|
330
338
|
}
|
|
331
339
|
|
|
340
|
+
if (isTypespecType(type)) {
|
|
341
|
+
newValue.tcgcType = getClientType(context, type);
|
|
342
|
+
newValue.__raw = type;
|
|
343
|
+
modularMetatree.set(type, newValue);
|
|
344
|
+
}
|
|
345
|
+
|
|
332
346
|
if (enableCache) {
|
|
333
347
|
if (!options.disableEffectiveModel) {
|
|
334
348
|
typesMap.set(effectiveModel, newValue);
|
|
@@ -349,7 +363,8 @@ function getType(
|
|
|
349
363
|
}
|
|
350
364
|
}
|
|
351
365
|
} else {
|
|
352
|
-
const
|
|
366
|
+
const { __raw, tcgcType, ...keyableValue } = newValue;
|
|
367
|
+
const key = JSON.stringify(keyableValue);
|
|
353
368
|
const value = simpleTypesMap.get(key);
|
|
354
369
|
if (value) {
|
|
355
370
|
newValue = value;
|
|
@@ -370,9 +385,14 @@ function getType(
|
|
|
370
385
|
target: type
|
|
371
386
|
});
|
|
372
387
|
}
|
|
388
|
+
|
|
373
389
|
return newValue;
|
|
374
390
|
}
|
|
375
391
|
|
|
392
|
+
function isTypespecType(type: EmitterType): type is Type {
|
|
393
|
+
return type.kind !== "Credential" && type.kind !== "CredentialTypeUnion";
|
|
394
|
+
}
|
|
395
|
+
|
|
376
396
|
// To pass the yaml dump
|
|
377
397
|
function getAddedOnVersion(p: Program, t: Type): string | undefined {
|
|
378
398
|
return getAddedOnVersions(p, t)?.[0]?.value;
|
|
@@ -386,6 +406,7 @@ type ParamBase = {
|
|
|
386
406
|
restApiName: string;
|
|
387
407
|
inOverload: boolean;
|
|
388
408
|
format?: string;
|
|
409
|
+
tcgcType: SdkType;
|
|
389
410
|
};
|
|
390
411
|
function emitParamBase(
|
|
391
412
|
context: SdkContext,
|
|
@@ -425,7 +446,8 @@ function emitParamBase(
|
|
|
425
446
|
clientName: applyCasing(name, { casing: CASING }),
|
|
426
447
|
restApiName,
|
|
427
448
|
inOverload: false,
|
|
428
|
-
format
|
|
449
|
+
format,
|
|
450
|
+
tcgcType: getClientType(context, parameter)
|
|
429
451
|
};
|
|
430
452
|
}
|
|
431
453
|
|
|
@@ -440,26 +462,33 @@ type BodyParameter = ParamBase & {
|
|
|
440
462
|
function emitBodyParameter(
|
|
441
463
|
context: SdkContext,
|
|
442
464
|
httpOperation: HttpOperation
|
|
443
|
-
): BodyParameter {
|
|
465
|
+
): BodyParameter | undefined {
|
|
444
466
|
const params = httpOperation.parameters;
|
|
445
467
|
const body = params.body!;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
contentTypes
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
468
|
+
if (body.bodyKind === "single") {
|
|
469
|
+
const base = emitParamBase(context, body.parameter ?? body.type);
|
|
470
|
+
let contentTypes = body.contentTypes;
|
|
471
|
+
if (contentTypes.length === 0) {
|
|
472
|
+
contentTypes = ["application/json"];
|
|
473
|
+
}
|
|
474
|
+
const type = getType(
|
|
475
|
+
context,
|
|
476
|
+
getBodyType(context.program, httpOperation)!,
|
|
477
|
+
{
|
|
478
|
+
disableEffectiveModel: true,
|
|
479
|
+
usage: UsageFlags.Input
|
|
480
|
+
}
|
|
481
|
+
);
|
|
455
482
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
483
|
+
return {
|
|
484
|
+
contentTypes,
|
|
485
|
+
type,
|
|
486
|
+
location: "body",
|
|
487
|
+
...base,
|
|
488
|
+
isBinaryPayload: isBinaryPayload(context, body.type, contentTypes)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
return undefined;
|
|
463
492
|
}
|
|
464
493
|
|
|
465
494
|
function emitParameter(
|
|
@@ -481,7 +510,7 @@ function emitParameter(
|
|
|
481
510
|
clientDefaultValue = type["value"];
|
|
482
511
|
type = type["valueType"];
|
|
483
512
|
}
|
|
484
|
-
const paramMap
|
|
513
|
+
const paramMap = {
|
|
485
514
|
restApiName: parameter.name,
|
|
486
515
|
location: parameter.type,
|
|
487
516
|
type: base.format ? { ...type, format: base.format } : type,
|
|
@@ -503,7 +532,7 @@ function emitParameter(
|
|
|
503
532
|
getServiceNamespace(context.program)
|
|
504
533
|
);
|
|
505
534
|
paramMap.implementation = implementation;
|
|
506
|
-
paramMap.in_docstring = false;
|
|
535
|
+
(paramMap as any).in_docstring = false;
|
|
507
536
|
if (defaultApiVersion) {
|
|
508
537
|
clientDefaultValue = defaultApiVersion.value;
|
|
509
538
|
}
|
|
@@ -511,7 +540,7 @@ function emitParameter(
|
|
|
511
540
|
clientDefaultValue = getDefaultApiVersionString(context);
|
|
512
541
|
}
|
|
513
542
|
if (clientDefaultValue !== undefined) {
|
|
514
|
-
paramMap.optional = true;
|
|
543
|
+
(paramMap as any).optional = true;
|
|
515
544
|
}
|
|
516
545
|
}
|
|
517
546
|
return { clientDefaultValue, ...base, ...paramMap };
|
|
@@ -943,7 +972,7 @@ function getName(program: Program, type: Model): string {
|
|
|
943
972
|
) {
|
|
944
973
|
return (
|
|
945
974
|
type.name +
|
|
946
|
-
type.templateMapper.args
|
|
975
|
+
(type.templateMapper.args.filter((it) => isType(it)) as Type[])
|
|
947
976
|
.map((it) => (it.kind === "Model" ? it.name : ""))
|
|
948
977
|
.join("")
|
|
949
978
|
);
|
|
@@ -993,7 +1022,7 @@ function emitModel(
|
|
|
993
1022
|
getPagedResult(context.program, type)
|
|
994
1023
|
) {
|
|
995
1024
|
modelName =
|
|
996
|
-
type.templateMapper.args
|
|
1025
|
+
(type.templateMapper.args.filter((it) => isType(it)) as Type[])
|
|
997
1026
|
.map((it) => {
|
|
998
1027
|
switch (it.kind) {
|
|
999
1028
|
case "Model":
|
|
@@ -1007,9 +1036,11 @@ function emitModel(
|
|
|
1007
1036
|
.join("") + "List";
|
|
1008
1037
|
}
|
|
1009
1038
|
|
|
1039
|
+
const page = extractPagedMetadataNested(context.program, type);
|
|
1040
|
+
const isPaging = page && page.itemsSegments && page.itemsSegments.length > 0;
|
|
1010
1041
|
return {
|
|
1011
1042
|
type: "model",
|
|
1012
|
-
name: modelName
|
|
1043
|
+
name: `${isPaging ? "_" : ""}${modelName}`,
|
|
1013
1044
|
description: getDocStr(context.program, type),
|
|
1014
1045
|
parents: baseModel ? [baseModel] : [],
|
|
1015
1046
|
discriminatedSubtypes: [],
|
|
@@ -1046,13 +1077,17 @@ function emitEnum(context: SdkContext, type: Enum): Record<string, any> {
|
|
|
1046
1077
|
});
|
|
1047
1078
|
}
|
|
1048
1079
|
|
|
1080
|
+
const name = normalizeName(
|
|
1081
|
+
getLibraryName(context, type) ? getLibraryName(context, type) : type.name,
|
|
1082
|
+
NameType.Interface
|
|
1083
|
+
);
|
|
1049
1084
|
return {
|
|
1050
1085
|
type: "enum",
|
|
1051
|
-
name
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1086
|
+
name,
|
|
1087
|
+
description:
|
|
1088
|
+
getDocStr(program, type) === ""
|
|
1089
|
+
? `Type of ${name}`
|
|
1090
|
+
: getDocStr(program, type),
|
|
1056
1091
|
valueType: { type: enumMemberType(type.members.values().next().value) },
|
|
1057
1092
|
values: enumValues,
|
|
1058
1093
|
isFixed: true,
|
|
@@ -1322,7 +1357,11 @@ function emitUnion(
|
|
|
1322
1357
|
type: Union,
|
|
1323
1358
|
usage: UsageFlags
|
|
1324
1359
|
): Record<string, any> {
|
|
1325
|
-
|
|
1360
|
+
let sdkType = getSdkUnion(context, type);
|
|
1361
|
+
const isNull = false;
|
|
1362
|
+
if (sdkType.kind === "nullable") {
|
|
1363
|
+
sdkType = sdkType.type;
|
|
1364
|
+
}
|
|
1326
1365
|
const nonNullOptions = getNonNullOptions(type);
|
|
1327
1366
|
if (sdkType === undefined) {
|
|
1328
1367
|
throw Error("Should not have an empty union");
|
|
@@ -1346,7 +1385,7 @@ function emitUnion(
|
|
|
1346
1385
|
? normalizeName(unionName, NameType.Interface)
|
|
1347
1386
|
: undefined;
|
|
1348
1387
|
return {
|
|
1349
|
-
nullable:
|
|
1388
|
+
nullable: isNull,
|
|
1350
1389
|
name: unionTypeName,
|
|
1351
1390
|
description: `Type of ${unionTypeName}`,
|
|
1352
1391
|
internal: true,
|
|
@@ -1360,7 +1399,8 @@ function emitUnion(
|
|
|
1360
1399
|
aliasType:
|
|
1361
1400
|
unionName === "" || unionName === undefined
|
|
1362
1401
|
? undefined
|
|
1363
|
-
: variantTypes.map((x) => getTypeName(x).name).join(" | ")
|
|
1402
|
+
: variantTypes.map((x) => getTypeName(x).name).join(" | "),
|
|
1403
|
+
tcgcType: sdkType
|
|
1364
1404
|
};
|
|
1365
1405
|
} else if (sdkType.kind === "enum") {
|
|
1366
1406
|
let typeName = getLibraryName(context, type)
|
|
@@ -1373,25 +1413,26 @@ function emitUnion(
|
|
|
1373
1413
|
: undefined;
|
|
1374
1414
|
return {
|
|
1375
1415
|
name: typeName,
|
|
1376
|
-
nullable:
|
|
1416
|
+
nullable: isNull,
|
|
1377
1417
|
description: sdkType.description || `Type of ${typeName}`,
|
|
1378
1418
|
internal: true,
|
|
1379
1419
|
type: sdkType.kind,
|
|
1380
1420
|
valueType: emitSimpleType(context, sdkType.valueType as SdkBuiltInType),
|
|
1381
1421
|
values: sdkType.values.map((x) => emitEnumMember(context, x)),
|
|
1382
1422
|
isFixed: sdkType.isFixed,
|
|
1423
|
+
isNonExhaustive: context.rlcOptions?.experimentalExtensibleEnums ?? false,
|
|
1383
1424
|
xmlMetadata: {},
|
|
1384
1425
|
usage
|
|
1385
1426
|
};
|
|
1386
1427
|
} else if (nonNullOptions.length === 1 && nonNullOptions[0]) {
|
|
1387
1428
|
return {
|
|
1388
1429
|
...emitType(context, nonNullOptions[0], usage),
|
|
1389
|
-
nullable:
|
|
1430
|
+
nullable: isNull
|
|
1390
1431
|
};
|
|
1391
1432
|
} else {
|
|
1392
1433
|
return {
|
|
1393
1434
|
...emitType(context, sdkType.__raw!, usage),
|
|
1394
|
-
nullable:
|
|
1435
|
+
nullable: isNull
|
|
1395
1436
|
};
|
|
1396
1437
|
}
|
|
1397
1438
|
}
|
|
@@ -1428,7 +1469,7 @@ function emitSimpleType(
|
|
|
1428
1469
|
}
|
|
1429
1470
|
|
|
1430
1471
|
return {
|
|
1431
|
-
nullable: sdkType.
|
|
1472
|
+
nullable: isNullType(sdkType.__raw!),
|
|
1432
1473
|
type: sdkType.kind === "string" ? "string" : "number", // TODO: handle other types
|
|
1433
1474
|
doc: "",
|
|
1434
1475
|
apiVersions: [],
|
|
@@ -1814,7 +1855,9 @@ export function emitCodeModel(
|
|
|
1814
1855
|
options: dpgContext.rlcOptions ?? {},
|
|
1815
1856
|
modularOptions: {
|
|
1816
1857
|
sourceRoot: modularSourcesRoot,
|
|
1817
|
-
compatibilityMode: !!dpgContext.rlcOptions?.compatibilityMode
|
|
1858
|
+
compatibilityMode: !!dpgContext.rlcOptions?.compatibilityMode,
|
|
1859
|
+
experimentalExtensibleEnums:
|
|
1860
|
+
!!dpgContext.rlcOptions?.experimentalExtensibleEnums
|
|
1818
1861
|
},
|
|
1819
1862
|
namespace: clientNamespaceString,
|
|
1820
1863
|
subnamespaceToClients: {},
|
|
@@ -1830,7 +1873,6 @@ export function emitCodeModel(
|
|
|
1830
1873
|
for (const model of allModels) {
|
|
1831
1874
|
getType(dpgContext, model.__raw!, { usage: model.usage as UsageFlags });
|
|
1832
1875
|
}
|
|
1833
|
-
|
|
1834
1876
|
for (const namespace of getNamespaces(dpgContext)) {
|
|
1835
1877
|
if (namespace === clientNamespaceString) {
|
|
1836
1878
|
codeModel.clients = emitClients(dpgContext, namespace, rlcModelsMap);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import { useContext } from "../contextManager.js";
|
|
3
|
+
const serializeRecordFunction = {
|
|
4
|
+
symbol: "serializeRecord",
|
|
5
|
+
content: `
|
|
6
|
+
export function serializeRecord<
|
|
7
|
+
T extends string | number | boolean | Date | null,
|
|
8
|
+
R
|
|
9
|
+
>(item: Record<string, T>): Record<string, R>;
|
|
10
|
+
export function serializeRecord<T, R>(
|
|
11
|
+
item: Record<string, T>,
|
|
12
|
+
serializer: (item: T) => R
|
|
13
|
+
): Record<string, R>;
|
|
14
|
+
export function serializeRecord<T, R>(
|
|
15
|
+
item: Record<string, T>,
|
|
16
|
+
serializer?: (item: T) => R
|
|
17
|
+
): Record<string, R> {
|
|
18
|
+
return Object.keys(item).reduce(
|
|
19
|
+
(acc, key) => {
|
|
20
|
+
if (isSupportedRecordType(item[key])) {
|
|
21
|
+
acc[key] = item[key] as any;
|
|
22
|
+
} else if (serializer) {
|
|
23
|
+
const value = item[key];
|
|
24
|
+
if (value !== undefined) {
|
|
25
|
+
acc[key] = serializer(value);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
console.warn(\`Don't know how to serialize \${item[key]}\`);
|
|
29
|
+
acc[key] = item[key] as any;
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
},
|
|
33
|
+
{} as Record<string, R>
|
|
34
|
+
);
|
|
35
|
+
}`
|
|
36
|
+
};
|
|
37
|
+
const isRecordElementSupportedFunction = {
|
|
38
|
+
symbol: "isSupportedRecordType",
|
|
39
|
+
content: `
|
|
40
|
+
function isSupportedRecordType(t: any) {
|
|
41
|
+
return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date;
|
|
42
|
+
}
|
|
43
|
+
`
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function emitSerializerHelpersFile(
|
|
47
|
+
project: Project,
|
|
48
|
+
srcPath: string = "src"
|
|
49
|
+
) {
|
|
50
|
+
const symbolMap = useContext("symbolMap");
|
|
51
|
+
const sourceFile = project.createSourceFile(
|
|
52
|
+
`${srcPath}/helpers/serializerHelpers.ts`,
|
|
53
|
+
"",
|
|
54
|
+
{
|
|
55
|
+
overwrite: true
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (!symbolMap.has(serializeRecordFunction.symbol)) {
|
|
60
|
+
symbolMap.set(serializeRecordFunction.symbol, sourceFile);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!symbolMap.has(isRecordElementSupportedFunction.symbol)) {
|
|
64
|
+
symbolMap.set(isRecordElementSupportedFunction.symbol, sourceFile);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
sourceFile.addStatements([
|
|
68
|
+
serializeRecordFunction.content,
|
|
69
|
+
isRecordElementSupportedFunction.content
|
|
70
|
+
]);
|
|
71
|
+
}
|