Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: internal
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Add mock API test case for the `AlternateInitialVerb` POST pagination scenario where the initial request uses POST with a filter body and subsequent next link requests use GET.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: internal
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Skip 8 failing client structure test cases pending `@azure-tools/typespec-client-generator-core` upgrade to 0.67.0
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjAyMDkyMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.0.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjAzMjIxMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.0.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "^4.21.0"
Expand Down
14 changes: 7 additions & 7 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"@azure-tools/typespec-azure-core": ">=0.66.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.66.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.66.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.65.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.66.1 <1.0.0"
"@azure-tools/typespec-azure-rulesets": ">=0.66.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.66.2 <1.0.0"
},
"dependencies": {
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
"tsx": "^4.21.0",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjAyMDkyMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.0.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjAzMjIxMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.0.tgz",
"fs-extra": "~11.2.0"
},
"devDependencies": {
Expand All @@ -83,11 +83,11 @@
"@typespec/xml": "~0.80.0",
"@azure-tools/typespec-azure-resource-manager": "~0.66.0",
"@azure-tools/typespec-azure-core": "~0.66.0",
"@azure-tools/typespec-azure-rulesets": "~0.65.1",
"@azure-tools/typespec-azure-rulesets": "~0.66.0",
"@azure-tools/typespec-autorest": "~0.66.0",
"@azure-tools/typespec-client-generator-core": "~0.66.1",
"@azure-tools/azure-http-specs": "0.1.0-alpha.39-dev.3",
"@typespec/http-specs": "0.1.0-alpha.35-dev.1",
"@azure-tools/typespec-client-generator-core": "~0.66.2",
"@azure-tools/azure-http-specs": "0.1.0-alpha.39-dev.4",
"@typespec/http-specs": "0.1.0-alpha.35-dev.4",
"@typespec/spector": "0.1.0-alpha.24",
"@typespec/spec-api": "0.1.0-alpha.14-dev.1",
"@types/js-yaml": "~4.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"CrossLanguagePackageId": "Payload.Pageable",
"CrossLanguageDefinitionId": {
"payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter": "Payload.Pageable.ServerDrivenPagination.AlternateInitialVerb.Filter",
"payload.pageable.serverdrivenpagination.models.NestedLinkResponseNestedItems": "Payload.Pageable.ServerDrivenPagination.nestedLink.Response.nestedItems.anonymous",
"payload.pageable.serverdrivenpagination.models.NestedLinkResponseNestedNext": "Payload.Pageable.ServerDrivenPagination.nestedLink.Response.nestedNext.anonymous",
"payload.pageable.models.Pet": "Payload.Pageable.Pet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def test_server_driven_pagination_nested_link(self, pageable_endpoint):
# please add some check logic here by yourself
# ...

@PageablePreparer()
@recorded_by_proxy
def test_server_driven_pagination_alternate_initial_verb_post(self, pageable_endpoint):
client = self.create_client(endpoint=pageable_endpoint)
response = client.server_driven_pagination.alternate_initial_verb.post(
body={"filter": "str"},
)
result = [r for r in response]
# please add some check logic here by yourself
# ...

@PageablePreparer()
@recorded_by_proxy
def test_server_driven_pagination_continuation_token_request_query_response_body(self, pageable_endpoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ async def test_server_driven_pagination_nested_link(self, pageable_endpoint):
# please add some check logic here by yourself
# ...

@PageablePreparer()
@recorded_by_proxy_async
async def test_server_driven_pagination_alternate_initial_verb_post(self, pageable_endpoint):
client = self.create_async_client(endpoint=pageable_endpoint)
response = client.server_driven_pagination.alternate_initial_verb.post(
body={"filter": "str"},
)
result = [r async for r in response]
# please add some check logic here by yourself
# ...

@PageablePreparer()
@recorded_by_proxy_async
async def test_server_driven_pagination_continuation_token_request_query_response_body(self, pageable_endpoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ...._utils.model_base import _deserialize
from ...._utils.serialization import Deserializer, Serializer
from ....aio._configuration import PageableClientConfiguration
from ...alternateinitialverb.aio.operations._operations import ServerDrivenPaginationAlternateInitialVerbOperations
from ...continuationtoken.aio.operations._operations import ServerDrivenPaginationContinuationTokenOperations
from ...operations._operations import (
build_server_driven_pagination_link_request,
Expand Down Expand Up @@ -54,6 +55,9 @@ def __init__(self, *args, **kwargs) -> None:
self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer")
self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer")

self.alternate_initial_verb = ServerDrivenPaginationAlternateInitialVerbOperations(
self._client, self._config, self._serialize, self._deserialize
)
self.continuation_token = ServerDrivenPaginationContinuationTokenOperations(
self._client, self._config, self._serialize, self._deserialize
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import


from ._patch import __all__ as _patch_all
from ._patch import *
from ._patch import patch_sdk as _patch_sdk

__all__ = []
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
_patch_sdk()
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from collections.abc import MutableMapping
from io import IOBase
import json
from typing import Any, Callable, IO, Optional, TypeVar, Union, overload

from azure.core import AsyncPipelineClient
from azure.core.async_paging import AsyncItemPaged, AsyncList
from azure.core.exceptions import (
ClientAuthenticationError,
HttpResponseError,
ResourceExistsError,
ResourceNotFoundError,
ResourceNotModifiedError,
map_error,
)
from azure.core.pipeline import PipelineResponse
from azure.core.rest import AsyncHttpResponse, HttpRequest
from azure.core.tracing.decorator import distributed_trace
from azure.core.utils import case_insensitive_dict

from ... import models as _models2
from ..... import models as _models4
from ....._utils.model_base import SdkJSONEncoder, _deserialize
from ....._utils.serialization import Deserializer, Serializer
from .....aio._configuration import PageableClientConfiguration
from ...operations._operations import build_server_driven_pagination_alternate_initial_verb_post_request

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


class ServerDrivenPaginationAlternateInitialVerbOperations: # pylint: disable=name-too-long
"""
.. warning::
**DO NOT** instantiate this class directly.

Instead, you should access the following operations through
:class:`~payload.pageable.aio.PageableClient`'s
:attr:`alternate_initial_verb` attribute.
"""

def __init__(self, *args, **kwargs) -> None:
input_args = list(args)
self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client")
self._config: PageableClientConfiguration = input_args.pop(0) if input_args else kwargs.pop("config")
self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer")
self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer")

@overload
def post(
self, body: _models2.Filter, *, content_type: str = "application/json", **kwargs: Any
) -> AsyncItemPaged["_models4.Pet"]:
"""post.

:param body: Required.
:type body: ~payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: An iterator like instance of Pet
:rtype: ~azure.core.async_paging.AsyncItemPaged[~payload.pageable.models.Pet]
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def post(
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
) -> AsyncItemPaged["_models4.Pet"]:
"""post.

:param body: Required.
:type body: JSON
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: An iterator like instance of Pet
:rtype: ~azure.core.async_paging.AsyncItemPaged[~payload.pageable.models.Pet]
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def post(
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
) -> AsyncItemPaged["_models4.Pet"]:
"""post.

:param body: Required.
:type body: IO[bytes]
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
Default value is "application/json".
:paramtype content_type: str
:return: An iterator like instance of Pet
:rtype: ~azure.core.async_paging.AsyncItemPaged[~payload.pageable.models.Pet]
:raises ~azure.core.exceptions.HttpResponseError:
"""

@distributed_trace
def post(self, body: Union[_models2.Filter, JSON, IO[bytes]], **kwargs: Any) -> AsyncItemPaged["_models4.Pet"]:
"""post.

:param body: Is one of the following types: Filter, JSON, IO[bytes] Required.
:type body: ~payload.pageable.serverdrivenpagination.alternateinitialverb.models.Filter or JSON
or IO[bytes]
:return: An iterator like instance of Pet
:rtype: ~azure.core.async_paging.AsyncItemPaged[~payload.pageable.models.Pet]
:raises ~azure.core.exceptions.HttpResponseError:
"""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
cls: ClsType[list[_models4.Pet]] = kwargs.pop("cls", None)

error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})
content_type = content_type or "application/json"
_content = None
if isinstance(body, (IOBase, bytes)):
_content = body
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

def prepare_request(next_link=None):
if not next_link:

_request = build_server_driven_pagination_alternate_initial_verb_post_request(
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
)
path_format_arguments = {
"endpoint": self._serialize.url(
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True
),
}
_request.url = self._client.format_url(_request.url, **path_format_arguments)

else:
_request = HttpRequest("GET", next_link)
path_format_arguments = {
"endpoint": self._serialize.url(
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True
),
}
_request.url = self._client.format_url(_request.url, **path_format_arguments)

return _request

async def extract_data(pipeline_response):
deserialized = pipeline_response.http_response.json()
list_of_elem = _deserialize(
list[_models4.Pet],
deserialized.get("pets", []),
)
if cls:
list_of_elem = cls(list_of_elem) # type: ignore
return deserialized.get("next") or None, AsyncList(list_of_elem)

async def get_next(next_link=None):
_request = prepare_request(next_link)

_stream = False
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------
"""Customize generated code here.
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""


__all__: list[str] = [] # Add all objects you want publicly available to users at this package level


def patch_sdk():
"""Do not remove from this file.
`patch_sdk` is a last resort escape hatch that allows you to do customizations
you can't accomplish using the techniques described in
https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import


from ._models import ( # type: ignore
Filter,
)
from ._patch import __all__ as _patch_all
from ._patch import *
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"Filter",
]
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
_patch_sdk()
Loading
Loading