@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,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SdkClient,
|
|
3
|
-
isApiVersion,
|
|
4
|
-
listOperationGroups,
|
|
5
|
-
listOperationsInOperationGroup
|
|
6
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
7
|
-
import { ignoreDiagnostics } from "@typespec/compiler";
|
|
8
1
|
import {
|
|
9
2
|
ApiVersionInfo,
|
|
10
|
-
|
|
11
|
-
extractPathApiVersion,
|
|
3
|
+
ApiVersionPosition,
|
|
12
4
|
extractDefinedPosition,
|
|
5
|
+
extractPathApiVersion,
|
|
13
6
|
SchemaContext,
|
|
14
|
-
|
|
7
|
+
UrlInfo
|
|
15
8
|
} from "@azure-tools/rlc-common";
|
|
9
|
+
import {
|
|
10
|
+
isApiVersion,
|
|
11
|
+
listOperationGroups,
|
|
12
|
+
listOperationsInOperationGroup,
|
|
13
|
+
SdkClient
|
|
14
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
15
|
+
import { ignoreDiagnostics } from "@typespec/compiler";
|
|
16
16
|
import { getHttpOperation } from "@typespec/http";
|
|
17
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
17
18
|
import {
|
|
18
19
|
getDefaultApiVersionString,
|
|
19
20
|
getSchemaForType,
|
|
20
21
|
trimUsage
|
|
21
22
|
} from "../utils/modelUtils.js";
|
|
22
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
23
23
|
|
|
24
24
|
export function transformApiVersionInfo(
|
|
25
25
|
client: SdkClient,
|
|
@@ -29,7 +29,12 @@ export function transformApiVersionInfo(
|
|
|
29
29
|
const queryVersionDetail = getOperationApiVersion(client, dpgContext);
|
|
30
30
|
const pathVersionDetail = extractPathApiVersion(urlInfo);
|
|
31
31
|
const isCrossedVersion =
|
|
32
|
-
|
|
32
|
+
queryVersionDetail || pathVersionDetail
|
|
33
|
+
? Boolean(
|
|
34
|
+
pathVersionDetail?.isCrossedVersion ||
|
|
35
|
+
queryVersionDetail?.isCrossedVersion
|
|
36
|
+
)
|
|
37
|
+
: undefined;
|
|
33
38
|
const defaultValue =
|
|
34
39
|
(pathVersionDetail || queryVersionDetail) && !isCrossedVersion
|
|
35
40
|
? getDefaultApiVersionString(dpgContext) ??
|
|
@@ -49,7 +54,8 @@ export function transformApiVersionInfo(
|
|
|
49
54
|
pathVersionDetail
|
|
50
55
|
),
|
|
51
56
|
isCrossedVersion,
|
|
52
|
-
defaultValue
|
|
57
|
+
defaultValue,
|
|
58
|
+
required: pathVersionDetail?.required ?? queryVersionDetail?.required
|
|
53
59
|
};
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -59,6 +65,7 @@ export function getOperationApiVersion(
|
|
|
59
65
|
): ApiVersionInfo | undefined {
|
|
60
66
|
const apiVersionTypes = new Set<string>();
|
|
61
67
|
const locations = new Set<ApiVersionPosition>();
|
|
68
|
+
const required = new Set<boolean>();
|
|
62
69
|
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
63
70
|
dpgContext.hasApiVersionInClient = true;
|
|
64
71
|
let hasApiVersionInOperation = true;
|
|
@@ -81,6 +88,7 @@ export function getOperationApiVersion(
|
|
|
81
88
|
needRef: false,
|
|
82
89
|
relevantProperty: p.param
|
|
83
90
|
});
|
|
91
|
+
required.add(!p.param.optional);
|
|
84
92
|
if (p.type !== "header") {
|
|
85
93
|
locations.add(p.type);
|
|
86
94
|
}
|
|
@@ -121,14 +129,18 @@ export function getOperationApiVersion(
|
|
|
121
129
|
needRef: false,
|
|
122
130
|
relevantProperty: p.param
|
|
123
131
|
});
|
|
132
|
+
required.add(!p.param.optional);
|
|
124
133
|
if (p.type !== "header") {
|
|
125
134
|
locations.add(p.type);
|
|
126
135
|
}
|
|
127
|
-
|
|
128
136
|
const typeString = JSON.stringify(trimUsage(type));
|
|
129
137
|
apiVersionTypes.add(typeString);
|
|
130
138
|
});
|
|
131
|
-
if (
|
|
139
|
+
if (
|
|
140
|
+
apiVersionTypes.size > 1 ||
|
|
141
|
+
!dpgContext.hasApiVersionInClient ||
|
|
142
|
+
required.size > 1
|
|
143
|
+
) {
|
|
132
144
|
break;
|
|
133
145
|
}
|
|
134
146
|
if (params.length === 1) {
|
|
@@ -147,7 +159,8 @@ export function getOperationApiVersion(
|
|
|
147
159
|
definedPosition:
|
|
148
160
|
locations.size > 1 ? "duplicate" : locations.values().next().value,
|
|
149
161
|
isCrossedVersion: apiVersionTypes.size > 1,
|
|
150
|
-
defaultValue: undefined // We won't prompt the query versions into client one
|
|
162
|
+
defaultValue: undefined, // We won't prompt the query versions into client one
|
|
163
|
+
required: required.values().next().value
|
|
151
164
|
};
|
|
152
165
|
return detail;
|
|
153
166
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
import { HelperFunctionDetails, PackageFlavor } from "@azure-tools/rlc-common";
|
|
1
2
|
import {
|
|
2
|
-
SdkClient,
|
|
3
3
|
listOperationGroups,
|
|
4
|
-
listOperationsInOperationGroup
|
|
4
|
+
listOperationsInOperationGroup,
|
|
5
|
+
SdkClient
|
|
5
6
|
} from "@azure-tools/typespec-client-generator-core";
|
|
6
|
-
import { HelperFunctionDetails, PackageFlavor } from "@azure-tools/rlc-common";
|
|
7
7
|
import { ignoreDiagnostics, Model, Program, Type } from "@typespec/compiler";
|
|
8
8
|
import { getHttpOperation, HttpOperation } from "@typespec/http";
|
|
9
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
9
10
|
import {
|
|
10
|
-
hasPagingOperations,
|
|
11
11
|
extractPagedMetadataNested,
|
|
12
|
-
hasPollingOperations,
|
|
13
12
|
getSpecialSerializeInfo,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
hasPagingOperations,
|
|
14
|
+
hasPollingOperations,
|
|
15
|
+
parseItemName,
|
|
16
|
+
parseNextLinkName
|
|
16
17
|
} from "../utils/operationUtil.js";
|
|
17
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
18
18
|
|
|
19
19
|
export function transformHelperFunctionDetails(
|
|
20
20
|
client: SdkClient,
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
ApiVersionInfo,
|
|
5
6
|
Imports,
|
|
6
7
|
ObjectSchema,
|
|
7
8
|
OperationParameter,
|
|
8
9
|
ParameterBodyMetadata,
|
|
9
10
|
ParameterMetadata,
|
|
10
11
|
Schema,
|
|
11
|
-
SchemaContext
|
|
12
|
-
ApiVersionInfo
|
|
12
|
+
SchemaContext
|
|
13
13
|
} from "@azure-tools/rlc-common";
|
|
14
14
|
import { ignoreDiagnostics, isVoidType, Type } from "@typespec/compiler";
|
|
15
15
|
import {
|
|
@@ -19,32 +19,32 @@ import {
|
|
|
19
19
|
HttpOperationParameters
|
|
20
20
|
} from "@typespec/http";
|
|
21
21
|
import {
|
|
22
|
+
getBodyType,
|
|
23
|
+
getFormattedPropertyDoc,
|
|
22
24
|
getImportedModelName,
|
|
23
|
-
getTypeName,
|
|
24
25
|
getSchemaForType,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
getSerializeTypeName
|
|
26
|
+
getSerializeTypeName,
|
|
27
|
+
getTypeName
|
|
28
28
|
} from "../utils/modelUtils.js";
|
|
29
29
|
|
|
30
30
|
import {
|
|
31
|
-
|
|
32
|
-
getOperationName,
|
|
33
|
-
getSpecialSerializeInfo
|
|
34
|
-
} from "../utils/operationUtil.js";
|
|
35
|
-
import {
|
|
36
|
-
SdkClient,
|
|
31
|
+
isApiVersion,
|
|
37
32
|
listOperationGroups,
|
|
38
33
|
listOperationsInOperationGroup,
|
|
39
|
-
|
|
34
|
+
SdkClient
|
|
40
35
|
} from "@azure-tools/typespec-client-generator-core";
|
|
41
36
|
import { SdkContext } from "../utils/interfaces.js";
|
|
42
37
|
import {
|
|
43
|
-
KnownMediaType,
|
|
44
38
|
extractMediaTypes,
|
|
45
39
|
hasMediaType,
|
|
46
|
-
isMediaTypeJsonMergePatch
|
|
40
|
+
isMediaTypeJsonMergePatch,
|
|
41
|
+
KnownMediaType
|
|
47
42
|
} from "../utils/mediaTypes.js";
|
|
43
|
+
import {
|
|
44
|
+
getOperationGroupName,
|
|
45
|
+
getOperationName,
|
|
46
|
+
getSpecialSerializeInfo
|
|
47
|
+
} from "../utils/operationUtil.js";
|
|
48
48
|
|
|
49
49
|
export function transformToParameterTypes(
|
|
50
50
|
client: SdkClient,
|
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
getResponseTypeName,
|
|
6
5
|
getParameterTypeName,
|
|
6
|
+
getResponseTypeName,
|
|
7
|
+
Imports,
|
|
8
|
+
OperationMethod,
|
|
7
9
|
PathMetadata,
|
|
8
10
|
Paths,
|
|
9
|
-
|
|
10
|
-
Imports
|
|
11
|
+
SchemaContext
|
|
11
12
|
} from "@azure-tools/rlc-common";
|
|
13
|
+
import {
|
|
14
|
+
isApiVersion,
|
|
15
|
+
listOperationGroups,
|
|
16
|
+
listOperationsInOperationGroup,
|
|
17
|
+
SdkClient
|
|
18
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
12
19
|
import { getDoc, ignoreDiagnostics } from "@typespec/compiler";
|
|
13
20
|
import {
|
|
14
21
|
getHttpOperation,
|
|
15
22
|
HttpOperation,
|
|
16
23
|
HttpOperationParameters
|
|
17
24
|
} from "@typespec/http";
|
|
18
|
-
import {
|
|
19
|
-
SdkClient,
|
|
20
|
-
listOperationGroups,
|
|
21
|
-
listOperationsInOperationGroup,
|
|
22
|
-
isApiVersion
|
|
23
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
25
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
24
26
|
import {
|
|
25
27
|
getImportedModelName,
|
|
26
28
|
getSchemaForType,
|
|
@@ -28,16 +30,14 @@ import {
|
|
|
28
30
|
} from "../utils/modelUtils.js";
|
|
29
31
|
import {
|
|
30
32
|
extractOperationLroDetail,
|
|
31
|
-
getOperationSuccessStatus,
|
|
32
33
|
getOperationGroupName,
|
|
33
34
|
getOperationName,
|
|
34
35
|
getOperationResponseTypes,
|
|
35
36
|
getOperationStatuscode,
|
|
37
|
+
getOperationSuccessStatus,
|
|
36
38
|
isPagingOperation,
|
|
37
39
|
sortedOperationResponses
|
|
38
40
|
} from "../utils/operationUtil.js";
|
|
39
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
40
|
-
import { SchemaContext } from "@azure-tools/rlc-common";
|
|
41
41
|
|
|
42
42
|
export function transformPaths(
|
|
43
43
|
client: SdkClient,
|
|
@@ -2,40 +2,40 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
listOperationsInOperationGroup
|
|
8
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
9
|
-
import {
|
|
10
|
-
ResponseHeaderSchema,
|
|
5
|
+
getLroLogicalResponseName,
|
|
6
|
+
Imports,
|
|
11
7
|
OperationResponse,
|
|
8
|
+
ResponseHeaderSchema,
|
|
12
9
|
ResponseMetadata,
|
|
13
10
|
Schema,
|
|
14
|
-
SchemaContext
|
|
15
|
-
getLroLogicalResponseName,
|
|
16
|
-
Imports
|
|
11
|
+
SchemaContext
|
|
17
12
|
} from "@azure-tools/rlc-common";
|
|
13
|
+
import {
|
|
14
|
+
listOperationGroups,
|
|
15
|
+
listOperationsInOperationGroup,
|
|
16
|
+
SdkClient
|
|
17
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
18
18
|
import { getDoc, ignoreDiagnostics, isVoidType } from "@typespec/compiler";
|
|
19
19
|
import {
|
|
20
20
|
getHttpOperation,
|
|
21
21
|
HttpOperation,
|
|
22
22
|
HttpOperationResponse
|
|
23
23
|
} from "@typespec/http";
|
|
24
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
24
25
|
import {
|
|
26
|
+
getBinaryType,
|
|
25
27
|
getImportedModelName,
|
|
26
|
-
getTypeName,
|
|
27
28
|
getSchemaForType,
|
|
28
|
-
|
|
29
|
+
getTypeName
|
|
29
30
|
} from "../utils/modelUtils.js";
|
|
30
31
|
import {
|
|
31
32
|
getOperationGroupName,
|
|
32
|
-
getOperationStatuscode,
|
|
33
|
-
isBinaryPayload,
|
|
34
33
|
getOperationLroOverload,
|
|
35
34
|
getOperationName,
|
|
35
|
+
getOperationStatuscode,
|
|
36
|
+
isBinaryPayload,
|
|
36
37
|
sortedOperationResponses
|
|
37
38
|
} from "../utils/operationUtil.js";
|
|
38
|
-
import { SdkContext } from "../utils/interfaces.js";
|
|
39
39
|
|
|
40
40
|
export function transformToResponseTypes(
|
|
41
41
|
client: SdkClient,
|
|
@@ -123,13 +123,16 @@ function transformHeaders(
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
const rlcHeaders =
|
|
126
|
+
const rlcHeaders: Map<string, ResponseHeaderSchema> = new Map();
|
|
127
127
|
// Current RLC client can't represent different headers per content type.
|
|
128
128
|
// So we merge headers here, and report any duplicates.
|
|
129
129
|
// It may be possible in principle to not error for identically declared
|
|
130
130
|
// headers.
|
|
131
131
|
for (const data of response.responses) {
|
|
132
|
-
const headers = data?.headers;
|
|
132
|
+
const headers = data?.headers ?? {};
|
|
133
|
+
if (data.body?.contentTypeProperty) {
|
|
134
|
+
headers["content-type"] = data.body?.contentTypeProperty;
|
|
135
|
+
}
|
|
133
136
|
if (!headers || !Object.keys(headers).length) {
|
|
134
137
|
continue;
|
|
135
138
|
}
|
|
@@ -152,11 +155,11 @@ function transformHeaders(
|
|
|
152
155
|
required: !value?.optional,
|
|
153
156
|
description: getDoc(dpgContext.program, value!)
|
|
154
157
|
};
|
|
155
|
-
rlcHeaders.
|
|
158
|
+
rlcHeaders.set(header.name, header);
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
return rlcHeaders.
|
|
162
|
+
return rlcHeaders.size ? Array.from(rlcHeaders.values()) : undefined;
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
function transformBody(
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
+
import { SchemaContext } from "@azure-tools/rlc-common";
|
|
4
5
|
import {
|
|
5
|
-
SdkClient,
|
|
6
6
|
listOperationGroups,
|
|
7
|
-
listOperationsInOperationGroup
|
|
7
|
+
listOperationsInOperationGroup,
|
|
8
|
+
SdkClient
|
|
8
9
|
} from "@azure-tools/typespec-client-generator-core";
|
|
9
|
-
import { SchemaContext } from "@azure-tools/rlc-common";
|
|
10
10
|
import { ignoreDiagnostics, Model, Type } from "@typespec/compiler";
|
|
11
11
|
import { getHttpOperation, getServers, HttpOperation } from "@typespec/http";
|
|
12
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
13
|
+
import { extractMediaTypes, KnownMediaType } from "../utils/mediaTypes.js";
|
|
12
14
|
import {
|
|
15
|
+
getBodyType,
|
|
16
|
+
getDefaultService,
|
|
13
17
|
getSchemaForType,
|
|
14
18
|
includeDerivedModel,
|
|
15
|
-
getBodyType,
|
|
16
|
-
trimUsage,
|
|
17
19
|
isAzureCoreErrorType,
|
|
18
|
-
|
|
20
|
+
trimUsage
|
|
19
21
|
} from "../utils/modelUtils.js";
|
|
20
|
-
import {
|
|
21
|
-
import { KnownMediaType, extractMediaTypes } from "../utils/mediaTypes.js";
|
|
22
|
+
import { useContext } from "../contextManager.js";
|
|
22
23
|
|
|
23
24
|
export function transformSchemas(client: SdkClient, dpgContext: SdkContext) {
|
|
24
25
|
const program = dpgContext.program;
|
|
@@ -87,6 +88,12 @@ export function transformSchemas(client: SdkClient, dpgContext: SdkContext) {
|
|
|
87
88
|
getGeneratedModels(value, SchemaContext.Output);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
91
|
+
if (resps.body?.contentTypeProperty) {
|
|
92
|
+
getGeneratedModels(
|
|
93
|
+
resps.body.contentTypeProperty,
|
|
94
|
+
SchemaContext.Output
|
|
95
|
+
);
|
|
96
|
+
}
|
|
90
97
|
const respModel = resps?.body?.type;
|
|
91
98
|
if (!respModel) {
|
|
92
99
|
continue;
|
|
@@ -112,6 +119,7 @@ export function transformSchemas(client: SdkClient, dpgContext: SdkContext) {
|
|
|
112
119
|
}
|
|
113
120
|
transformHostParameters();
|
|
114
121
|
usageMap.forEach((context, tspModel) => {
|
|
122
|
+
const metatree = useContext("rlcMetaTree");
|
|
115
123
|
const model = getSchemaForType(dpgContext, tspModel, {
|
|
116
124
|
usage: context,
|
|
117
125
|
isRequestBody: requestBodySet.has(tspModel),
|
|
@@ -121,6 +129,7 @@ export function transformSchemas(client: SdkClient, dpgContext: SdkContext) {
|
|
|
121
129
|
if (model) {
|
|
122
130
|
model.usage = context;
|
|
123
131
|
}
|
|
132
|
+
metatree.set(tspModel, { rlcType: model });
|
|
124
133
|
if (model.name === "") {
|
|
125
134
|
return;
|
|
126
135
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TelemetryInfo } from "@azure-tools/rlc-common";
|
|
2
2
|
import {
|
|
3
|
-
SdkClient,
|
|
4
|
-
SdkContext,
|
|
5
3
|
listOperationGroups,
|
|
6
|
-
listOperationsInOperationGroup
|
|
4
|
+
listOperationsInOperationGroup,
|
|
5
|
+
SdkClient,
|
|
6
|
+
SdkContext
|
|
7
7
|
} from "@azure-tools/typespec-client-generator-core";
|
|
8
8
|
import { ignoreDiagnostics } from "@typespec/compiler";
|
|
9
|
-
import { getCustomRequestHeaderNameForOperation } from "../utils/operationUtil.js";
|
|
10
9
|
import { getHttpOperation } from "@typespec/http";
|
|
10
|
+
import { getCustomRequestHeaderNameForOperation } from "../utils/operationUtil.js";
|
|
11
11
|
|
|
12
12
|
export function transformTelemetryInfo(
|
|
13
13
|
client: SdkClient,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
pascalCase,
|
|
2
3
|
NameType,
|
|
3
4
|
normalizeName,
|
|
4
5
|
PackageDetails,
|
|
@@ -6,6 +7,10 @@ import {
|
|
|
6
7
|
RLCOptions,
|
|
7
8
|
ServiceInfo
|
|
8
9
|
} from "@azure-tools/rlc-common";
|
|
10
|
+
import {
|
|
11
|
+
listOperationGroups,
|
|
12
|
+
listOperationsInOperationGroup
|
|
13
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
9
14
|
import {
|
|
10
15
|
getDoc,
|
|
11
16
|
ignoreDiagnostics,
|
|
@@ -14,15 +19,11 @@ import {
|
|
|
14
19
|
} from "@typespec/compiler";
|
|
15
20
|
import { getAuthentication, getHttpOperation } from "@typespec/http";
|
|
16
21
|
import { EmitterOptions, reportDiagnostic } from "../lib.js";
|
|
17
|
-
import { getDefaultService } from "../utils/modelUtils.js";
|
|
18
22
|
import { getRLCClients } from "../utils/clientUtils.js";
|
|
19
23
|
import { SdkContext } from "../utils/interfaces.js";
|
|
20
|
-
import {
|
|
21
|
-
listOperationGroups,
|
|
22
|
-
listOperationsInOperationGroup
|
|
23
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
24
|
-
import { getOperationName } from "../utils/operationUtil.js";
|
|
24
|
+
import { getDefaultService } from "../utils/modelUtils.js";
|
|
25
25
|
import { detectModelConflicts } from "../utils/namespaceUtils.js";
|
|
26
|
+
import { getOperationName } from "../utils/operationUtil.js";
|
|
26
27
|
|
|
27
28
|
export function transformRLCOptions(
|
|
28
29
|
emitterOptions: EmitterOptions,
|
|
@@ -106,7 +107,13 @@ function processAuth(program: Program) {
|
|
|
106
107
|
case "http":
|
|
107
108
|
securityInfo.addCredentials = true;
|
|
108
109
|
securityInfo.customHttpAuthHeaderName = "Authorization";
|
|
109
|
-
|
|
110
|
+
// If it is basic or bearer auth we should generate it as Basic or Bearer
|
|
111
|
+
securityInfo.customHttpAuthSharedKeyPrefix = [
|
|
112
|
+
"basic",
|
|
113
|
+
"bearer"
|
|
114
|
+
].includes(auth.scheme.toLowerCase())
|
|
115
|
+
? pascalCase(auth.scheme)
|
|
116
|
+
: auth.scheme;
|
|
110
117
|
break;
|
|
111
118
|
case "apiKey":
|
|
112
119
|
if (auth.in === "cookie") {
|
package/src/utils/clientUtils.ts
CHANGED
package/src/utils/emitUtil.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
buildSchemaTypes,
|
|
3
|
+
ContentBuilder,
|
|
4
|
+
File,
|
|
5
|
+
RLCModel
|
|
6
|
+
} from "@azure-tools/rlc-common";
|
|
4
7
|
import { CompilerHost, Program } from "@typespec/compiler";
|
|
5
8
|
import { dirname, join } from "path";
|
|
6
9
|
import { format } from "prettier";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { dirname, relative, resolve } from "path";
|
|
2
|
+
import { useContext } from "../contextManager.js";
|
|
3
|
+
import { SourceFile } from "ts-morph";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Adds a named import to a TypeScript source file if it does not already exist.
|
|
7
|
+
* Utilizes a global symbol map context to resolve module paths and ensure the import is correctly referenced.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} symbol The name of the export to import.
|
|
10
|
+
* @param {SourceFile} currentFile The ts-morph SourceFile object where the import will be added.
|
|
11
|
+
*/
|
|
12
|
+
export function addImportBySymbol(symbol: string, currentFile: SourceFile) {
|
|
13
|
+
// Retrieve the global map of symbols to their source files.
|
|
14
|
+
const symbolMap = useContext("symbolMap");
|
|
15
|
+
|
|
16
|
+
// Attempt to resolve the file path for the given symbol.
|
|
17
|
+
const modulePath = symbolMap.get(symbol)?.getFilePath();
|
|
18
|
+
if (!modulePath) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Resolve absolute path and compute a relative path from the current file to the module.
|
|
23
|
+
const moduleAbsolutePath = resolve(modulePath);
|
|
24
|
+
const relativeImportPath = getRelativeImportPath(
|
|
25
|
+
currentFile.getFilePath(),
|
|
26
|
+
moduleAbsolutePath
|
|
27
|
+
)
|
|
28
|
+
.replace(/\\/g, "/")
|
|
29
|
+
.replace(/\.ts$/, ".js");
|
|
30
|
+
|
|
31
|
+
// Check if the import declaration already exists and if it includes the symbol.
|
|
32
|
+
const existing = currentFile.getImportDeclaration(
|
|
33
|
+
(i) => i.getModuleSpecifierValue() === relativeImportPath
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (existing) {
|
|
37
|
+
const sameImport = existing
|
|
38
|
+
.getNamedImports()
|
|
39
|
+
.some((i) => i.getName() === symbol);
|
|
40
|
+
|
|
41
|
+
if (!sameImport) {
|
|
42
|
+
existing.addNamedImport(symbol);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
currentFile.addImportDeclaration({
|
|
46
|
+
moduleSpecifier: relativeImportPath,
|
|
47
|
+
namedImports: [symbol]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Computes a relative import path suitable for TypeScript imports given two file paths.
|
|
54
|
+
* Ensures the returned path starts with './' if necessary to be recognized as a relative module.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} from The file path to import from.
|
|
57
|
+
* @param {string} to The file path to import to.
|
|
58
|
+
* @returns {string} The relative path adjusted for import syntax.
|
|
59
|
+
*/
|
|
60
|
+
function getRelativeImportPath(from: string, to: string) {
|
|
61
|
+
const relativePath = relative(dirname(from), to);
|
|
62
|
+
// Adjust the path format to TypeScript module syntax
|
|
63
|
+
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
64
|
+
}
|