@typespec/http-client-python 0.8.0 → 0.8.2
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/README.md +92 -84
- package/dist/emitter/code-model.d.ts +1 -2
- package/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +2 -2
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/emitter.d.ts +0 -2
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +21 -32
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/http.d.ts +4 -4
- package/dist/emitter/http.d.ts.map +1 -1
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/index.d.ts +1 -1
- package/dist/emitter/index.d.ts.map +1 -1
- package/dist/emitter/index.js +1 -1
- package/dist/emitter/index.js.map +1 -1
- package/dist/emitter/lib.d.ts +65 -21
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +56 -26
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/types.d.ts +3 -3
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +2 -2
- package/dist/emitter/types.js.map +1 -1
- package/dist/emitter/utils.d.ts +5 -4
- package/dist/emitter/utils.d.ts.map +1 -1
- package/dist/emitter/utils.js +31 -16
- package/dist/emitter/utils.js.map +1 -1
- package/emitter/src/code-model.ts +12 -19
- package/emitter/src/emitter.ts +35 -51
- package/emitter/src/http.ts +18 -21
- package/emitter/src/index.ts +1 -1
- package/emitter/src/lib.ts +68 -40
- package/emitter/src/types.ts +15 -25
- package/emitter/src/utils.ts +36 -25
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/Generate.ps1 +3 -0
- package/eng/scripts/ci/regenerate.ts +92 -41
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/generator/build/lib/pygen/codegen/__init__.py +0 -2
- package/generator/build/lib/pygen/codegen/models/code_model.py +5 -5
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +18 -14
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +5 -2
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +6 -2
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +5 -5
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +3 -3
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +14 -5
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/__init__.py +0 -2
- package/generator/pygen/codegen/models/code_model.py +5 -5
- package/generator/pygen/codegen/serializers/__init__.py +18 -14
- package/generator/pygen/codegen/serializers/general_serializer.py +5 -2
- package/generator/pygen/codegen/serializers/test_serializer.py +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +6 -2
- package/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +5 -5
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +3 -3
- package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +14 -5
- package/generator/pygen.egg-info/PKG-INFO +2 -2
- package/generator/pygen.egg-info/requires.txt +2 -2
- package/generator/setup.py +2 -2
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +1 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_rpc_async.py +2 -2
- package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +1 -0
- package/generator/test/azure/mock_api_tests/test_azure_core_lro_rpc.py +1 -1
- package/generator/test/azure/requirements.txt +1 -1
- package/generator/test/azure/tox.ini +2 -2
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +4 -3
- package/generator/test/generic_mock_api_tests/asynctests/test_parameters_collection_format_async.py +0 -6
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py +1 -0
- package/generator/test/generic_mock_api_tests/test_encode_bytes.py +4 -3
- package/generator/test/generic_mock_api_tests/test_parameters_collection_format.py +0 -4
- package/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py +1 -0
- package/generator/test/unbranded/tox.ini +2 -2
- package/package.json +27 -26
|
@@ -32,15 +32,10 @@ import {
|
|
|
32
32
|
simpleTypesMap,
|
|
33
33
|
typesMap,
|
|
34
34
|
} from "./types.js";
|
|
35
|
-
import {
|
|
36
|
-
emitParamBase,
|
|
37
|
-
getClientNamespace,
|
|
38
|
-
getImplementation,
|
|
39
|
-
removeUnderscoresFromNamespace,
|
|
40
|
-
} from "./utils.js";
|
|
35
|
+
import { emitParamBase, getClientNamespace, getImplementation, getRootNamespace } from "./utils.js";
|
|
41
36
|
|
|
42
37
|
function emitBasicMethod<TServiceOperation extends SdkServiceOperation>(
|
|
43
|
-
context: PythonSdkContext
|
|
38
|
+
context: PythonSdkContext,
|
|
44
39
|
rootClient: SdkClientType<TServiceOperation>,
|
|
45
40
|
method: SdkBasicServiceMethod<TServiceOperation>,
|
|
46
41
|
operationGroupName: string,
|
|
@@ -56,7 +51,7 @@ function emitBasicMethod<TServiceOperation extends SdkServiceOperation>(
|
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
function emitLroMethod<TServiceOperation extends SdkServiceOperation>(
|
|
59
|
-
context: PythonSdkContext
|
|
54
|
+
context: PythonSdkContext,
|
|
60
55
|
rootClient: SdkClientType<TServiceOperation>,
|
|
61
56
|
method: SdkLroServiceMethod<TServiceOperation>,
|
|
62
57
|
operationGroupName: string,
|
|
@@ -72,7 +67,7 @@ function emitLroMethod<TServiceOperation extends SdkServiceOperation>(
|
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
function emitPagingMethod<TServiceOperation extends SdkServiceOperation>(
|
|
75
|
-
context: PythonSdkContext
|
|
70
|
+
context: PythonSdkContext,
|
|
76
71
|
rootClient: SdkClientType<TServiceOperation>,
|
|
77
72
|
method: SdkPagingServiceMethod<TServiceOperation>,
|
|
78
73
|
operationGroupName: string,
|
|
@@ -88,7 +83,7 @@ function emitPagingMethod<TServiceOperation extends SdkServiceOperation>(
|
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(
|
|
91
|
-
context: PythonSdkContext
|
|
86
|
+
context: PythonSdkContext,
|
|
92
87
|
rootClient: SdkClientType<TServiceOperation>,
|
|
93
88
|
method: SdkLroPagingServiceMethod<TServiceOperation>,
|
|
94
89
|
operationGroupName: string,
|
|
@@ -103,8 +98,8 @@ function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(
|
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
function emitMethodParameter
|
|
107
|
-
context: PythonSdkContext
|
|
101
|
+
function emitMethodParameter(
|
|
102
|
+
context: PythonSdkContext,
|
|
108
103
|
parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter,
|
|
109
104
|
): Record<string, any>[] {
|
|
110
105
|
if (parameter.kind === "endpoint") {
|
|
@@ -158,7 +153,7 @@ function emitMethodParameter<TServiceOperation extends SdkServiceOperation>(
|
|
|
158
153
|
}
|
|
159
154
|
|
|
160
155
|
function emitMethod<TServiceOperation extends SdkServiceOperation>(
|
|
161
|
-
context: PythonSdkContext
|
|
156
|
+
context: PythonSdkContext,
|
|
162
157
|
rootClient: SdkClientType<TServiceOperation>,
|
|
163
158
|
method: SdkServiceMethod<TServiceOperation>,
|
|
164
159
|
operationGroupName: string,
|
|
@@ -176,7 +171,7 @@ function emitMethod<TServiceOperation extends SdkServiceOperation>(
|
|
|
176
171
|
}
|
|
177
172
|
|
|
178
173
|
function emitOperationGroups<TServiceOperation extends SdkServiceOperation>(
|
|
179
|
-
context: PythonSdkContext
|
|
174
|
+
context: PythonSdkContext,
|
|
180
175
|
client: SdkClientType<TServiceOperation>,
|
|
181
176
|
rootClient: SdkClientType<TServiceOperation>,
|
|
182
177
|
prefix: string,
|
|
@@ -232,7 +227,7 @@ function emitOperationGroups<TServiceOperation extends SdkServiceOperation>(
|
|
|
232
227
|
}
|
|
233
228
|
|
|
234
229
|
function emitClient<TServiceOperation extends SdkServiceOperation>(
|
|
235
|
-
context: PythonSdkContext
|
|
230
|
+
context: PythonSdkContext,
|
|
236
231
|
client: SdkClientType<TServiceOperation>,
|
|
237
232
|
): Record<string, any> {
|
|
238
233
|
if (client.clientInitialization) {
|
|
@@ -275,13 +270,11 @@ function onlyUsedByPolling(usage: UsageFlags): boolean {
|
|
|
275
270
|
);
|
|
276
271
|
}
|
|
277
272
|
|
|
278
|
-
export function emitCodeModel
|
|
279
|
-
sdkContext: PythonSdkContext<TServiceOperation>,
|
|
280
|
-
) {
|
|
273
|
+
export function emitCodeModel(sdkContext: PythonSdkContext) {
|
|
281
274
|
// Get types
|
|
282
275
|
const sdkPackage = sdkContext.sdkPackage;
|
|
283
276
|
const codeModel: Record<string, any> = {
|
|
284
|
-
namespace:
|
|
277
|
+
namespace: getRootNamespace(sdkContext),
|
|
285
278
|
clients: [],
|
|
286
279
|
};
|
|
287
280
|
for (const client of sdkPackage.clients) {
|
package/emitter/src/emitter.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createSdkContext,
|
|
3
|
-
SdkContext,
|
|
4
|
-
SdkHttpOperation,
|
|
5
|
-
SdkServiceOperation,
|
|
6
|
-
} from "@azure-tools/typespec-client-generator-core";
|
|
1
|
+
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
7
2
|
import { EmitContext, NoTarget } from "@typespec/compiler";
|
|
8
3
|
import { execSync } from "child_process";
|
|
9
4
|
import fs from "fs";
|
|
@@ -16,60 +11,53 @@ import { saveCodeModelAsYaml } from "./external-process.js";
|
|
|
16
11
|
import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js";
|
|
17
12
|
import { runPython3 } from "./run-python3.js";
|
|
18
13
|
import { disableGenerationMap, simpleTypesMap, typesMap } from "./types.js";
|
|
19
|
-
import {
|
|
14
|
+
import { getRootNamespace, md2Rst } from "./utils.js";
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
const specifiedModelsMode = context.emitContext.options["models-mode"];
|
|
23
|
-
if (specifiedModelsMode) {
|
|
24
|
-
const modelModes = ["dpg", "none"];
|
|
25
|
-
if (modelModes.includes(specifiedModelsMode)) {
|
|
26
|
-
return specifiedModelsMode;
|
|
27
|
-
}
|
|
28
|
-
reportDiagnostic(context.program, {
|
|
29
|
-
code: "invalid-models-mode",
|
|
30
|
-
target: NoTarget,
|
|
31
|
-
format: { inValidValue: specifiedModelsMode },
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return "dpg";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function addDefaultOptions(sdkContext: SdkContext) {
|
|
16
|
+
function addDefaultOptions(sdkContext: PythonSdkContext) {
|
|
38
17
|
const defaultOptions = {
|
|
39
18
|
"package-version": "1.0.0b1",
|
|
40
19
|
"generate-packaging-files": true,
|
|
41
|
-
flavor: undefined,
|
|
42
20
|
};
|
|
43
21
|
sdkContext.emitContext.options = {
|
|
44
22
|
...defaultOptions,
|
|
45
23
|
...sdkContext.emitContext.options,
|
|
46
24
|
};
|
|
47
25
|
const options = sdkContext.emitContext.options;
|
|
48
|
-
options["models-mode"] = getModelsMode(sdkContext);
|
|
49
|
-
if (options["generate-packaging-files"]) {
|
|
50
|
-
options["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane";
|
|
51
|
-
}
|
|
52
26
|
if (!options["package-name"]) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
const namespace = getRootNamespace(sdkContext);
|
|
28
|
+
const packageName = namespace.replace(/\./g, "-");
|
|
29
|
+
reportDiagnostic(sdkContext.program, {
|
|
30
|
+
code: "no-package-name",
|
|
31
|
+
target: NoTarget,
|
|
32
|
+
format: { namespace, packageName },
|
|
33
|
+
});
|
|
34
|
+
options["package-name"] = packageName;
|
|
56
35
|
}
|
|
57
|
-
if (options.flavor !== "azure") {
|
|
36
|
+
if ((options as any).flavor !== "azure") {
|
|
58
37
|
// if they pass in a flavor other than azure, we want to ignore the value
|
|
59
|
-
options.flavor = undefined;
|
|
38
|
+
(options as any).flavor = undefined;
|
|
60
39
|
}
|
|
61
|
-
if (
|
|
62
|
-
options.flavor
|
|
40
|
+
if (
|
|
41
|
+
(options as any).flavor === undefined &&
|
|
42
|
+
sdkContext.emitContext.emitterOutputDir.includes("azure")
|
|
43
|
+
) {
|
|
44
|
+
(options as any).flavor = "azure";
|
|
63
45
|
}
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
options["package-pprint-name"] !== undefined &&
|
|
49
|
+
!options["package-pprint-name"].startsWith('"')
|
|
50
|
+
) {
|
|
51
|
+
options["package-pprint-name"] = options["use-pyodide"]
|
|
52
|
+
? `${options["package-pprint-name"]}`
|
|
53
|
+
: `"${options["package-pprint-name"]}"`;
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
56
|
|
|
69
|
-
async function createPythonSdkContext
|
|
57
|
+
async function createPythonSdkContext(
|
|
70
58
|
context: EmitContext<PythonEmitterOptions>,
|
|
71
|
-
): Promise<PythonSdkContext
|
|
72
|
-
const sdkContext = await createSdkContext<PythonEmitterOptions
|
|
59
|
+
): Promise<PythonSdkContext> {
|
|
60
|
+
const sdkContext = await createSdkContext<PythonEmitterOptions>(
|
|
73
61
|
context,
|
|
74
62
|
"@azure-tools/typespec-python",
|
|
75
63
|
);
|
|
@@ -146,7 +134,7 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
|
|
|
146
134
|
cleanAllCache();
|
|
147
135
|
|
|
148
136
|
const program = context.program;
|
|
149
|
-
const sdkContext = await createPythonSdkContext
|
|
137
|
+
const sdkContext = await createPythonSdkContext(context);
|
|
150
138
|
const root = path.join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
151
139
|
const outputDir = context.emitterOutputDir;
|
|
152
140
|
addDefaultOptions(sdkContext);
|
|
@@ -173,25 +161,21 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
|
|
|
173
161
|
commandArgs["packaging-files-config"] = keyValuePairs.join("|");
|
|
174
162
|
resolvedOptions["packaging-files-config"] = undefined;
|
|
175
163
|
}
|
|
176
|
-
if (
|
|
177
|
-
resolvedOptions["package-pprint-name"] !== undefined &&
|
|
178
|
-
!resolvedOptions["package-pprint-name"].startsWith('"')
|
|
179
|
-
) {
|
|
180
|
-
resolvedOptions["package-pprint-name"] = resolvedOptions["use-pyodide"]
|
|
181
|
-
? `${resolvedOptions["package-pprint-name"]}`
|
|
182
|
-
: `"${resolvedOptions["package-pprint-name"]}"`;
|
|
183
|
-
}
|
|
184
164
|
|
|
185
165
|
for (const [key, value] of Object.entries(resolvedOptions)) {
|
|
186
166
|
commandArgs[key] = value;
|
|
187
167
|
}
|
|
168
|
+
if (resolvedOptions["generate-packaging-files"]) {
|
|
169
|
+
commandArgs["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane";
|
|
170
|
+
}
|
|
188
171
|
if (sdkContext.arm === true) {
|
|
189
172
|
commandArgs["azure-arm"] = "true";
|
|
190
173
|
}
|
|
191
|
-
if (resolvedOptions.flavor === "azure") {
|
|
174
|
+
if ((resolvedOptions as any).flavor === "azure") {
|
|
192
175
|
commandArgs["emit-cross-language-definition-file"] = "true";
|
|
193
176
|
}
|
|
194
177
|
commandArgs["from-typespec"] = "true";
|
|
178
|
+
commandArgs["models-mode"] = (resolvedOptions as any)["models-mode"] ?? "dpg";
|
|
195
179
|
|
|
196
180
|
if (!program.compilerOptions.noEmit && !program.hasError()) {
|
|
197
181
|
// if not using pyodide and there's no venv, we try to create venv
|
package/emitter/src/http.ts
CHANGED
|
@@ -48,7 +48,7 @@ function arrayToRecord(examples: SdkHttpOperationExample[] | undefined): Record<
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function emitBasicHttpMethod(
|
|
51
|
-
context: PythonSdkContext
|
|
51
|
+
context: PythonSdkContext,
|
|
52
52
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
53
53
|
method: SdkBasicServiceMethod<SdkHttpOperation>,
|
|
54
54
|
operationGroupName: string,
|
|
@@ -65,7 +65,7 @@ export function emitBasicHttpMethod(
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function emitInitialLroHttpMethod(
|
|
68
|
-
context: PythonSdkContext
|
|
68
|
+
context: PythonSdkContext,
|
|
69
69
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
70
70
|
method: SdkLroServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
71
71
|
operationGroupName: string,
|
|
@@ -82,7 +82,7 @@ function emitInitialLroHttpMethod(
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function addLroInformation(
|
|
85
|
-
context: PythonSdkContext
|
|
85
|
+
context: PythonSdkContext,
|
|
86
86
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
87
87
|
method: SdkLroServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
88
88
|
operationGroupName: string,
|
|
@@ -110,7 +110,7 @@ function getWireNameFromPropertySegments(segments: SdkModelPropertyType[]): stri
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function getWireNameWithDiagnostics(
|
|
113
|
-
context: PythonSdkContext
|
|
113
|
+
context: PythonSdkContext,
|
|
114
114
|
segments: SdkModelPropertyType[] | undefined,
|
|
115
115
|
code: "invalid-paging-items" | "invalid-next-link" | "invalid-lro-result",
|
|
116
116
|
method?: SdkServiceMethod<SdkHttpOperation>,
|
|
@@ -132,7 +132,7 @@ function getWireNameWithDiagnostics(
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function buildContinuationToken(
|
|
135
|
-
context: PythonSdkContext
|
|
135
|
+
context: PythonSdkContext,
|
|
136
136
|
method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
137
137
|
segments: SdkModelPropertyType[],
|
|
138
138
|
input: boolean = true,
|
|
@@ -166,7 +166,7 @@ function buildContinuationToken(
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
function buildAllContinuationToken(
|
|
169
|
-
context: PythonSdkContext
|
|
169
|
+
context: PythonSdkContext,
|
|
170
170
|
method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
171
171
|
): Record<string, any> {
|
|
172
172
|
const parameterSegments = method.pagingMetadata.continuationTokenParameterSegments ?? [];
|
|
@@ -181,7 +181,7 @@ function buildAllContinuationToken(
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
function addPagingInformation(
|
|
184
|
-
context: PythonSdkContext
|
|
184
|
+
context: PythonSdkContext,
|
|
185
185
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
186
186
|
method: SdkPagingServiceMethod<SdkHttpOperation> | SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
187
187
|
operationGroupName: string,
|
|
@@ -223,7 +223,7 @@ function addPagingInformation(
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
export function emitLroHttpMethod(
|
|
226
|
-
context: PythonSdkContext
|
|
226
|
+
context: PythonSdkContext,
|
|
227
227
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
228
228
|
method: SdkLroServiceMethod<SdkHttpOperation>,
|
|
229
229
|
operationGroupName: string,
|
|
@@ -233,7 +233,7 @@ export function emitLroHttpMethod(
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
export function emitPagingHttpMethod(
|
|
236
|
-
context: PythonSdkContext
|
|
236
|
+
context: PythonSdkContext,
|
|
237
237
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
238
238
|
method: SdkPagingServiceMethod<SdkHttpOperation>,
|
|
239
239
|
operationGroupName: string,
|
|
@@ -243,7 +243,7 @@ export function emitPagingHttpMethod(
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
export function emitLroPagingHttpMethod(
|
|
246
|
-
context: PythonSdkContext
|
|
246
|
+
context: PythonSdkContext,
|
|
247
247
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
248
248
|
method: SdkLroPagingServiceMethod<SdkHttpOperation>,
|
|
249
249
|
operationGroupName: string,
|
|
@@ -254,7 +254,7 @@ export function emitLroPagingHttpMethod(
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
function emitHttpOperation(
|
|
257
|
-
context: PythonSdkContext
|
|
257
|
+
context: PythonSdkContext,
|
|
258
258
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
259
259
|
operationGroupName: string,
|
|
260
260
|
operation: SdkHttpOperation,
|
|
@@ -339,10 +339,7 @@ function emitFlattenedParameter(
|
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
function emitHttpPathParameter(
|
|
343
|
-
context: PythonSdkContext<SdkHttpOperation>,
|
|
344
|
-
parameter: SdkPathParameter,
|
|
345
|
-
) {
|
|
342
|
+
function emitHttpPathParameter(context: PythonSdkContext, parameter: SdkPathParameter) {
|
|
346
343
|
const base = emitParamBase(context, parameter);
|
|
347
344
|
return {
|
|
348
345
|
...base,
|
|
@@ -354,7 +351,7 @@ function emitHttpPathParameter(
|
|
|
354
351
|
};
|
|
355
352
|
}
|
|
356
353
|
function emitHttpHeaderParameter(
|
|
357
|
-
context: PythonSdkContext
|
|
354
|
+
context: PythonSdkContext,
|
|
358
355
|
parameter: SdkHeaderParameter,
|
|
359
356
|
method: SdkServiceMethod<SdkHttpOperation>,
|
|
360
357
|
): Record<string, any> {
|
|
@@ -380,7 +377,7 @@ function emitHttpHeaderParameter(
|
|
|
380
377
|
}
|
|
381
378
|
|
|
382
379
|
function emitHttpQueryParameter(
|
|
383
|
-
context: PythonSdkContext
|
|
380
|
+
context: PythonSdkContext,
|
|
384
381
|
parameter: SdkQueryParameter,
|
|
385
382
|
method: SdkServiceMethod<SdkHttpOperation>,
|
|
386
383
|
): Record<string, any> {
|
|
@@ -398,7 +395,7 @@ function emitHttpQueryParameter(
|
|
|
398
395
|
}
|
|
399
396
|
|
|
400
397
|
function emitHttpParameters(
|
|
401
|
-
context: PythonSdkContext
|
|
398
|
+
context: PythonSdkContext,
|
|
402
399
|
rootClient: SdkClientType<SdkHttpOperation>,
|
|
403
400
|
operation: SdkHttpOperation,
|
|
404
401
|
method: SdkServiceMethod<SdkHttpOperation>,
|
|
@@ -421,7 +418,7 @@ function emitHttpParameters(
|
|
|
421
418
|
}
|
|
422
419
|
|
|
423
420
|
function emitHttpBodyParameter(
|
|
424
|
-
context: PythonSdkContext
|
|
421
|
+
context: PythonSdkContext,
|
|
425
422
|
bodyParam?: SdkBodyParameter,
|
|
426
423
|
): Record<string, any> | undefined {
|
|
427
424
|
if (bodyParam === undefined) return undefined;
|
|
@@ -438,7 +435,7 @@ function emitHttpBodyParameter(
|
|
|
438
435
|
}
|
|
439
436
|
|
|
440
437
|
function emitHttpResponse(
|
|
441
|
-
context: PythonSdkContext
|
|
438
|
+
context: PythonSdkContext,
|
|
442
439
|
statusCodes: HttpStatusCodeRange | number | "*",
|
|
443
440
|
response: SdkHttpResponse | SdkHttpErrorResponse,
|
|
444
441
|
method?: SdkServiceMethod<SdkHttpOperation>,
|
|
@@ -479,7 +476,7 @@ function emitHttpResponse(
|
|
|
479
476
|
}
|
|
480
477
|
|
|
481
478
|
function emitHttpResponseHeader(
|
|
482
|
-
context: PythonSdkContext
|
|
479
|
+
context: PythonSdkContext,
|
|
483
480
|
header: SdkServiceResponseHeader,
|
|
484
481
|
): Record<string, any> {
|
|
485
482
|
return {
|
package/emitter/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./emitter.js";
|
|
2
|
-
export { $lib } from "./lib.js";
|
|
2
|
+
export { $lib, PythonEmitterOptions, PythonEmitterOptionsSchema } from "./lib.js";
|
package/emitter/src/lib.ts
CHANGED
|
@@ -1,54 +1,82 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SdkContext,
|
|
3
|
+
SdkEmitterOptions,
|
|
4
|
+
SdkEmitterOptionsSchema,
|
|
5
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
2
6
|
import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler";
|
|
3
7
|
|
|
4
|
-
export interface PythonEmitterOptions {
|
|
8
|
+
export interface PythonEmitterOptions extends SdkEmitterOptions {
|
|
5
9
|
"package-version"?: string;
|
|
6
10
|
"package-name"?: string;
|
|
7
|
-
"output-dir"?: string;
|
|
8
11
|
"generate-packaging-files"?: boolean;
|
|
9
12
|
"packaging-files-dir"?: string;
|
|
10
13
|
"packaging-files-config"?: object;
|
|
11
14
|
"package-pprint-name"?: string;
|
|
12
15
|
"head-as-boolean"?: boolean;
|
|
13
|
-
"models-mode"?: string;
|
|
14
|
-
tracing?: boolean;
|
|
15
16
|
"company-name"?: string;
|
|
16
|
-
"generate-test"?: boolean;
|
|
17
|
-
debug?: boolean;
|
|
18
|
-
flavor?: "azure";
|
|
19
|
-
"examples-dir"?: string;
|
|
20
|
-
// If true, package namespace will respect the typespec namespace. Otherwise,
|
|
21
|
-
// package namespace is always aligned with package name.
|
|
22
|
-
"enable-typespec-namespace"?: boolean;
|
|
23
17
|
"use-pyodide"?: boolean;
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
export interface PythonSdkContext
|
|
27
|
-
extends SdkContext<PythonEmitterOptions, TServiceOperation> {
|
|
20
|
+
export interface PythonSdkContext extends SdkContext<PythonEmitterOptions> {
|
|
28
21
|
__endpointPathParameters: Record<string, any>[];
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
const
|
|
24
|
+
export const PythonEmitterOptionsSchema: JSONSchemaType<PythonEmitterOptions> = {
|
|
32
25
|
type: "object",
|
|
33
26
|
additionalProperties: true,
|
|
34
27
|
properties: {
|
|
35
|
-
"package-version": {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
28
|
+
"package-version": {
|
|
29
|
+
type: "string",
|
|
30
|
+
nullable: true,
|
|
31
|
+
description: "The version of the package.",
|
|
32
|
+
},
|
|
33
|
+
"package-name": {
|
|
34
|
+
type: "string",
|
|
35
|
+
nullable: true,
|
|
36
|
+
description: "The name of the package.",
|
|
37
|
+
},
|
|
38
|
+
"generate-packaging-files": {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
nullable: true,
|
|
41
|
+
description:
|
|
42
|
+
"Whether to generate packaging files. Packaging files refer to the `setup.py`, `README`, and other files that are needed to package your code.",
|
|
43
|
+
},
|
|
44
|
+
"packaging-files-dir": {
|
|
45
|
+
type: "string",
|
|
46
|
+
nullable: true,
|
|
47
|
+
description:
|
|
48
|
+
"If you are using a custom packaging files directory, you can specify it here. We won't generate with the default packaging files we have.",
|
|
49
|
+
},
|
|
50
|
+
"packaging-files-config": {
|
|
51
|
+
type: "object",
|
|
52
|
+
nullable: true,
|
|
53
|
+
description:
|
|
54
|
+
"If you are using a custom packaging files directory, and have additional configuration parameters you want to pass in during generation, you can specify it here. Only applicable if `packaging-files-dir` is set.",
|
|
55
|
+
},
|
|
56
|
+
"package-pprint-name": {
|
|
57
|
+
type: "string",
|
|
58
|
+
nullable: true,
|
|
59
|
+
description:
|
|
60
|
+
"The name of the package to be used in pretty-printing. Will be the name of the package in `README` and pprinting of `setup.py`.",
|
|
61
|
+
},
|
|
62
|
+
"head-as-boolean": {
|
|
63
|
+
type: "boolean",
|
|
64
|
+
nullable: true,
|
|
65
|
+
description: "Whether to return responses from HEAD requests as boolean. Defaults to `true`.",
|
|
66
|
+
},
|
|
67
|
+
"company-name": {
|
|
68
|
+
type: "string",
|
|
69
|
+
nullable: true,
|
|
70
|
+
description:
|
|
71
|
+
"The name of the company. This will be reflected in your license files and documentation.",
|
|
72
|
+
},
|
|
73
|
+
"use-pyodide": {
|
|
74
|
+
type: "boolean",
|
|
75
|
+
nullable: true,
|
|
76
|
+
description:
|
|
77
|
+
"Whether to generate using `pyodide` instead of `python`. If there is no python installed on your device, we will default to using pyodide to generate the code.",
|
|
78
|
+
},
|
|
79
|
+
...SdkEmitterOptionsSchema.properties,
|
|
52
80
|
},
|
|
53
81
|
required: [],
|
|
54
82
|
};
|
|
@@ -63,12 +91,6 @@ const libDef = {
|
|
|
63
91
|
default: paramMessage`Can't generate Python client code from this TypeSpec. Please open an issue on https://github.com/microsoft/typespec'.${"stack"}`,
|
|
64
92
|
},
|
|
65
93
|
},
|
|
66
|
-
"invalid-models-mode": {
|
|
67
|
-
severity: "error",
|
|
68
|
-
messages: {
|
|
69
|
-
default: paramMessage`Invalid value '${"inValidValue"}' for 'models-mode' of tspconfig.yaml and expected values are 'dpg'/'none'.`,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
94
|
"pyodide-flag-conflict": {
|
|
73
95
|
severity: "error",
|
|
74
96
|
messages: {
|
|
@@ -77,6 +99,12 @@ const libDef = {
|
|
|
77
99
|
},
|
|
78
100
|
},
|
|
79
101
|
// warning
|
|
102
|
+
"no-package-name": {
|
|
103
|
+
severity: "warning",
|
|
104
|
+
messages: {
|
|
105
|
+
default: paramMessage`No package-name configured in tspconfig.yaml and will infer package-name '${"packageName"}' from namespace '${"namespace"}'.`,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
80
108
|
"no-valid-client": {
|
|
81
109
|
severity: "warning",
|
|
82
110
|
messages: {
|
|
@@ -109,9 +137,9 @@ const libDef = {
|
|
|
109
137
|
},
|
|
110
138
|
},
|
|
111
139
|
emitter: {
|
|
112
|
-
options:
|
|
140
|
+
options: PythonEmitterOptionsSchema,
|
|
113
141
|
},
|
|
114
142
|
} as const;
|
|
115
143
|
|
|
116
144
|
export const $lib = createTypeSpecLibrary(libDef);
|
|
117
|
-
export const { reportDiagnostic,
|
|
145
|
+
export const { reportDiagnostic, createDiagnostic } = $lib;
|
package/emitter/src/types.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
SdkEnumType,
|
|
12
12
|
SdkEnumValueType,
|
|
13
13
|
SdkModelType,
|
|
14
|
-
SdkServiceOperation,
|
|
15
14
|
SdkType,
|
|
16
15
|
SdkUnionType,
|
|
17
16
|
UsageFlags,
|
|
@@ -70,8 +69,8 @@ export function getSimpleTypeResult(result: Record<string, any>): Record<string,
|
|
|
70
69
|
return result;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
export function getType
|
|
74
|
-
context: PythonSdkContext
|
|
72
|
+
export function getType(
|
|
73
|
+
context: PythonSdkContext,
|
|
75
74
|
type: CredentialType | CredentialTypeUnion | Type | SdkType | MultiPartFileType,
|
|
76
75
|
): Record<string, any> {
|
|
77
76
|
switch (type.kind) {
|
|
@@ -128,8 +127,8 @@ export function getType<TServiceOperation extends SdkServiceOperation>(
|
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
function emitMultiPartFile
|
|
132
|
-
context: PythonSdkContext
|
|
130
|
+
function emitMultiPartFile(
|
|
131
|
+
context: PythonSdkContext,
|
|
133
132
|
type: MultiPartFileType,
|
|
134
133
|
): Record<string, any> {
|
|
135
134
|
if (type.type.kind === "array") {
|
|
@@ -218,12 +217,12 @@ function addDisableGenerationMap(type: SdkType): void {
|
|
|
218
217
|
}
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
function emitProperty
|
|
222
|
-
context: PythonSdkContext
|
|
220
|
+
function emitProperty(
|
|
221
|
+
context: PythonSdkContext,
|
|
223
222
|
model: SdkModelType,
|
|
224
223
|
property: SdkBodyModelPropertyType,
|
|
225
224
|
): Record<string, any> {
|
|
226
|
-
const isMultipartFileInput = property.
|
|
225
|
+
const isMultipartFileInput = property.serializationOptions?.multipart?.isFilePart;
|
|
227
226
|
let sourceType: SdkType | MultiPartFileType = property.type;
|
|
228
227
|
if (isMultipartFileInput) {
|
|
229
228
|
sourceType = createMultiPartFileType(property.type);
|
|
@@ -254,10 +253,7 @@ function emitProperty<TServiceOperation extends SdkServiceOperation>(
|
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
function emitModel<
|
|
258
|
-
context: PythonSdkContext<TServiceOperation>,
|
|
259
|
-
type: SdkModelType,
|
|
260
|
-
): Record<string, any> {
|
|
256
|
+
function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string, any> {
|
|
261
257
|
if (isEmptyModel(type)) {
|
|
262
258
|
return KnownTypes.any;
|
|
263
259
|
}
|
|
@@ -320,10 +316,7 @@ function emitModel<TServiceOperation extends SdkServiceOperation>(
|
|
|
320
316
|
return newValue;
|
|
321
317
|
}
|
|
322
318
|
|
|
323
|
-
function emitEnum<
|
|
324
|
-
context: PythonSdkContext<TServiceOperation>,
|
|
325
|
-
type: SdkEnumType,
|
|
326
|
-
): Record<string, any> {
|
|
319
|
+
function emitEnum(context: PythonSdkContext, type: SdkEnumType): Record<string, any> {
|
|
327
320
|
if (typesMap.has(type)) {
|
|
328
321
|
return typesMap.get(type)!;
|
|
329
322
|
}
|
|
@@ -401,8 +394,8 @@ function emitDurationOrDateType(type: SdkDurationType | SdkDateTimeType): Record
|
|
|
401
394
|
});
|
|
402
395
|
}
|
|
403
396
|
|
|
404
|
-
function emitArrayOrDict
|
|
405
|
-
context: PythonSdkContext
|
|
397
|
+
function emitArrayOrDict(
|
|
398
|
+
context: PythonSdkContext,
|
|
406
399
|
type: SdkArrayType | SdkDictionaryType,
|
|
407
400
|
): Record<string, any> {
|
|
408
401
|
const kind = type.kind === "array" ? "list" : type.kind;
|
|
@@ -470,10 +463,7 @@ function emitBuiltInType(
|
|
|
470
463
|
});
|
|
471
464
|
}
|
|
472
465
|
|
|
473
|
-
function emitUnion<
|
|
474
|
-
context: PythonSdkContext<TServiceOperation>,
|
|
475
|
-
type: SdkUnionType,
|
|
476
|
-
): Record<string, any> {
|
|
466
|
+
function emitUnion(context: PythonSdkContext, type: SdkUnionType): Record<string, any> {
|
|
477
467
|
return getSimpleTypeResult({
|
|
478
468
|
name: type.isGeneratedName ? undefined : type.name,
|
|
479
469
|
snakeCaseName: type.isGeneratedName ? undefined : camelToSnakeCase(type.name),
|
|
@@ -508,8 +498,8 @@ export const KnownTypes = {
|
|
|
508
498
|
any: { type: "any" },
|
|
509
499
|
};
|
|
510
500
|
|
|
511
|
-
export function emitEndpointType
|
|
512
|
-
context: PythonSdkContext
|
|
501
|
+
export function emitEndpointType(
|
|
502
|
+
context: PythonSdkContext,
|
|
513
503
|
type: SdkEndpointType,
|
|
514
504
|
): Record<string, any>[] {
|
|
515
505
|
const params: Record<string, any>[] = [];
|
|
@@ -523,7 +513,7 @@ export function emitEndpointType<TServiceOperation extends SdkServiceOperation>(
|
|
|
523
513
|
location: "endpointPath",
|
|
524
514
|
implementation: getImplementation(context, param),
|
|
525
515
|
clientDefaultValue: param.clientDefaultValue,
|
|
526
|
-
skipUrlEncoding: param.
|
|
516
|
+
skipUrlEncoding: param.allowReserved === false,
|
|
527
517
|
});
|
|
528
518
|
context.__endpointPathParameters!.push(params.at(-1)!);
|
|
529
519
|
}
|