Skip to content

Commit 76165b0

Browse files
authored
[tcgc] add overload for list of models (#3216)
* Update dependencies * Update dependencies (2025-09-23 03:39:58) * Regenerate for typespec-python (2025-09-23 03:44:53) * add test case * add changelog --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent f6ec7e3 commit 76165b0

14 files changed

Lines changed: 314 additions & 57 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Add overload for operation when body type is array of model

packages/autorest.python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTM2NTY3Ni9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.17.0.tgz",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTM3MDU0Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.17.0.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"

packages/typespec-python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"js-yaml": "~4.1.0",
6868
"semver": "~7.6.2",
6969
"tsx": "~4.19.1",
70-
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTM2NTY3Ni9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.17.0.tgz",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTM3MDU0Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.17.0.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {

packages/typespec-python/test/azure/generated/typetest-array/typetest/array/aio/operations/_operations.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
T = TypeVar("T")
6767
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
68+
JSON = MutableMapping[str, Any]
6869

6970

7071
class Int32ValueOperations:
@@ -1424,6 +1425,20 @@ async def put(
14241425
:raises ~azure.core.exceptions.HttpResponseError:
14251426
"""
14261427

1428+
@overload
1429+
async def put(self, body: list[JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1430+
"""put.
1431+
1432+
:param body: Required.
1433+
:type body: list[JSON]
1434+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1435+
Default value is "application/json".
1436+
:paramtype content_type: str
1437+
:return: None
1438+
:rtype: None
1439+
:raises ~azure.core.exceptions.HttpResponseError:
1440+
"""
1441+
14271442
@overload
14281443
async def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
14291444
"""put.
@@ -1439,11 +1454,11 @@ async def put(self, body: IO[bytes], *, content_type: str = "application/json",
14391454
"""
14401455

14411456
@distributed_trace_async
1442-
async def put(self, body: Union[list[_models.InnerModel], IO[bytes]], **kwargs: Any) -> None:
1457+
async def put(self, body: Union[list[_models.InnerModel], list[JSON], IO[bytes]], **kwargs: Any) -> None:
14431458
"""put.
14441459
1445-
:param body: Is either a [InnerModel] type or a IO[bytes] type. Required.
1446-
:type body: list[~typetest.array.models.InnerModel] or IO[bytes]
1460+
:param body: Is one of the following types: [InnerModel], [JSON], IO[bytes] Required.
1461+
:type body: list[~typetest.array.models.InnerModel] or list[JSON] or IO[bytes]
14471462
:return: None
14481463
:rtype: None
14491464
:raises ~azure.core.exceptions.HttpResponseError:
@@ -2216,6 +2231,20 @@ async def put(
22162231
:raises ~azure.core.exceptions.HttpResponseError:
22172232
"""
22182233

2234+
@overload
2235+
async def put(self, body: list[JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
2236+
"""put.
2237+
2238+
:param body: Required.
2239+
:type body: list[JSON]
2240+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
2241+
Default value is "application/json".
2242+
:paramtype content_type: str
2243+
:return: None
2244+
:rtype: None
2245+
:raises ~azure.core.exceptions.HttpResponseError:
2246+
"""
2247+
22192248
@overload
22202249
async def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
22212250
"""put.
@@ -2231,11 +2260,11 @@ async def put(self, body: IO[bytes], *, content_type: str = "application/json",
22312260
"""
22322261

22332262
@distributed_trace_async
2234-
async def put(self, body: Union[list[_models.InnerModel], IO[bytes]], **kwargs: Any) -> None:
2263+
async def put(self, body: Union[list[_models.InnerModel], list[JSON], IO[bytes]], **kwargs: Any) -> None:
22352264
"""put.
22362265
2237-
:param body: Is either a [InnerModel] type or a IO[bytes] type. Required.
2238-
:type body: list[~typetest.array.models.InnerModel] or IO[bytes]
2266+
:param body: Is one of the following types: [InnerModel], [JSON], IO[bytes] Required.
2267+
:type body: list[~typetest.array.models.InnerModel] or list[JSON] or IO[bytes]
22392268
:return: None
22402269
:rtype: None
22412270
:raises ~azure.core.exceptions.HttpResponseError:

packages/typespec-python/test/azure/generated/typetest-array/typetest/array/operations/_operations.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
T = TypeVar("T")
3737
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]]
38+
JSON = MutableMapping[str, Any]
3839

3940
_SERIALIZER = Serializer()
4041
_SERIALIZER.client_side_validation = False
@@ -1799,6 +1800,20 @@ def put(self, body: list[_models.InnerModel], *, content_type: str = "applicatio
17991800
:raises ~azure.core.exceptions.HttpResponseError:
18001801
"""
18011802

1803+
@overload
1804+
def put(self, body: list[JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1805+
"""put.
1806+
1807+
:param body: Required.
1808+
:type body: list[JSON]
1809+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1810+
Default value is "application/json".
1811+
:paramtype content_type: str
1812+
:return: None
1813+
:rtype: None
1814+
:raises ~azure.core.exceptions.HttpResponseError:
1815+
"""
1816+
18021817
@overload
18031818
def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
18041819
"""put.
@@ -1815,12 +1830,12 @@ def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwar
18151830

18161831
@distributed_trace
18171832
def put( # pylint: disable=inconsistent-return-statements
1818-
self, body: Union[list[_models.InnerModel], IO[bytes]], **kwargs: Any
1833+
self, body: Union[list[_models.InnerModel], list[JSON], IO[bytes]], **kwargs: Any
18191834
) -> None:
18201835
"""put.
18211836
1822-
:param body: Is either a [InnerModel] type or a IO[bytes] type. Required.
1823-
:type body: list[~typetest.array.models.InnerModel] or IO[bytes]
1837+
:param body: Is one of the following types: [InnerModel], [JSON], IO[bytes] Required.
1838+
:type body: list[~typetest.array.models.InnerModel] or list[JSON] or IO[bytes]
18241839
:return: None
18251840
:rtype: None
18261841
:raises ~azure.core.exceptions.HttpResponseError:
@@ -2599,6 +2614,20 @@ def put(self, body: list[_models.InnerModel], *, content_type: str = "applicatio
25992614
:raises ~azure.core.exceptions.HttpResponseError:
26002615
"""
26012616

2617+
@overload
2618+
def put(self, body: list[JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
2619+
"""put.
2620+
2621+
:param body: Required.
2622+
:type body: list[JSON]
2623+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
2624+
Default value is "application/json".
2625+
:paramtype content_type: str
2626+
:return: None
2627+
:rtype: None
2628+
:raises ~azure.core.exceptions.HttpResponseError:
2629+
"""
2630+
26022631
@overload
26032632
def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
26042633
"""put.
@@ -2615,12 +2644,12 @@ def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwar
26152644

26162645
@distributed_trace
26172646
def put( # pylint: disable=inconsistent-return-statements
2618-
self, body: Union[list[_models.InnerModel], IO[bytes]], **kwargs: Any
2647+
self, body: Union[list[_models.InnerModel], list[JSON], IO[bytes]], **kwargs: Any
26192648
) -> None:
26202649
"""put.
26212650
2622-
:param body: Is either a [InnerModel] type or a IO[bytes] type. Required.
2623-
:type body: list[~typetest.array.models.InnerModel] or IO[bytes]
2651+
:param body: Is one of the following types: [InnerModel], [JSON], IO[bytes] Required.
2652+
:type body: list[~typetest.array.models.InnerModel] or list[JSON] or IO[bytes]
26242653
:return: None
26252654
:rtype: None
26262655
:raises ~azure.core.exceptions.HttpResponseError:

packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/aio/operations/_operations.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
T = TypeVar("T")
6161
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
62+
JSON = MutableMapping[str, Any]
6263

6364

6465
class Int32ValueOperations:
@@ -1418,6 +1419,20 @@ async def put(
14181419
:raises ~azure.core.exceptions.HttpResponseError:
14191420
"""
14201421

1422+
@overload
1423+
async def put(self, body: dict[str, JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1424+
"""put.
1425+
1426+
:param body: Required.
1427+
:type body: dict[str, JSON]
1428+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1429+
Default value is "application/json".
1430+
:paramtype content_type: str
1431+
:return: None
1432+
:rtype: None
1433+
:raises ~azure.core.exceptions.HttpResponseError:
1434+
"""
1435+
14211436
@overload
14221437
async def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
14231438
"""put.
@@ -1433,11 +1448,11 @@ async def put(self, body: IO[bytes], *, content_type: str = "application/json",
14331448
"""
14341449

14351450
@distributed_trace_async
1436-
async def put(self, body: Union[dict[str, _models.InnerModel], IO[bytes]], **kwargs: Any) -> None:
1451+
async def put(self, body: Union[dict[str, _models.InnerModel], dict[str, JSON], IO[bytes]], **kwargs: Any) -> None:
14371452
"""put.
14381453
1439-
:param body: Is either a {str: InnerModel} type or a IO[bytes] type. Required.
1440-
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or IO[bytes]
1454+
:param body: Is one of the following types: {str: InnerModel}, {str: JSON}, IO[bytes] Required.
1455+
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or dict[str, JSON] or IO[bytes]
14411456
:return: None
14421457
:rtype: None
14431458
:raises ~azure.core.exceptions.HttpResponseError:
@@ -1578,6 +1593,20 @@ async def put(
15781593
:raises ~azure.core.exceptions.HttpResponseError:
15791594
"""
15801595

1596+
@overload
1597+
async def put(self, body: dict[str, JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1598+
"""put.
1599+
1600+
:param body: Required.
1601+
:type body: dict[str, JSON]
1602+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1603+
Default value is "application/json".
1604+
:paramtype content_type: str
1605+
:return: None
1606+
:rtype: None
1607+
:raises ~azure.core.exceptions.HttpResponseError:
1608+
"""
1609+
15811610
@overload
15821611
async def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
15831612
"""put.
@@ -1593,11 +1622,11 @@ async def put(self, body: IO[bytes], *, content_type: str = "application/json",
15931622
"""
15941623

15951624
@distributed_trace_async
1596-
async def put(self, body: Union[dict[str, _models.InnerModel], IO[bytes]], **kwargs: Any) -> None:
1625+
async def put(self, body: Union[dict[str, _models.InnerModel], dict[str, JSON], IO[bytes]], **kwargs: Any) -> None:
15971626
"""put.
15981627
1599-
:param body: Is either a {str: InnerModel} type or a IO[bytes] type. Required.
1600-
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or IO[bytes]
1628+
:param body: Is one of the following types: {str: InnerModel}, {str: JSON}, IO[bytes] Required.
1629+
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or dict[str, JSON] or IO[bytes]
16011630
:return: None
16021631
:rtype: None
16031632
:raises ~azure.core.exceptions.HttpResponseError:

packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/operations/_operations.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
T = TypeVar("T")
3737
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]]
38+
JSON = MutableMapping[str, Any]
3839

3940
_SERIALIZER = Serializer()
4041
_SERIALIZER.client_side_validation = False
@@ -1719,6 +1720,20 @@ def put(
17191720
:raises ~azure.core.exceptions.HttpResponseError:
17201721
"""
17211722

1723+
@overload
1724+
def put(self, body: dict[str, JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1725+
"""put.
1726+
1727+
:param body: Required.
1728+
:type body: dict[str, JSON]
1729+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1730+
Default value is "application/json".
1731+
:paramtype content_type: str
1732+
:return: None
1733+
:rtype: None
1734+
:raises ~azure.core.exceptions.HttpResponseError:
1735+
"""
1736+
17221737
@overload
17231738
def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
17241739
"""put.
@@ -1735,12 +1750,12 @@ def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwar
17351750

17361751
@distributed_trace
17371752
def put( # pylint: disable=inconsistent-return-statements
1738-
self, body: Union[dict[str, _models.InnerModel], IO[bytes]], **kwargs: Any
1753+
self, body: Union[dict[str, _models.InnerModel], dict[str, JSON], IO[bytes]], **kwargs: Any
17391754
) -> None:
17401755
"""put.
17411756
1742-
:param body: Is either a {str: InnerModel} type or a IO[bytes] type. Required.
1743-
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or IO[bytes]
1757+
:param body: Is one of the following types: {str: InnerModel}, {str: JSON}, IO[bytes] Required.
1758+
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or dict[str, JSON] or IO[bytes]
17441759
:return: None
17451760
:rtype: None
17461761
:raises ~azure.core.exceptions.HttpResponseError:
@@ -1881,6 +1896,20 @@ def put(
18811896
:raises ~azure.core.exceptions.HttpResponseError:
18821897
"""
18831898

1899+
@overload
1900+
def put(self, body: dict[str, JSON], *, content_type: str = "application/json", **kwargs: Any) -> None:
1901+
"""put.
1902+
1903+
:param body: Required.
1904+
:type body: dict[str, JSON]
1905+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1906+
Default value is "application/json".
1907+
:paramtype content_type: str
1908+
:return: None
1909+
:rtype: None
1910+
:raises ~azure.core.exceptions.HttpResponseError:
1911+
"""
1912+
18841913
@overload
18851914
def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
18861915
"""put.
@@ -1897,12 +1926,12 @@ def put(self, body: IO[bytes], *, content_type: str = "application/json", **kwar
18971926

18981927
@distributed_trace
18991928
def put( # pylint: disable=inconsistent-return-statements
1900-
self, body: Union[dict[str, _models.InnerModel], IO[bytes]], **kwargs: Any
1929+
self, body: Union[dict[str, _models.InnerModel], dict[str, JSON], IO[bytes]], **kwargs: Any
19011930
) -> None:
19021931
"""put.
19031932
1904-
:param body: Is either a {str: InnerModel} type or a IO[bytes] type. Required.
1905-
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or IO[bytes]
1933+
:param body: Is one of the following types: {str: InnerModel}, {str: JSON}, IO[bytes] Required.
1934+
:type body: dict[str, ~typetest.dictionary.models.InnerModel] or dict[str, JSON] or IO[bytes]
19061935
:return: None
19071936
:rtype: None
19081937
:raises ~azure.core.exceptions.HttpResponseError:

packages/typespec-python/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,22 @@ async def test_model_value(client: ArrayClient):
5858
models.InnerModel(property="hello"),
5959
models.InnerModel(property="world"),
6060
]
61+
# test list[model]
6162
await client.model_value.put(
6263
[
6364
models.InnerModel(property="hello"),
6465
models.InnerModel(property="world"),
6566
]
6667
)
6768

69+
# test list[JSON]
70+
await client.model_value.put(
71+
[
72+
{"property": "hello"},
73+
{"property": "world"},
74+
]
75+
)
76+
6877

6978
@pytest.mark.asyncio
7079
async def test_nullable_boolean_value(client: ArrayClient):

packages/typespec-python/test/generic_mock_api_tests/test_typetest_array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,20 @@ def test_model_value(client: ArrayClient):
5050
models.InnerModel(property="hello"),
5151
models.InnerModel(property="world"),
5252
]
53+
# test list[model]
5354
client.model_value.put(
5455
[
5556
models.InnerModel(property="hello"),
5657
models.InnerModel(property="world"),
5758
]
5859
)
60+
# test list[JSON]
61+
client.model_value.put(
62+
[
63+
{"property": "hello"},
64+
{"property": "world"},
65+
]
66+
)
5967

6068

6169
def test_nullable_boolean_value(client: ArrayClient):

0 commit comments

Comments
 (0)