From a748347bf7c7e3e2e856ffea7b04b860242fb17b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 17 Jun 2022 13:20:01 -0700 Subject: [PATCH 01/11] reformat api-version into next link if its a client param --- autorest/codegen/models/client.py | 2 +- autorest/codegen/models/paging_operation.py | 13 +++++++++- .../codegen/serializers/builder_serializer.py | 24 ++++++++++++++++++- .../aio/operations/_operations.py | 11 +++++++-- .../operations/_operations.py | 11 +++++++-- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/autorest/codegen/models/client.py b/autorest/codegen/models/client.py index 9a127e52884..a25f9316bb1 100644 --- a/autorest/codegen/models/client.py +++ b/autorest/codegen/models/client.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union +from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union, Optional from .base_model import BaseModel from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList diff --git a/autorest/codegen/models/paging_operation.py b/autorest/codegen/models/paging_operation.py index e8f5fac0113..e44cd37b3fe 100644 --- a/autorest/codegen/models/paging_operation.py +++ b/autorest/codegen/models/paging_operation.py @@ -140,7 +140,18 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import.merge( self.get_request_builder_import(self.next_request_builder, async_mode) ) - + elif ( + "api-version" + in [p.rest_api_name for p in self.code_model.client.parameters] + and self.code_model.options["version_tolerant"] + ): + file_import.add_submodule_import( + "urllib.parse", "urlparse", ImportType.STDLIB + ) + file_import.add_submodule_import( + "urllib.parse", "parse_qs", ImportType.STDLIB + ) + file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) return file_import diff --git a/autorest/codegen/serializers/builder_serializer.py b/autorest/codegen/serializers/builder_serializer.py index 3f85a6432a4..9751e7849ab 100644 --- a/autorest/codegen/serializers/builder_serializer.py +++ b/autorest/codegen/serializers/builder_serializer.py @@ -1140,8 +1140,30 @@ def call_next_link_request_builder(self, builder: PagingOperationType) -> List[s template_url=template_url, is_next_request=True, ) - retval = ['request = HttpRequest("GET", next_link)'] + retval: List[str] = [] + query_str = "" + try: + api_version_param = next( + p + for p in self.code_model.client.parameters + if p.rest_api_name == "api-version" + ) + retval.append("_next_request_params: Dict[str, str] = {}") + retval.append( + 'if "api-version" not in parse_qs(urlparse(next_link).query).keys():' + ) + retval.append( + ' _next_request_params = {"api-version": ' + + api_version_param.full_client_name + + "}" + ) + query_str = ", params=_next_request_params" + except StopIteration: + pass + + retval.append(f'request = HttpRequest("GET", next_link{query_str})') retval.extend(self._postprocess_http_request(builder, "request.url")) + return retval def _prepare_request_callback(self, builder: PagingOperationType) -> List[str]: diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py index d73cec9be13..0aabaa4670c 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -1373,7 +1374,10 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + _next_request_params: Dict[str, str] = {} + if "api-version" not in parse_qs(urlparse(next_link).query).keys(): + _next_request_params = {"api-version": self._config.api_version} + request = HttpRequest("GET", next_link, params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1504,7 +1508,10 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + _next_request_params: Dict[str, str] = {} + if "api-version" not in parse_qs(urlparse(next_link).query).keys(): + _next_request_params = {"api-version": self._config.api_version} + request = HttpRequest("GET", next_link, params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py index 9b241fe14a4..2233715b487 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -1638,7 +1639,10 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + _next_request_params: Dict[str, str] = {} + if "api-version" not in parse_qs(urlparse(next_link).query).keys(): + _next_request_params = {"api-version": self._config.api_version} + request = HttpRequest("GET", next_link, params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1769,7 +1773,10 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + _next_request_params: Dict[str, str] = {} + if "api-version" not in parse_qs(urlparse(next_link).query).keys(): + _next_request_params = {"api-version": self._config.api_version} + request = HttpRequest("GET", next_link, params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request From a3c0d53cf9489315282ad0508d84cac7c22517a6 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 17 Jun 2022 13:35:48 -0700 Subject: [PATCH 02/11] update changelog --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 15d92184978..5ed83935100 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -15,7 +15,7 @@ - Default to generating DPG SDKs with `--version-tolerant` now defaulting to `true`. For a list of flag default changes, please see [here](https://github.com/Azure/autorest.python/issues/1186) #1304 - Only generate Python3 SDKs #1297 -- Don't reformat initial query parameters into the next link #1297 +- Don't reformat initial query parameters into the next link. However, we do append `api-version` parameters if they are not present in the next link #1297 #1309 - Don't generate operations with more than two body types. SDK authors need to implement this operation themselves #1300 **New Features** From 96c71a657d6678879cfabc17f45bfa44f80972a0 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 20 Jun 2022 12:32:44 -0700 Subject: [PATCH 03/11] replace api version in next link --- autorest/codegen/models/paging_operation.py | 11 +++++--- .../codegen/serializers/builder_serializer.py | 19 ++++++-------- .../_multiapi_service_client_operations.py | 19 ++++---------- .../_multiapi_service_client_operations.py | 18 +++---------- .../_multiapi_service_client_operations.py | 10 +++---- .../_multiapi_service_client_operations.py | 10 +++---- .../_storage_accounts_operations.py | 26 ++++++++----------- .../_storage_accounts_operations.py | 26 ++++++++----------- 8 files changed, 54 insertions(+), 85 deletions(-) diff --git a/autorest/codegen/models/paging_operation.py b/autorest/codegen/models/paging_operation.py index e44cd37b3fe..fe9ce412265 100644 --- a/autorest/codegen/models/paging_operation.py +++ b/autorest/codegen/models/paging_operation.py @@ -141,17 +141,20 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: self.get_request_builder_import(self.next_request_builder, async_mode) ) elif ( - "api-version" - in [p.rest_api_name for p in self.code_model.client.parameters] - and self.code_model.options["version_tolerant"] + "api-version" in [p.rest_api_name for p in self.code_model.client.parameters] ): file_import.add_submodule_import( "urllib.parse", "urlparse", ImportType.STDLIB ) + file_import.add_submodule_import( + "urllib.parse", "urljoin", ImportType.STDLIB + ) file_import.add_submodule_import( "urllib.parse", "parse_qs", ImportType.STDLIB ) - file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) + file_import.add_submodule_import( + "azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE + ) return file_import diff --git a/autorest/codegen/serializers/builder_serializer.py b/autorest/codegen/serializers/builder_serializer.py index 9751e7849ab..065f6c0b983 100644 --- a/autorest/codegen/serializers/builder_serializer.py +++ b/autorest/codegen/serializers/builder_serializer.py @@ -1133,7 +1133,7 @@ def call_next_link_request_builder(self, builder: PagingOperationType) -> List[s template_url = "next_link" request_builder = builder.next_request_builder or builder.request_builder - if builder.next_request_builder or self.code_model.is_legacy: + if builder.next_request_builder: return self._call_request_builder_helper( builder, request_builder, @@ -1142,26 +1142,23 @@ def call_next_link_request_builder(self, builder: PagingOperationType) -> List[s ) retval: List[str] = [] query_str = "" + next_link_str = "next_link" try: api_version_param = next( p for p in self.code_model.client.parameters if p.rest_api_name == "api-version" ) - retval.append("_next_request_params: Dict[str, str] = {}") - retval.append( - 'if "api-version" not in parse_qs(urlparse(next_link).query).keys():' - ) - retval.append( - ' _next_request_params = {"api-version": ' - + api_version_param.full_client_name - + "}" - ) + retval.append("# make call to next link with the client's api-version") + retval.append("_parsed_next_link = urlparse(next_link)") + retval.append("_next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query))") + retval.append(f'_next_request_params["api-version"] = {api_version_param.full_client_name}') query_str = ", params=_next_request_params" + next_link_str = "urljoin(next_link, _parsed_next_link.path)" except StopIteration: pass - retval.append(f'request = HttpRequest("GET", next_link{query_str})') + retval.append(f'request = HttpRequest("GET", {next_link_str}{query_str})') retval.extend(self._postprocess_http_request(builder, "request.url")) return retval diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py index 4fac2add56c..5f5a5fd355c 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -370,20 +371,10 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py index 2edb0f75d7f..d7d0e768b22 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -444,20 +445,9 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", next_link, params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py index 43791b41dcc..16a068f7434 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from urllib.parse import parse_qs, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -66,12 +67,9 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", next_link, params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py index a77052584d2..e73400733f5 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -108,12 +109,9 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", next_link, params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations/_storage_accounts_operations.py b/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations/_storage_accounts_operations.py index 1e4cf18a5cb..df60a803d97 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations/_storage_accounts_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations/_storage_accounts_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -762,13 +763,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -838,14 +837,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py b/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py index 4c0fc9b0994..3cde6186583 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -1022,13 +1023,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1096,14 +1095,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" From 4d3170ee6e355f0aca95f32ebb401f1f3dedc49c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 10:28:38 -0700 Subject: [PATCH 04/11] regen with paging api version test --- autorest/preprocess/__init__.py | 2 +- .../aio/operations/_paging_operations.py | 7 +- .../operations/_paging_operations.py | 7 +- .../paging/_auto_rest_paging_test_service.py | 3 + .../Paging/paging/_configuration.py | 6 + .../aio/_auto_rest_paging_test_service.py | 3 + .../Paging/paging/aio/_configuration.py | 6 + .../aio/operations/_paging_operations.py | 269 ++++++++-------- .../paging/operations/_paging_operations.py | 287 ++++++++++-------- .../pagingversiontolerant/_client.py | 3 + .../pagingversiontolerant/_configuration.py | 6 + .../pagingversiontolerant/aio/_client.py | 3 + .../aio/_configuration.py | 6 + .../aio/operations/_operations.py | 163 +++++++++- .../operations/_operations.py | 181 ++++++++++- 15 files changed, 659 insertions(+), 293 deletions(-) diff --git a/autorest/preprocess/__init__.py b/autorest/preprocess/__init__.py index ba0010c5b4a..a802b59dcb2 100644 --- a/autorest/preprocess/__init__.py +++ b/autorest/preprocess/__init__.py @@ -170,7 +170,7 @@ def update_paging_operation(self, yaml_data: Dict[str, Any]) -> None: item_type = next( p["type"]["elementType"] for p in returned_response_object["type"]["properties"] - if p["restApiName"] == yaml_data["itemName"] + if p["restApiName"] == (yaml_data["itemName"] or "value") ) if yaml_data.get("nextOperation"): yaml_data["nextOperation"]["groupName"] = pad_reserved_words( diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/aio/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/aio/operations/_paging_operations.py index 4d2e613975b..118d292bcee 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/aio/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/aio/operations/_paging_operations.py @@ -88,12 +88,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url, **path_format_arguments) # type: ignore else: - - request = build_get_pages_partial_url_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) path_format_arguments = { "accountName": self._serialize.url("account_name", account_name, "str", skip_quote=True), diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/operations/_paging_operations.py index 2102951286f..0bc36136ad6 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/custombaseurlpaging/operations/_paging_operations.py @@ -135,12 +135,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url, **path_format_arguments) # type: ignore else: - - request = build_get_pages_partial_url_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) path_format_arguments = { "accountName": self._serialize.url("account_name", account_name, "str", skip_quote=True), diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_auto_rest_paging_test_service.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_auto_rest_paging_test_service.py index 58714a12e1e..767825de303 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_auto_rest_paging_test_service.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_auto_rest_paging_test_service.py @@ -25,6 +25,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :vartype paging: paging.operations.PagingOperations :param base_url: Service URL. Default value is "http://localhost:3000". :type base_url: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_configuration.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_configuration.py index 3352eae9c24..1660053277a 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_configuration.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/_configuration.py @@ -19,11 +19,17 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= Note that all parameters used to create this instance are saved as instance attributes. + + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + self.api_version = api_version kwargs.setdefault("sdk_moniker", "autorestpagingtestservice/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_auto_rest_paging_test_service.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_auto_rest_paging_test_service.py index c61d6109627..b6b7c182fd4 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_auto_rest_paging_test_service.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_auto_rest_paging_test_service.py @@ -25,6 +25,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :vartype paging: paging.aio.operations.PagingOperations :param base_url: Service URL. Default value is "http://localhost:3000". :type base_url: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_configuration.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_configuration.py index b095035214a..9de641828d2 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_configuration.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/_configuration.py @@ -19,11 +19,17 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= Note that all parameters used to create this instance are saved as instance attributes. + + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + self.api_version = api_version kwargs.setdefault("sdk_moniker", "autorestpagingtestservice/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py index 85161525528..5cf77cda9f0 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -49,6 +50,7 @@ build_next_fragment_request, build_next_fragment_with_grouping_request, build_next_operation_with_query_params_request, + build_page_with_api_version_request, ) T = TypeVar("T") @@ -103,12 +105,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_no_item_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -168,12 +169,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_null_next_link_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -233,12 +233,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -299,12 +298,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_first_response_empty_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -381,20 +379,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_options is not None: - _maxresults = paging_get_multiple_pages_options.maxresults - _timeout = paging_get_multiple_pages_options.timeout - - request = build_get_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -536,12 +525,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_duplicate_params_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -619,20 +607,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_odata_multiple_pages_options is not None: - _maxresults = paging_get_odata_multiple_pages_options.maxresults - _timeout = paging_get_odata_multiple_pages_options.timeout - - request = build_get_odata_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -713,23 +692,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _offset = None - _timeout = None - if paging_get_multiple_pages_with_offset_options is not None: - _maxresults = paging_get_multiple_pages_with_offset_options.maxresults - _offset = paging_get_multiple_pages_with_offset_options.offset - _timeout = paging_get_multiple_pages_with_offset_options.timeout - - request = build_get_multiple_pages_with_offset_request( - offset=_offset, - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -790,12 +757,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_first_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -856,12 +822,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_second_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -921,12 +886,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -986,12 +950,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1051,12 +1014,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_uri_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1353,20 +1315,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_lro_options is not None: - _maxresults = paging_get_multiple_pages_lro_options.maxresults - _timeout = paging_get_multiple_pages_lro_options.timeout - - request = build_get_multiple_pages_lro_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1434,6 +1387,73 @@ async def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore + @distributed_trace + def page_with_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~paging.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_page_with_api_version_request( + api_version=api_version, + template_url=self.page_with_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + page_with_api_version.metadata = {"url": "/paging/apiVersion/1"} # type: ignore + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1464,12 +1484,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_paging_model_with_item_name_with_xms_client_name_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py index 41ca73eb5b4..c4f10234a0e 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -415,6 +416,25 @@ def build_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) +def build_page_with_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop("template_url", "/paging/apiVersion/1") + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + def build_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) @@ -477,12 +497,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_no_item_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -542,12 +561,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_null_next_link_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -607,12 +625,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -673,12 +690,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_first_response_empty_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -755,20 +771,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_options is not None: - _maxresults = paging_get_multiple_pages_options.maxresults - _timeout = paging_get_multiple_pages_options.timeout - - request = build_get_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -910,12 +917,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_duplicate_params_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -993,20 +999,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_odata_multiple_pages_options is not None: - _maxresults = paging_get_odata_multiple_pages_options.maxresults - _timeout = paging_get_odata_multiple_pages_options.timeout - - request = build_get_odata_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1087,23 +1084,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _offset = None - _timeout = None - if paging_get_multiple_pages_with_offset_options is not None: - _maxresults = paging_get_multiple_pages_with_offset_options.maxresults - _offset = paging_get_multiple_pages_with_offset_options.offset - _timeout = paging_get_multiple_pages_with_offset_options.timeout - - request = build_get_multiple_pages_with_offset_request( - offset=_offset, - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1164,12 +1149,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_first_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1230,12 +1214,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_second_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1295,12 +1278,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1360,12 +1342,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1425,12 +1406,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_uri_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1726,20 +1706,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_lro_options is not None: - _maxresults = paging_get_multiple_pages_lro_options.maxresults - _timeout = paging_get_multiple_pages_lro_options.timeout - - request = build_get_multiple_pages_lro_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1805,6 +1776,73 @@ def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore + @distributed_trace + def page_with_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~paging.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_page_with_api_version_request( + api_version=api_version, + template_url=self.page_with_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + page_with_api_version.metadata = {"url": "/paging/apiVersion/1"} # type: ignore + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> Iterable["_models.Product"]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1835,12 +1873,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_paging_model_with_item_name_with_xms_client_name_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_client.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_client.py index 5acb8f0a277..1c339c5835a 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_client.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_client.py @@ -28,6 +28,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :vartype paging: pagingversiontolerant.operations.PagingOperations :keyword endpoint: Service URL. Default value is "http://localhost:3000". :paramtype endpoint: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_configuration.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_configuration.py index 3352eae9c24..1660053277a 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_configuration.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/_configuration.py @@ -19,11 +19,17 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= Note that all parameters used to create this instance are saved as instance attributes. + + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + self.api_version = api_version kwargs.setdefault("sdk_moniker", "autorestpagingtestservice/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_client.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_client.py index f1167c9d399..e1bbc495255 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_client.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_client.py @@ -28,6 +28,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :vartype paging: pagingversiontolerant.aio.operations.PagingOperations :keyword endpoint: Service URL. Default value is "http://localhost:3000". :paramtype endpoint: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_configuration.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_configuration.py index b095035214a..9de641828d2 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_configuration.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/_configuration.py @@ -19,11 +19,17 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= Note that all parameters used to create this instance are saved as instance attributes. + + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + self.api_version = api_version kwargs.setdefault("sdk_moniker", "autorestpagingtestservice/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py index 44997ec7d2a..a34c2795a20 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -48,6 +49,7 @@ build_paging_next_fragment_request, build_paging_next_fragment_with_grouping_request, build_paging_next_operation_with_query_params_request, + build_paging_page_with_api_version_request, ) if sys.version_info >= (3, 9): @@ -113,7 +115,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -178,7 +184,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -243,7 +253,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -309,7 +323,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -392,7 +410,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -543,7 +565,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -626,7 +652,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -713,7 +743,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -779,7 +813,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -845,7 +883,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -910,7 +952,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -975,7 +1021,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1040,7 +1090,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1336,7 +1390,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1402,6 +1460,77 @@ async def internal_get_next(next_link=None): ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + @distributed_trace + def page_with_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.async_paging.AsyncItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_page_with_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + async def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> AsyncIterable[JSON]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1440,7 +1569,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py index 94c43df57c7..55f98af0c74 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -422,6 +423,25 @@ def build_paging_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) +def build_paging_page_with_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/paging/apiVersion/1" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + def build_paging_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) @@ -490,7 +510,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -555,7 +579,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -620,7 +648,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -686,7 +718,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -769,7 +805,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -920,7 +960,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1003,7 +1047,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1090,7 +1138,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1156,7 +1208,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1222,7 +1278,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1287,7 +1347,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1352,7 +1416,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1417,7 +1485,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1711,7 +1783,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1775,6 +1851,77 @@ def internal_get_next(next_link=None): ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + @distributed_trace + def page_with_api_version(self, **kwargs: Any) -> Iterable[JSON]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.paging.ItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_page_with_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> Iterable[JSON]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1813,7 +1960,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request From 1d754bb3bd3feb02bae1a85ddf5cc53b1f30249c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 10:30:25 -0700 Subject: [PATCH 05/11] add acceptance tests --- .../azure/legacy/AcceptanceTests/asynctests/test_paging.py | 7 +++++++ test/azure/legacy/AcceptanceTests/test_paging.py | 6 ++++++ .../AcceptanceTests/asynctests/test_paging.py | 7 +++++++ test/azure/version-tolerant/AcceptanceTests/test_paging.py | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py index a143dc5b8ac..82c38a62eb8 100644 --- a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py @@ -247,3 +247,10 @@ async def test_duplicate_params(self, client): assert len(pages) == 1 assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" + + @pytest.mark.asyncio + async def test_api_version(self, client): + pages = [p async for p in client.paging.page_with_api_version()] + assert len(pages) == 1 + assert pages[0].properties.id == 1 + assert pages[0].properties.name == "Product" diff --git a/test/azure/legacy/AcceptanceTests/test_paging.py b/test/azure/legacy/AcceptanceTests/test_paging.py index 28f69086ec8..624b7647649 100644 --- a/test/azure/legacy/AcceptanceTests/test_paging.py +++ b/test/azure/legacy/AcceptanceTests/test_paging.py @@ -186,6 +186,12 @@ def test_duplicate_params(self, client): assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" + def test_api_version(self, client): + pages = list(client.paging.page_with_api_version()) + assert len(pages) == 1 + assert pages[0].properties.id == 1 + assert pages[0].properties.name == "Product" + def test_models(self): from paging.models import OperationResult from paging.models._models_py3 import OperationResult as OperationResultPy3 diff --git a/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py b/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py index d7574fffc63..a2e0b731723 100644 --- a/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py @@ -234,3 +234,10 @@ async def test_duplicate_params(client): assert len(pages) == 1 assert pages[0]["properties"]["id"] == 1 assert pages[0]["properties"]["name"] == "Product" + +@pytest.mark.asyncio +async def test_api_version(client): + pages = [p async for p in client.paging.page_with_api_version()] + assert len(pages) == 1 + assert pages[0]["properties"]["id"] == 1 + assert pages[0]["properties"]["name"] == "Product" diff --git a/test/azure/version-tolerant/AcceptanceTests/test_paging.py b/test/azure/version-tolerant/AcceptanceTests/test_paging.py index 5ffac65c6c0..f28fa98c2d5 100644 --- a/test/azure/version-tolerant/AcceptanceTests/test_paging.py +++ b/test/azure/version-tolerant/AcceptanceTests/test_paging.py @@ -170,3 +170,9 @@ def test_duplicate_params(client): assert len(pages) == 1 assert pages[0]["properties"]["id"] == 1 assert pages[0]["properties"]["name"] == "Product" + +def test_api_version(client): + pages = list(client.paging.page_with_api_version()) + assert len(pages) == 1 + assert pages[0]["properties"]["id"] == 1 + assert pages[0]["properties"]["name"] == "Product" From 6a26de1673a57fa466bbe6966f949aa51ba0ad9b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 10:34:36 -0700 Subject: [PATCH 06/11] update testserver dep --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eae0be054e8..da96aef454d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@autorest/system-requirements": "~1.0.0" }, "devDependencies": { - "@microsoft.azure/autorest.testserver": "^3.3.29" + "@microsoft.azure/autorest.testserver": "^3.3.30" }, "files": [ "autorest/**/*.py", From 89c66d7760a409aa28e09154aa0810d3fba00ec1 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 12:55:40 -0700 Subject: [PATCH 07/11] black and lint --- autorest/codegen/models/client.py | 2 +- autorest/codegen/models/paging_operation.py | 6 +++--- autorest/codegen/serializers/builder_serializer.py | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/autorest/codegen/models/client.py b/autorest/codegen/models/client.py index a25f9316bb1..9a127e52884 100644 --- a/autorest/codegen/models/client.py +++ b/autorest/codegen/models/client.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union, Optional +from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union from .base_model import BaseModel from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList diff --git a/autorest/codegen/models/paging_operation.py b/autorest/codegen/models/paging_operation.py index fe9ce412265..559c5611517 100644 --- a/autorest/codegen/models/paging_operation.py +++ b/autorest/codegen/models/paging_operation.py @@ -140,9 +140,9 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import.merge( self.get_request_builder_import(self.next_request_builder, async_mode) ) - elif ( - "api-version" in [p.rest_api_name for p in self.code_model.client.parameters] - ): + elif "api-version" in [ + p.rest_api_name for p in self.code_model.client.parameters + ]: file_import.add_submodule_import( "urllib.parse", "urlparse", ImportType.STDLIB ) diff --git a/autorest/codegen/serializers/builder_serializer.py b/autorest/codegen/serializers/builder_serializer.py index 065f6c0b983..7209a5e9e85 100644 --- a/autorest/codegen/serializers/builder_serializer.py +++ b/autorest/codegen/serializers/builder_serializer.py @@ -1151,8 +1151,12 @@ def call_next_link_request_builder(self, builder: PagingOperationType) -> List[s ) retval.append("# make call to next link with the client's api-version") retval.append("_parsed_next_link = urlparse(next_link)") - retval.append("_next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query))") - retval.append(f'_next_request_params["api-version"] = {api_version_param.full_client_name}') + retval.append( + "_next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query))" + ) + retval.append( + f'_next_request_params["api-version"] = {api_version_param.full_client_name}' + ) query_str = ", params=_next_request_params" next_link_str = "urljoin(next_link, _parsed_next_link.path)" except StopIteration: From 96cc355e17ec6e3f4f046a1958cb72785df4bf5c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 13:12:35 -0700 Subject: [PATCH 08/11] update tests with append api version paging test --- .../AcceptanceTests/asynctests/test_paging.py | 14 +++ .../legacy/AcceptanceTests/test_paging.py | 10 +- .../aio/operations/_paging_operations.py | 80 ++++++++++++-- .../paging/operations/_paging_operations.py | 100 ++++++++++++++++-- .../AcceptanceTests/asynctests/test_paging.py | 11 +- .../AcceptanceTests/test_paging.py | 10 +- .../aio/operations/_operations.py | 80 +++++++++++++- .../operations/_operations.py | 100 +++++++++++++++++- 8 files changed, 377 insertions(+), 28 deletions(-) diff --git a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py index 82c38a62eb8..a7867bd94bf 100644 --- a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py @@ -254,3 +254,17 @@ async def test_api_version(self, client): assert len(pages) == 1 assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" + + @pytest.mark.asyncio + async def test_append_api_version(self, client): + pages = [p async for p in client.paging.append_api_version()] + assert len(pages) == 1 + assert pages[0].properties.id == 1 + assert pages[0].properties.name == "Product" + + @pytest.mark.asyncio + async def test_replace_api_version(self, client): + pages = [p async for p in client.paging.replace_api_version()] + assert len(pages) == 1 + assert pages[0].properties.id == 1 + assert pages[0].properties.name == "Product" diff --git a/test/azure/legacy/AcceptanceTests/test_paging.py b/test/azure/legacy/AcceptanceTests/test_paging.py index 624b7647649..e19a5d84e8c 100644 --- a/test/azure/legacy/AcceptanceTests/test_paging.py +++ b/test/azure/legacy/AcceptanceTests/test_paging.py @@ -186,8 +186,14 @@ def test_duplicate_params(self, client): assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" - def test_api_version(self, client): - pages = list(client.paging.page_with_api_version()) + def test_append_api_version(self, client): + pages = list(client.paging.append_api_version()) + assert len(pages) == 1 + assert pages[0].properties.id == 1 + assert pages[0].properties.name == "Product" + + def test_replace_api_version(self, client): + pages = list(client.paging.replace_api_version()) assert len(pages) == 1 assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py index 5cf77cda9f0..a833f096b33 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/aio/operations/_paging_operations.py @@ -29,6 +29,7 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._paging_operations import ( + build_append_api_version_request, build_duplicate_params_request, build_first_response_empty_request, build_get_multiple_pages_failure_request, @@ -50,14 +51,14 @@ build_next_fragment_request, build_next_fragment_with_grouping_request, build_next_operation_with_query_params_request, - build_page_with_api_version_request, + build_replace_api_version_request, ) T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -1388,7 +1389,74 @@ async def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore @distributed_trace - def page_with_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: + def append_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~paging.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_append_api_version_request( + api_version=api_version, + template_url=self.append_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + append_api_version.metadata = {"url": "/paging/apiVersion/append/1"} # type: ignore + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: """A paging operation with api version. When calling the next link, you want to reformat it and override the returned api version with your client's api version. @@ -1409,9 +1477,9 @@ def page_with_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product def prepare_request(next_link=None): if not next_link: - request = build_page_with_api_version_request( + request = build_replace_api_version_request( api_version=api_version, - template_url=self.page_with_api_version.metadata["url"], + template_url=self.replace_api_version.metadata["url"], headers=_headers, params=_params, ) @@ -1452,7 +1520,7 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - page_with_api_version.metadata = {"url": "/paging/apiVersion/1"} # type: ignore + replace_api_version.metadata = {"url": "/paging/apiVersion/replace/1"} # type: ignore @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: diff --git a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py index c4f10234a0e..188312508eb 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py @@ -416,7 +416,7 @@ def build_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) -def build_page_with_api_version_request(**kwargs: Any) -> HttpRequest: +def build_append_api_version_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -424,7 +424,26 @@ def build_page_with_api_version_request(**kwargs: Any) -> HttpRequest: accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/paging/apiVersion/1") + _url = kwargs.pop("template_url", "/paging/apiVersion/append/1") + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_replace_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop("template_url", "/paging/apiVersion/replace/1") # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -449,7 +468,7 @@ def build_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -1777,7 +1796,74 @@ def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore @distributed_trace - def page_with_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: + def append_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~paging.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_append_api_version_request( + api_version=api_version, + template_url=self.append_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + append_api_version.metadata = {"url": "/paging/apiVersion/append/1"} # type: ignore + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: """A paging operation with api version. When calling the next link, you want to reformat it and override the returned api version with your client's api version. @@ -1798,9 +1884,9 @@ def page_with_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: def prepare_request(next_link=None): if not next_link: - request = build_page_with_api_version_request( + request = build_replace_api_version_request( api_version=api_version, - template_url=self.page_with_api_version.metadata["url"], + template_url=self.replace_api_version.metadata["url"], headers=_headers, params=_params, ) @@ -1841,7 +1927,7 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - page_with_api_version.metadata = {"url": "/paging/apiVersion/1"} # type: ignore + replace_api_version.metadata = {"url": "/paging/apiVersion/replace/1"} # type: ignore @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> Iterable["_models.Product"]: diff --git a/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py b/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py index a2e0b731723..cc34b41860a 100644 --- a/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/version-tolerant/AcceptanceTests/asynctests/test_paging.py @@ -236,8 +236,15 @@ async def test_duplicate_params(client): assert pages[0]["properties"]["name"] == "Product" @pytest.mark.asyncio -async def test_api_version(client): - pages = [p async for p in client.paging.page_with_api_version()] +async def test_append_api_version(client): + pages = [p async for p in client.paging.append_api_version()] + assert len(pages) == 1 + assert pages[0]["properties"]["id"] == 1 + assert pages[0]["properties"]["name"] == "Product" + +@pytest.mark.asyncio +async def test_replace_api_version(client): + pages = [p async for p in client.paging.replace_api_version()] assert len(pages) == 1 assert pages[0]["properties"]["id"] == 1 assert pages[0]["properties"]["name"] == "Product" diff --git a/test/azure/version-tolerant/AcceptanceTests/test_paging.py b/test/azure/version-tolerant/AcceptanceTests/test_paging.py index f28fa98c2d5..601a2c80fa8 100644 --- a/test/azure/version-tolerant/AcceptanceTests/test_paging.py +++ b/test/azure/version-tolerant/AcceptanceTests/test_paging.py @@ -171,8 +171,14 @@ def test_duplicate_params(client): assert pages[0]["properties"]["id"] == 1 assert pages[0]["properties"]["name"] == "Product" -def test_api_version(client): - pages = list(client.paging.page_with_api_version()) +def test_append_api_version(client): + pages = list(client.paging.append_api_version()) + assert len(pages) == 1 + assert pages[0]["properties"]["id"] == 1 + assert pages[0]["properties"]["name"] == "Product" + +def test_replace_api_version(client): + pages = list(client.paging.replace_api_version()) assert len(pages) == 1 assert pages[0]["properties"]["id"] == 1 assert pages[0]["properties"]["name"] == "Product" diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py index a34c2795a20..6547a7d08b0 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/aio/operations/_operations.py @@ -28,6 +28,7 @@ from azure.core.utils import case_insensitive_dict from ...operations._operations import ( + build_paging_append_api_version_request, build_paging_duplicate_params_request, build_paging_first_response_empty_request, build_paging_get_multiple_pages_failure_request, @@ -49,7 +50,7 @@ build_paging_next_fragment_request, build_paging_next_fragment_with_grouping_request, build_paging_next_operation_with_query_params_request, - build_paging_page_with_api_version_request, + build_paging_replace_api_version_request, ) if sys.version_info >= (3, 9): @@ -61,7 +62,7 @@ ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -1461,7 +1462,78 @@ async def internal_get_next(next_link=None): return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) @distributed_trace - def page_with_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: + def append_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.async_paging.AsyncItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_append_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + async def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: """A paging operation with api version. When calling the next link, you want to reformat it and override the returned api version with your client's api version. @@ -1491,7 +1563,7 @@ def page_with_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: def prepare_request(next_link=None): if not next_link: - request = build_paging_page_with_api_version_request( + request = build_paging_replace_api_version_request( api_version=self._config.api_version, headers=_headers, params=_params, diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py index 55f98af0c74..0b5b9fb08d2 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/pagingversiontolerant/operations/_operations.py @@ -423,7 +423,7 @@ def build_paging_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) -def build_paging_page_with_api_version_request(**kwargs: Any) -> HttpRequest: +def build_paging_append_api_version_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -431,7 +431,26 @@ def build_paging_page_with_api_version_request(**kwargs: Any) -> HttpRequest: accept = _headers.pop("Accept", "application/json") # Construct URL - _url = "/paging/apiVersion/1" + _url = "/paging/apiVersion/append/1" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_paging_replace_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/paging/apiVersion/replace/1" # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -456,7 +475,7 @@ def build_paging_get_paging_model_with_item_name_with_xms_client_name_request(** return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -1852,7 +1871,78 @@ def internal_get_next(next_link=None): return LROPoller(self._client, raw_result, get_long_running_output, polling_method) @distributed_trace - def page_with_api_version(self, **kwargs: Any) -> Iterable[JSON]: + def append_api_version(self, **kwargs: Any) -> Iterable[JSON]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.paging.ItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_append_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> Iterable[JSON]: """A paging operation with api version. When calling the next link, you want to reformat it and override the returned api version with your client's api version. @@ -1882,7 +1972,7 @@ def page_with_api_version(self, **kwargs: Any) -> Iterable[JSON]: def prepare_request(next_link=None): if not next_link: - request = build_paging_page_with_api_version_request( + request = build_paging_replace_api_version_request( api_version=self._config.api_version, headers=_headers, params=_params, From 6ee76e139a750145b5c7bda77ac3003c998199d2 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 15:38:13 -0700 Subject: [PATCH 09/11] regen --- .../_multiapi_service_client_operations.py | 1 + .../_multiapi_service_client_operations.py | 8 +- .../_multiapi_service_client_operations.py | 8 +- .../_multiapi_service_client_operations.py | 8 +- .../_auto_rest_paging_test_service.py | 3 + .../custompollerpager/_configuration.py | 6 + .../aio/_auto_rest_paging_test_service.py | 3 + .../custompollerpager/aio/_configuration.py | 6 + .../aio/operations/_paging_operations.py | 339 ++++++++++------ .../operations/_paging_operations.py | 375 ++++++++++++------ .../_client.py | 3 + .../_configuration.py | 6 + .../aio/_client.py | 3 + .../aio/_configuration.py | 6 + .../aio/operations/_operations.py | 237 ++++++++++- .../operations/_operations.py | 273 ++++++++++++- .../aio/operations/_operations.py | 20 +- .../operations/_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 20 +- .../_multiapi_service_client_operations.py | 12 +- .../_multiapi_service_client_operations.py | 12 +- 38 files changed, 1134 insertions(+), 519 deletions(-) diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py index 5f5a5fd355c..3c1e2632246 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/aio/operations/_multiapi_service_client_operations.py @@ -371,6 +371,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: + # make call to next link with the client's api-version _parsed_next_link = urlparse(next_link) _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) _next_request_params["api-version"] = self._config.api_version diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py index d7d0e768b22..25492055295 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v1/operations/_multiapi_service_client_operations.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload -from urllib.parse import parse_qs, urlparse +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -445,9 +445,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest("GET", next_link, params=_next_request_params) + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py index 16a068f7434..dd7df34c9a6 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar -from urllib.parse import parse_qs, urlparse +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -67,9 +67,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest("GET", next_link, params=_next_request_params) + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py index e73400733f5..2dae9416065 100644 --- a/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py +++ b/docs/samples/specification/multiapi/generated/azure/multiapi/sample/v3/operations/_multiapi_service_client_operations.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from urllib.parse import parse_qs, urlparse +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -109,9 +109,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params = case_insensitive_dict(parse_qs(urlparse(next_link).query)) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest("GET", next_link, params=_next_request_params) + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_auto_rest_paging_test_service.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_auto_rest_paging_test_service.py index de9fbd1dd79..927c0d278e1 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_auto_rest_paging_test_service.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_auto_rest_paging_test_service.py @@ -31,6 +31,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :type credential: ~azure.core.credentials.TokenCredential :param base_url: Service URL. Default value is "http://localhost:3000". :type base_url: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_configuration.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_configuration.py index f77ec997826..4e3e9a5fd86 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_configuration.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/_configuration.py @@ -27,14 +27,20 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + if credential is None: raise ValueError("Parameter 'credential' must not be None.") self.credential = credential + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "custompollerpager/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_auto_rest_paging_test_service.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_auto_rest_paging_test_service.py index 8d0d183535c..fe272056899 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_auto_rest_paging_test_service.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_auto_rest_paging_test_service.py @@ -31,6 +31,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param base_url: Service URL. Default value is "http://localhost:3000". :type base_url: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_configuration.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_configuration.py index abcb38a81fc..559644e6e5d 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_configuration.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/_configuration.py @@ -27,14 +27,20 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + if credential is None: raise ValueError("Parameter 'credential' must not be None.") self.credential = credential + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "custompollerpager/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/operations/_paging_operations.py index 1d0c4931638..9def3c95f30 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/aio/operations/_paging_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -30,6 +31,7 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._paging_operations import ( + build_append_api_version_request, build_duplicate_params_request, build_first_response_empty_request, build_get_multiple_pages_failure_request, @@ -51,13 +53,14 @@ build_next_fragment_request, build_next_fragment_with_grouping_request, build_next_operation_with_query_params_request, + build_replace_api_version_request, ) T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -105,12 +108,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_no_item_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -170,12 +172,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_null_next_link_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -235,12 +236,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -301,12 +301,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_first_response_empty_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -384,20 +383,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_options is not None: - _maxresults = paging_get_multiple_pages_options.maxresults - _timeout = paging_get_multiple_pages_options.timeout - - request = build_get_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -539,12 +529,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_duplicate_params_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -622,20 +611,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_odata_multiple_pages_options is not None: - _maxresults = paging_get_odata_multiple_pages_options.maxresults - _timeout = paging_get_odata_multiple_pages_options.timeout - - request = build_get_odata_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -716,23 +696,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _offset = None - _timeout = None - if paging_get_multiple_pages_with_offset_options is not None: - _maxresults = paging_get_multiple_pages_with_offset_options.maxresults - _offset = paging_get_multiple_pages_with_offset_options.offset - _timeout = paging_get_multiple_pages_with_offset_options.timeout - - request = build_get_multiple_pages_with_offset_request( - offset=_offset, - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -793,12 +761,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_first_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -859,12 +826,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_second_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -924,12 +890,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -989,12 +954,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1054,12 +1018,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_uri_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1357,20 +1320,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_lro_options is not None: - _maxresults = paging_get_multiple_pages_lro_options.maxresults - _timeout = paging_get_multiple_pages_lro_options.timeout - - request = build_get_multiple_pages_lro_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1436,6 +1390,140 @@ async def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore + @distributed_trace + def append_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~custompollerpager.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_append_api_version_request( + api_version=api_version, + template_url=self.append_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + append_api_version.metadata = {"url": "/paging/apiVersion/append/1"} # type: ignore + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~custompollerpager.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_replace_api_version_request( + api_version=api_version, + template_url=self.replace_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + replace_api_version.metadata = {"url": "/paging/apiVersion/replace/1"} # type: ignore + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> AsyncIterable["_models.Product"]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1466,12 +1554,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_paging_model_with_item_name_with_xms_client_name_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/operations/_paging_operations.py b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/operations/_paging_operations.py index a3026d0e3e4..01bc882c82b 100644 --- a/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/operations/_paging_operations.py +++ b/test/azure/legacy/Expected/AcceptanceTests/CustomPollerPager/custompollerpager/operations/_paging_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -417,6 +418,44 @@ def build_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) +def build_append_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop("template_url", "/paging/apiVersion/append/1") + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_replace_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop("template_url", "/paging/apiVersion/replace/1") + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + def build_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) @@ -431,7 +470,7 @@ def build_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -479,12 +518,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_no_item_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -544,12 +582,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_null_next_link_name_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -609,12 +646,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -675,12 +711,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_first_response_empty_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -758,20 +793,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_options is not None: - _maxresults = paging_get_multiple_pages_options.maxresults - _timeout = paging_get_multiple_pages_options.timeout - - request = build_get_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -913,12 +939,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_duplicate_params_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -996,20 +1021,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_odata_multiple_pages_options is not None: - _maxresults = paging_get_odata_multiple_pages_options.maxresults - _timeout = paging_get_odata_multiple_pages_options.timeout - - request = build_get_odata_multiple_pages_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1090,23 +1106,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _offset = None - _timeout = None - if paging_get_multiple_pages_with_offset_options is not None: - _maxresults = paging_get_multiple_pages_with_offset_options.maxresults - _offset = paging_get_multiple_pages_with_offset_options.offset - _timeout = paging_get_multiple_pages_with_offset_options.timeout - - request = build_get_multiple_pages_with_offset_request( - offset=_offset, - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1167,12 +1171,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_first_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1233,12 +1236,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_retry_second_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1298,12 +1300,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_single_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1363,12 +1364,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1428,12 +1428,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_multiple_pages_failure_uri_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1731,20 +1730,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if paging_get_multiple_pages_lro_options is not None: - _maxresults = paging_get_multiple_pages_lro_options.maxresults - _timeout = paging_get_multiple_pages_lro_options.timeout - - request = build_get_multiple_pages_lro_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1810,6 +1800,140 @@ def internal_get_next(next_link=None): begin_get_multiple_pages_lro.metadata = {"url": "/paging/multiple/lro"} # type: ignore + @distributed_trace + def append_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~custompollerpager.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_append_api_version_request( + api_version=api_version, + template_url=self.append_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + append_api_version.metadata = {"url": "/paging/apiVersion/append/1"} # type: ignore + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> Iterable["_models.Product"]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Product or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~custompollerpager.models.Product] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ProductResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_replace_api_version_request( + api_version=api_version, + template_url=self.replace_api_version.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProductResult", pipeline_response) + list_of_elem = deserialized.values + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + replace_api_version.metadata = {"url": "/paging/apiVersion/replace/1"} # type: ignore + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> Iterable["_models.Product"]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1840,12 +1964,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_get_paging_model_with_item_name_with_xms_client_name_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_client.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_client.py index 12b1aad54e2..4021248577f 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_client.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_client.py @@ -32,6 +32,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :type credential: ~azure.core.credentials.TokenCredential :keyword endpoint: Service URL. Default value is "http://localhost:3000". :paramtype endpoint: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_configuration.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_configuration.py index 8ef4715c52a..25626630011 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_configuration.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/_configuration.py @@ -27,14 +27,20 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + if credential is None: raise ValueError("Parameter 'credential' must not be None.") self.credential = credential + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "custompollerpagerversiontolerant/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_client.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_client.py index 7fba8ac463d..7604055a3c7 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_client.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_client.py @@ -32,6 +32,9 @@ class AutoRestPagingTestService: # pylint: disable=client-accepts-api-version-k :type credential: ~azure.core.credentials_async.AsyncTokenCredential :keyword endpoint: Service URL. Default value is "http://localhost:3000". :paramtype endpoint: str + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_configuration.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_configuration.py index 21f06fd30f1..2777e209700 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_configuration.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/_configuration.py @@ -27,14 +27,20 @@ class AutoRestPagingTestServiceConfiguration(Configuration): # pylint: disable= :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :keyword api_version: Api Version. Default value is "1.0.0". Note that overriding this default + value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", **kwargs: Any) -> None: super(AutoRestPagingTestServiceConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop("api_version", "1.0.0") # type: str + if credential is None: raise ValueError("Parameter 'credential' must not be None.") self.credential = credential + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "custompollerpagerversiontolerant/{}".format(VERSION)) self._configure(**kwargs) diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/operations/_operations.py index 73681d7f8af..163474cd428 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -29,6 +30,7 @@ from custompollerpagerdefinitions.aio import AsyncCustomPager, AsyncCustomPoller from ...operations._operations import ( + build_paging_append_api_version_request, build_paging_duplicate_params_request, build_paging_first_response_empty_request, build_paging_get_multiple_pages_failure_request, @@ -50,6 +52,7 @@ build_paging_next_fragment_request, build_paging_next_fragment_with_grouping_request, build_paging_next_operation_with_query_params_request, + build_paging_replace_api_version_request, ) if sys.version_info >= (3, 9): @@ -61,7 +64,7 @@ ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -115,7 +118,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -180,7 +187,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -245,7 +256,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -311,7 +326,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -394,7 +413,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -545,7 +568,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -628,7 +655,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -715,7 +746,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -781,7 +816,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -847,7 +886,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -912,7 +955,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -977,7 +1024,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1042,7 +1093,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1339,7 +1394,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1403,6 +1462,148 @@ async def internal_get_next(next_link=None): ) return AsyncCustomPoller(self._client, raw_result, get_long_running_output, polling_method) + @distributed_trace + def append_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.async_paging.AsyncItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_append_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + async def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> AsyncIterable[JSON]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.async_paging.AsyncItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_replace_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + async def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> AsyncIterable[JSON]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1441,7 +1642,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/operations/_operations.py index 04900070b70..c8c735ed34d 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/CustomPollerPagerVersionTolerant/custompollerpagerversiontolerant/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -424,6 +425,44 @@ def build_paging_get_multiple_pages_lro_request( return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) +def build_paging_append_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/paging/apiVersion/append/1" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_paging_replace_api_version_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "1.0.0")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/paging/apiVersion/replace/1" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + def build_paging_get_paging_model_with_item_name_with_xms_client_name_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) @@ -438,7 +477,7 @@ def build_paging_get_paging_model_with_item_name_with_xms_client_name_request(** return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) -class PagingOperations: +class PagingOperations: # pylint: disable=too-many-public-methods """ .. warning:: **DO NOT** instantiate this class directly. @@ -492,7 +531,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -557,7 +600,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -622,7 +669,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -688,7 +739,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -771,7 +826,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -922,7 +981,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1005,7 +1068,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1092,7 +1159,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1158,7 +1229,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1224,7 +1299,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1289,7 +1368,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1354,7 +1437,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1419,7 +1506,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1713,7 +1804,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1777,6 +1872,148 @@ def internal_get_next(next_link=None): ) return CustomPoller(self._client, raw_result, get_long_running_output, polling_method) + @distributed_trace + def append_api_version(self, **kwargs: Any) -> Iterable[JSON]: + """A paging operation with api version. When calling the next link, you want to append your + client's api version to the next link. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.paging.ItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_append_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + @distributed_trace + def replace_api_version(self, **kwargs: Any) -> Iterable[JSON]: + """A paging operation with api version. When calling the next link, you want to reformat it and + override the returned api version with your client's api version. + + :return: An iterator like instance of JSON object + :rtype: ~azure.core.paging.ItemPaged[JSON] + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "properties": { + "id": 0, # Optional. + "name": "str" # Optional. + } + } + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls = kwargs.pop("cls", None) # type: ClsType[JSON] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_paging_replace_api_version_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + request.url = self._client.format_url(request.url) # type: ignore + + else: + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) + request.url = self._client.format_url(request.url) # type: ignore + + return request + + def extract_data(pipeline_response): + deserialized = pipeline_response.http_response.json() + list_of_elem = deserialized["values"] + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.get("nextLink", None), iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + @distributed_trace def get_paging_model_with_item_name_with_xms_client_name(self, **kwargs: Any) -> Iterable[JSON]: """A paging operation that returns a paging model whose item name is is overriden by @@ -1815,7 +2052,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py index 0aabaa4670c..72354cc3a47 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload -from urllib.parse import parse_qs, urlparse +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -1374,10 +1374,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params: Dict[str, str] = {} - if "api-version" not in parse_qs(urlparse(next_link).query).keys(): - _next_request_params = {"api-version": self._config.api_version} - request = HttpRequest("GET", next_link, params=_next_request_params) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1508,10 +1509,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params: Dict[str, str] = {} - if "api-version" not in parse_qs(urlparse(next_link).query).keys(): - _next_request_params = {"api-version": self._config.api_version} - request = HttpRequest("GET", next_link, params=_next_request_params) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py index 2233715b487..8456973f7f6 100644 --- a/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py +++ b/test/azure/version-tolerant/Expected/AcceptanceTests/StorageManagementClientVersionTolerant/storageversiontolerant/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import sys from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload -from urllib.parse import parse_qs, urlparse +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -1639,10 +1639,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params: Dict[str, str] = {} - if "api-version" not in parse_qs(urlparse(next_link).query).keys(): - _next_request_params = {"api-version": self._config.api_version} - request = HttpRequest("GET", next_link, params=_next_request_params) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request @@ -1773,10 +1774,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _next_request_params: Dict[str, str] = {} - if "api-version" not in parse_qs(urlparse(next_link).query).keys(): - _next_request_params = {"api-version": self._config.api_version} - request = HttpRequest("GET", next_link, params=_next_request_params) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request.url = self._client.format_url(request.url) # type: ignore return request diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations/_multiapi_service_client_operations.py index 8fe59679a12..df77ba3bb4c 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -370,20 +371,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py index cc1bf7ef671..526524caf3a 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -444,20 +445,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/aio/operations/_multiapi_service_client_operations.py index 15ecbe2364d..fbc7a542a8e 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -66,12 +67,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/operations/_multiapi_service_client_operations.py index dca9d95c7c2..0f24863caed 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -108,12 +109,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations/_multiapi_service_client_operations.py index a7df273a288..f61ae152b8d 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -371,20 +372,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/operations/_multiapi_service_client_operations.py index 46695e998b8..6366067f934 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -445,20 +446,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/aio/operations/_multiapi_service_client_operations.py index 3b55603ed98..137c18f88dc 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -67,12 +68,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/operations/_multiapi_service_client_operations.py index 1fd3e16eb45..6115e02b0dc 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -108,12 +109,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/aio/operations/_multiapi_service_client_operations.py index 3a66e899806..e10e733cd10 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -371,20 +372,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/operations/_multiapi_service_client_operations.py index 5d9900d0cfa..78fbb70a78e 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -443,20 +444,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/aio/operations/_multiapi_service_client_operations.py index 37ecb7ff1dc..079a9eb07c6 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -65,12 +66,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/operations/_multiapi_service_client_operations.py index a3e702d4b97..64675f4253d 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiDataPlane/multiapidataplane/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -107,12 +108,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py index 85ca722c3d2..c8158d267c0 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -444,20 +445,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/operations/_multiapi_service_client_operations.py index 58a8934bf79..86d01c4b8ac 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -108,12 +109,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/aio/operations/_multiapi_service_client_operations.py index 78c1d19959b..fa7c3841419 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -371,20 +372,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/operations/_multiapi_service_client_operations.py index 0d975d5de48..ca2365c8a36 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiSecurity/multiapisecurity/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -443,20 +444,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations/_multiapi_service_client_operations.py index fb78b3f0cb4..c448f7b6504 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -371,20 +372,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py index d653758e623..4b866ad2c8e 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -445,20 +446,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - _maxresults = None - _timeout = None - if test_lro_and_paging_options is not None: - _maxresults = test_lro_and_paging_options.maxresults - _timeout = test_lro_and_paging_options.timeout - - request = build_test_lro_and_paging_request( - client_request_id=client_request_id, - maxresults=_maxresults, - timeout=_timeout, - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/aio/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/aio/operations/_multiapi_service_client_operations.py index 52b28320d4a..2e00b907f6b 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/aio/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/aio/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -67,12 +68,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/operations/_multiapi_service_client_operations.py index 5f9bde6e9f6..de7d5156208 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/operations/_multiapi_service_client_operations.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from urllib.parse import parse_qs, urljoin, urlparse from azure.core.exceptions import ( ClientAuthenticationError, @@ -108,12 +109,11 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_test_paging_request( - template_url=next_link, - headers=_headers, - params=_params, - ) + # make call to next link with the client's api-version + _parsed_next_link = urlparse(next_link) + _next_request_params = case_insensitive_dict(parse_qs(_parsed_next_link.query)) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest("GET", urljoin(next_link, _parsed_next_link.path), params=_next_request_params) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" From 1926e03c5724368897193fab52798e05e6a64bb9 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Jun 2022 16:06:00 -0700 Subject: [PATCH 10/11] remove old test --- .../azure/legacy/AcceptanceTests/asynctests/test_paging.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py index a7867bd94bf..c6b79bf8acf 100644 --- a/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/legacy/AcceptanceTests/asynctests/test_paging.py @@ -248,13 +248,6 @@ async def test_duplicate_params(self, client): assert pages[0].properties.id == 1 assert pages[0].properties.name == "Product" - @pytest.mark.asyncio - async def test_api_version(self, client): - pages = [p async for p in client.paging.page_with_api_version()] - assert len(pages) == 1 - assert pages[0].properties.id == 1 - assert pages[0].properties.name == "Product" - @pytest.mark.asyncio async def test_append_api_version(self, client): pages = [p async for p in client.paging.append_api_version()] From 1a325a3edb410ba0aeaef38d3201780527936714 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 22 Jun 2022 10:37:06 -0700 Subject: [PATCH 11/11] fix lropaging overloads --- autorest/preprocess/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/autorest/preprocess/__init__.py b/autorest/preprocess/__init__.py index a802b59dcb2..a73cdd751c8 100644 --- a/autorest/preprocess/__init__.py +++ b/autorest/preprocess/__init__.py @@ -144,13 +144,16 @@ def _update_lro_operation_helper(self, yaml_data: Dict[str, Any]) -> None: def update_lro_paging_operation(self, yaml_data: Dict[str, Any]) -> None: self.update_lro_operation(yaml_data) self.update_paging_operation(yaml_data) + yaml_data["discriminator"] = "lropaging" for response in yaml_data.get("responses", []): response["discriminator"] = "lropaging" + for overload in yaml_data.get("overloads", []): + self.update_lro_paging_operation(overload) def update_lro_operation(self, yaml_data: Dict[str, Any]) -> None: self.update_operation(yaml_data) self._update_lro_operation_helper(yaml_data) - for overload in yaml_data["overloads"]: + for overload in yaml_data.get("overloads", []): self._update_lro_operation_helper(overload) def update_paging_operation(self, yaml_data: Dict[str, Any]) -> None: @@ -170,7 +173,7 @@ def update_paging_operation(self, yaml_data: Dict[str, Any]) -> None: item_type = next( p["type"]["elementType"] for p in returned_response_object["type"]["properties"] - if p["restApiName"] == (yaml_data["itemName"] or "value") + if p["restApiName"] == (yaml_data.get("itemName") or "value") ) if yaml_data.get("nextOperation"): yaml_data["nextOperation"]["groupName"] = pad_reserved_words(