Skip to content

Commit cf46ab8

Browse files
authored
[python] Support customized http method to call next link for paging operation (#3268)
* add test case * Update dependencies * Add changelog .chronus/changes/auto-microsoft-python-post-paging-2025-10-28-7-34-49.md * Update dependencies (2025-11-28 09:18:14) * Regenerate for typespec-python (2025-11-28 09:23:25) --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent 1feff61 commit cf46ab8

File tree

9 files changed

+75
-11
lines changed

9 files changed

+75
-11
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: feature
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Support customized http method to call next link for paging operation

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/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYxODM5OC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.tgz",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYxODk4MC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.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/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYxODM5OC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.tgz",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTYxODk4MC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {

packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def prepare_request(next_link=None):
9191
_request.url = self._client.format_url(_request.url, **path_format_arguments)
9292

9393
else:
94-
_request = HttpRequest("GET", next_link)
94+
_request = HttpRequest("POST", next_link)
9595
path_format_arguments = {
9696
"endpoint": self._serialize.url(
9797
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True

packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/aio/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def prepare_request(next_link=None):
7474
_request.url = self._client.format_url(_request.url, **path_format_arguments)
7575

7676
else:
77-
_request = HttpRequest("GET", next_link)
77+
_request = HttpRequest("POST", next_link)
7878
path_format_arguments = {
7979
"endpoint": self._serialize.url(
8080
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
8+
from specs.azure.clientgenerator.core.nextlinkverb.aio import NextLinkVerbClient
9+
10+
11+
@pytest.fixture
12+
async def client():
13+
async with NextLinkVerbClient(endpoint="http://localhost:3000") as client:
14+
yield client
15+
16+
17+
def assert_items(items):
18+
assert len(items) == 2
19+
assert items[0].id == "test1"
20+
assert items[1].id == "test2"
21+
22+
23+
@pytest.mark.asyncio
24+
async def test_list_items_next_link_verb(client: NextLinkVerbClient):
25+
# The operation uses POST for nextLink per @nextLinkVerb
26+
pager = client.list_items()
27+
items = [item async for item in pager]
28+
assert_items(items)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
8+
from specs.azure.clientgenerator.core.nextlinkverb import NextLinkVerbClient
9+
10+
11+
@pytest.fixture
12+
def client():
13+
with NextLinkVerbClient(endpoint="http://localhost:3000") as client:
14+
yield client
15+
16+
17+
def assert_items(items):
18+
items = list(items)
19+
assert len(items) == 2
20+
assert items[0].id == "test1"
21+
assert items[1].id == "test2"
22+
23+
24+
def test_list_items_next_link_verb(client: NextLinkVerbClient):
25+
# The operation uses POST for nextLink per @nextLinkVerb
26+
pager = client.list_items()
27+
assert_items(pager)

packages/typespec-python/test/azure/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ azure-mgmt-core==1.6.0
2222
-e ./generated/azure-core-model
2323
-e ./generated/azure-core-traits
2424
-e ./generated/azure-core-page
25+
-e ./generated/azure-client-generator-core-next-link-verb
2526
-e ./generated/azure-encode-duration
2627
-e ./generated/azure-special-headers-client-request-id/
2728
-e ./generated/azure-example-basic

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)