@typespec/http-client-python 0.7.1 → 0.8.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/dist/emitter/code-model.js +6 -6
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +57 -54
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/external-process.js +3 -3
- package/dist/emitter/external-process.js.map +1 -1
- package/dist/emitter/http.d.ts.map +1 -1
- package/dist/emitter/http.js +81 -23
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/lib.d.ts +37 -1
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +24 -0
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/types.js +3 -3
- package/dist/emitter/types.js.map +1 -1
- package/dist/emitter/utils.d.ts +4 -2
- package/dist/emitter/utils.d.ts.map +1 -1
- package/dist/emitter/utils.js +21 -2
- package/dist/emitter/utils.js.map +1 -1
- package/emitter/src/code-model.ts +8 -8
- package/emitter/src/emitter.ts +57 -53
- package/emitter/src/external-process.ts +3 -3
- package/emitter/src/http.ts +113 -26
- package/emitter/src/lib.ts +24 -0
- package/emitter/src/types.ts +3 -3
- package/emitter/src/utils.ts +36 -1
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/eng/scripts/setup/run_tsp.py +2 -2
- package/generator/build/lib/pygen/__init__.py +3 -3
- package/generator/build/lib/pygen/black.py +2 -2
- package/generator/build/lib/pygen/codegen/__init__.py +5 -5
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +11 -2
- package/generator/build/lib/pygen/codegen/models/parameter.py +2 -1
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +2 -0
- package/generator/build/lib/pygen/codegen/models/response.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +47 -25
- package/generator/build/lib/pygen/preprocess/__init__.py +10 -12
- package/generator/build/lib/pygen/preprocess/python_mappings.py +1 -1
- package/generator/build/lib/pygen/utils.py +5 -5
- package/generator/component-detection-pip-report.json +7 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +3 -3
- package/generator/pygen/black.py +2 -2
- package/generator/pygen/codegen/__init__.py +5 -5
- package/generator/pygen/codegen/models/paging_operation.py +11 -2
- package/generator/pygen/codegen/models/parameter.py +2 -1
- package/generator/pygen/codegen/models/request_builder_parameter.py +2 -0
- package/generator/pygen/codegen/models/response.py +1 -1
- package/generator/pygen/codegen/serializers/builder_serializer.py +47 -25
- package/generator/pygen/preprocess/__init__.py +10 -12
- package/generator/pygen/preprocess/python_mappings.py +1 -1
- package/generator/pygen/utils.py +5 -5
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py +75 -0
- package/generator/test/generic_mock_api_tests/test_payload_pageable.py +54 -0
- package/package.json +1 -1
- package/generator/test/unbranded/mock_api_tests/cadl-ranch-config.yaml +0 -27
|
@@ -14,7 +14,7 @@ from .helpers import (
|
|
|
14
14
|
pad_builtin_namespaces,
|
|
15
15
|
pad_special_chars,
|
|
16
16
|
)
|
|
17
|
-
from .python_mappings import
|
|
17
|
+
from .python_mappings import TSP_RESERVED_WORDS, RESERVED_WORDS, PadType
|
|
18
18
|
|
|
19
19
|
from .. import YamlUpdatePlugin
|
|
20
20
|
from ..utils import (
|
|
@@ -182,11 +182,11 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
182
182
|
|
|
183
183
|
@property
|
|
184
184
|
def models_mode(self) -> Optional[str]:
|
|
185
|
-
return self.options.get("models-mode", "dpg" if self.
|
|
185
|
+
return self.options.get("models-mode", "dpg" if self.is_tsp else None)
|
|
186
186
|
|
|
187
187
|
@property
|
|
188
|
-
def
|
|
189
|
-
return self.options.get("
|
|
188
|
+
def is_tsp(self) -> bool:
|
|
189
|
+
return self.options.get("tsp_file", False)
|
|
190
190
|
|
|
191
191
|
def add_body_param_type(
|
|
192
192
|
self,
|
|
@@ -197,9 +197,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
197
197
|
if ( # pylint: disable=too-many-boolean-expressions
|
|
198
198
|
body_parameter
|
|
199
199
|
and body_parameter["type"]["type"] in ("model", "dict", "list")
|
|
200
|
-
and (
|
|
201
|
-
has_json_content_type(body_parameter) or (self.is_cadl and has_multi_part_content_type(body_parameter))
|
|
202
|
-
)
|
|
200
|
+
and (has_json_content_type(body_parameter) or (self.is_tsp and has_multi_part_content_type(body_parameter)))
|
|
203
201
|
and not body_parameter["type"].get("xmlMetadata")
|
|
204
202
|
and not any(t for t in ["flattened", "groupedBy"] if body_parameter.get(t))
|
|
205
203
|
):
|
|
@@ -210,7 +208,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
210
208
|
"types": [body_parameter["type"]],
|
|
211
209
|
}
|
|
212
210
|
# don't add binary overload for multipart content type
|
|
213
|
-
if not (self.
|
|
211
|
+
if not (self.is_tsp and has_multi_part_content_type(body_parameter)):
|
|
214
212
|
body_parameter["type"]["types"].append(KNOWN_TYPES["binary"])
|
|
215
213
|
|
|
216
214
|
if origin_type == "model" and is_dpg_model and self.models_mode == "dpg":
|
|
@@ -223,8 +221,8 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
223
221
|
# we'll pass in empty operation groups sometime etc.
|
|
224
222
|
return name
|
|
225
223
|
|
|
226
|
-
if self.
|
|
227
|
-
reserved_words = {k: (v +
|
|
224
|
+
if self.is_tsp:
|
|
225
|
+
reserved_words = {k: (v + TSP_RESERVED_WORDS.get(k, [])) for k, v in RESERVED_WORDS.items()}
|
|
228
226
|
else:
|
|
229
227
|
reserved_words = RESERVED_WORDS
|
|
230
228
|
name = pad_special_chars(name)
|
|
@@ -506,6 +504,6 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
506
504
|
|
|
507
505
|
|
|
508
506
|
if __name__ == "__main__":
|
|
509
|
-
#
|
|
507
|
+
# TSP pipeline will call this
|
|
510
508
|
args, unknown_args = parse_args()
|
|
511
|
-
PreProcessPlugin(output_folder=args.output_folder,
|
|
509
|
+
PreProcessPlugin(output_folder=args.output_folder, tsp_file=args.tsp_file, **unknown_args).process()
|
package/generator/pygen/utils.py
CHANGED
|
@@ -44,7 +44,7 @@ def to_snake_case(name: str) -> str:
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def parse_args(
|
|
47
|
-
|
|
47
|
+
need_tsp_file: bool = True,
|
|
48
48
|
) -> Tuple[argparse.Namespace, Dict[str, Any]]:
|
|
49
49
|
parser = argparse.ArgumentParser(
|
|
50
50
|
description="Run mypy against target folder. Add a local custom plugin to the path prior to execution. "
|
|
@@ -56,10 +56,10 @@ def parse_args(
|
|
|
56
56
|
required=True,
|
|
57
57
|
)
|
|
58
58
|
parser.add_argument(
|
|
59
|
-
"--
|
|
60
|
-
dest="
|
|
61
|
-
help="Serialized
|
|
62
|
-
required=
|
|
59
|
+
"--tsp-file",
|
|
60
|
+
dest="tsp_file",
|
|
61
|
+
help="Serialized tsp file",
|
|
62
|
+
required=need_tsp_file,
|
|
63
63
|
)
|
|
64
64
|
parser.add_argument(
|
|
65
65
|
"--debug",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import pytest
|
|
7
|
+
from payload.pageable.aio import PageableClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture
|
|
11
|
+
async def client():
|
|
12
|
+
async with PageableClient(endpoint="http://localhost:3000") as client:
|
|
13
|
+
yield client
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def assert_result(result):
|
|
17
|
+
assert len(result) == 4
|
|
18
|
+
assert result[0].id == "1"
|
|
19
|
+
assert result[1].id == "2"
|
|
20
|
+
assert result[2].id == "3"
|
|
21
|
+
assert result[3].id == "4"
|
|
22
|
+
assert result[0].name == "dog"
|
|
23
|
+
assert result[1].name == "cat"
|
|
24
|
+
assert result[2].name == "bird"
|
|
25
|
+
assert result[3].name == "fish"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.asyncio
|
|
29
|
+
async def test_link(client: PageableClient):
|
|
30
|
+
result = [p async for p in client.server_driven_pagination.link()]
|
|
31
|
+
assert_result(result)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.mark.asyncio
|
|
35
|
+
async def test_request_query_response_body(client: PageableClient):
|
|
36
|
+
result = [
|
|
37
|
+
p
|
|
38
|
+
async for p in client.server_driven_pagination.continuation_token.request_query_response_body(
|
|
39
|
+
foo="foo", bar="bar"
|
|
40
|
+
)
|
|
41
|
+
]
|
|
42
|
+
assert_result(result)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@pytest.mark.asyncio
|
|
46
|
+
async def test_request_header_response_body(client: PageableClient):
|
|
47
|
+
result = [
|
|
48
|
+
p
|
|
49
|
+
async for p in client.server_driven_pagination.continuation_token.request_header_response_body(
|
|
50
|
+
foo="foo", bar="bar"
|
|
51
|
+
)
|
|
52
|
+
]
|
|
53
|
+
assert_result(result)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@pytest.mark.asyncio
|
|
57
|
+
async def test_request_query_response_header(client: PageableClient):
|
|
58
|
+
result = [
|
|
59
|
+
p
|
|
60
|
+
async for p in client.server_driven_pagination.continuation_token.request_query_response_header(
|
|
61
|
+
foo="foo", bar="bar"
|
|
62
|
+
)
|
|
63
|
+
]
|
|
64
|
+
assert_result(result)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.asyncio
|
|
68
|
+
async def test_request_header_response_header(client: PageableClient):
|
|
69
|
+
result = [
|
|
70
|
+
p
|
|
71
|
+
async for p in client.server_driven_pagination.continuation_token.request_query_response_header(
|
|
72
|
+
foo="foo", bar="bar"
|
|
73
|
+
)
|
|
74
|
+
]
|
|
75
|
+
assert_result(result)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import pytest
|
|
7
|
+
from payload.pageable import PageableClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture
|
|
11
|
+
def client():
|
|
12
|
+
with PageableClient(endpoint="http://localhost:3000") as client:
|
|
13
|
+
yield client
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def assert_result(result):
|
|
17
|
+
assert len(result) == 4
|
|
18
|
+
assert result[0].id == "1"
|
|
19
|
+
assert result[1].id == "2"
|
|
20
|
+
assert result[2].id == "3"
|
|
21
|
+
assert result[3].id == "4"
|
|
22
|
+
assert result[0].name == "dog"
|
|
23
|
+
assert result[1].name == "cat"
|
|
24
|
+
assert result[2].name == "bird"
|
|
25
|
+
assert result[3].name == "fish"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_link(client: PageableClient):
|
|
29
|
+
result = list(client.server_driven_pagination.link())
|
|
30
|
+
assert_result(result)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_request_query_response_body(client: PageableClient):
|
|
34
|
+
result = list(client.server_driven_pagination.continuation_token.request_query_response_body(foo="foo", bar="bar"))
|
|
35
|
+
assert_result(result)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_request_header_response_body(client: PageableClient):
|
|
39
|
+
result = list(client.server_driven_pagination.continuation_token.request_header_response_body(foo="foo", bar="bar"))
|
|
40
|
+
assert_result(result)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_request_query_response_header(client: PageableClient):
|
|
44
|
+
result = list(
|
|
45
|
+
client.server_driven_pagination.continuation_token.request_query_response_header(foo="foo", bar="bar")
|
|
46
|
+
)
|
|
47
|
+
assert_result(result)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_request_header_response_header(client: PageableClient):
|
|
51
|
+
result = list(
|
|
52
|
+
client.server_driven_pagination.continuation_token.request_header_response_header(foo="foo", bar="bar")
|
|
53
|
+
)
|
|
54
|
+
assert_result(result)
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
unsupportedScenarios: Azure_ClientGenerator_Core_Access_InternalOperation
|
|
2
|
-
Azure_ClientGenerator_Core_Access_PublicOperation
|
|
3
|
-
Azure_ClientGenerator_Core_Access_RelativeModelInOperation
|
|
4
|
-
Azure_ClientGenerator_Core_Access_SharedModelInOperation
|
|
5
|
-
Azure_ClientGenerator_Core_Usage_ModelInOperation
|
|
6
|
-
Azure_Core_Basic_createOrReplace
|
|
7
|
-
Azure_Core_Basic_createOrUpdate
|
|
8
|
-
Azure_Core_Basic_delete
|
|
9
|
-
Azure_Core_Basic_export
|
|
10
|
-
Azure_Core_Basic_get
|
|
11
|
-
Azure_Core_Basic_list
|
|
12
|
-
Azure_Core_Basic_listWithCustomPageModel
|
|
13
|
-
Azure_Core_Basic_listWithPage
|
|
14
|
-
Azure_Core_Basic_listWithParameters
|
|
15
|
-
Azure_Core_Basic_TwoModelsAsPageItem
|
|
16
|
-
Azure_Core_Lro_Rpc_longRunningRpc
|
|
17
|
-
Azure_Core_Lro_Standard_createOrReplace
|
|
18
|
-
Azure_Core_Lro_Standard_delete
|
|
19
|
-
Azure_Core_Lro_Standard_export
|
|
20
|
-
Azure_Core_Scalar_AzureLocationScalar_get
|
|
21
|
-
Azure_Core_Scalar_AzureLocationScalar_header
|
|
22
|
-
Azure_Core_Scalar_AzureLocationScalar_post
|
|
23
|
-
Azure_Core_Scalar_AzureLocationScalar_put
|
|
24
|
-
Azure_Core_Scalar_AzureLocationScalar_query
|
|
25
|
-
Azure_Core_Traits_repeatableAction
|
|
26
|
-
Azure_Core_Traits_smokeTest
|
|
27
|
-
Azure_SpecialHeaders_XmsClientRequestId
|