diff --git a/ChangeLog.md b/ChangeLog.md index 517f501d6c4..3e1e5f8732b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,7 @@ Modelerfour version: 4.13.351 **New Features** +- Supports a function that is both LRO and paging #689 - We have added a `--credential-default-policy-type` flag. Its default value is `BearerTokenCredentialPolicy`, but it can also accept `AzureKeyCredentialPolicy`. The value passed in will be the default authentication policy in the client's config, so users using the generated library will use that auth policy unless they pass in a separate one through kwargs #686 diff --git a/autorest/codegen/models/lro_operation.py b/autorest/codegen/models/lro_operation.py index e09a7f3ee30..f7298fd3141 100644 --- a/autorest/codegen/models/lro_operation.py +++ b/autorest/codegen/models/lro_operation.py @@ -32,7 +32,7 @@ def __init__( responses: Optional[List[SchemaResponse]] = None, exceptions: Optional[List[SchemaResponse]] = None, want_description_docstring: bool = True, - want_tracing: bool = True, + want_tracing: bool = True ) -> None: super(LROOperation, self).__init__( yaml_data, diff --git a/autorest/codegen/models/lro_paging_operation.py b/autorest/codegen/models/lro_paging_operation.py new file mode 100644 index 00000000000..ae9996491cf --- /dev/null +++ b/autorest/codegen/models/lro_paging_operation.py @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +from typing import Any, Dict, List, Set, Optional +from .lro_operation import LROOperation +from .paging_operation import PagingOperation +from .imports import FileImport +from .schema_request import SchemaRequest +from .parameter import Parameter +from .schema_response import SchemaResponse + +class LROPagingOperation(PagingOperation, LROOperation): + def __init__( + self, + yaml_data: Dict[str, Any], + name: str, + description: str, + url: str, + method: str, + api_versions: Set[str], + requests: List[SchemaRequest], + summary: Optional[str] = None, + parameters: Optional[List[Parameter]] = None, + multiple_media_type_parameters: Optional[List[Parameter]] = None, + responses: Optional[List[SchemaResponse]] = None, + exceptions: Optional[List[SchemaResponse]] = None, + want_description_docstring: bool = True, + want_tracing: bool = True + ) -> None: + super(LROPagingOperation, self).__init__( + yaml_data, + name, + description, + url, + method, + api_versions, + requests, + summary, + parameters, + multiple_media_type_parameters, + responses, + exceptions, + want_description_docstring, + want_tracing, + override_success_response_to_200=True + ) + + def imports(self, code_model, async_mode: bool) -> FileImport: + lro_imports = LROOperation.imports(self, code_model, async_mode) + paging_imports = PagingOperation.imports(self, code_model, async_mode) + + file_import = lro_imports + file_import.merge(paging_imports) + return file_import + \ No newline at end of file diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 5ae527ea5c3..aebce7e0e17 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -107,7 +107,7 @@ def __init__( responses: Optional[List[SchemaResponse]] = None, exceptions: Optional[List[SchemaResponse]] = None, want_description_docstring: bool = True, - want_tracing: bool = True, + want_tracing: bool = True ) -> None: super().__init__(yaml_data) self.name = name diff --git a/autorest/codegen/models/operation_group.py b/autorest/codegen/models/operation_group.py index c74379a0bb4..1601c9c1a5d 100644 --- a/autorest/codegen/models/operation_group.py +++ b/autorest/codegen/models/operation_group.py @@ -10,6 +10,7 @@ from .operation import Operation from .lro_operation import LROOperation from .paging_operation import PagingOperation +from .lro_paging_operation import LROPagingOperation from .imports import FileImport, ImportType @@ -82,9 +83,13 @@ def from_yaml(cls, code_model, yaml_data: Dict[str, Any]) -> "OperationGroup": operations = [] api_versions: Set[str] = set() for operation_yaml in yaml_data["operations"]: - if operation_yaml.get("extensions", {}).get("x-ms-long-running-operation"): + lro_operation = operation_yaml.get("extensions", {}).get("x-ms-long-running-operation") + paging_operation = operation_yaml.get("extensions", {}).get("x-ms-pageable") + if lro_operation and paging_operation: + operation = LROPagingOperation.from_yaml(operation_yaml) + elif lro_operation: operation = LROOperation.from_yaml(operation_yaml) - elif operation_yaml.get("extensions", {}).get("x-ms-pageable"): + elif paging_operation: operation = PagingOperation.from_yaml(operation_yaml) else: operation = Operation.from_yaml(operation_yaml) diff --git a/autorest/codegen/models/paging_operation.py b/autorest/codegen/models/paging_operation.py index b64f9b2c2b2..3522783ef63 100644 --- a/autorest/codegen/models/paging_operation.py +++ b/autorest/codegen/models/paging_operation.py @@ -4,7 +4,7 @@ # license information. # -------------------------------------------------------------------------- import logging -from typing import cast, Dict, List, Any, Optional, Set +from typing import cast, Dict, List, Any, Optional, Set, Union from .operation import Operation from .parameter import Parameter @@ -31,6 +31,10 @@ def __init__( multiple_media_type_parameters: Optional[List[Parameter]] = None, responses: Optional[List[SchemaResponse]] = None, exceptions: Optional[List[SchemaResponse]] = None, + want_description_docstring: bool = True, + want_tracing: bool = True, + *, + override_success_response_to_200: bool = False ) -> None: super(PagingOperation, self).__init__( yaml_data, @@ -44,12 +48,15 @@ def __init__( parameters, multiple_media_type_parameters, responses, - exceptions + exceptions, + want_description_docstring, + want_tracing ) self._item_name: str = yaml_data["extensions"]["x-ms-pageable"].get("itemName") self._next_link_name: str = yaml_data["extensions"]["x-ms-pageable"].get("nextLinkName") self.operation_name: str = yaml_data["extensions"]["x-ms-pageable"].get("operationName") self.next_operation: Optional[Operation] = None + self.override_success_response_to_200 = override_success_response_to_200 def _get_response(self) -> SchemaResponse: response = self.responses[0] @@ -98,6 +105,14 @@ def has_optional_return_type(self) -> bool: """A paging will never have an optional return type, we will always return ItemPaged[return type]""" return False + @property + def success_status_code(self) -> List[Union[str, int]]: + """The list of all successfull status code. + """ + if self.override_success_response_to_200: + return [200] + return super(PagingOperation, self).success_status_code + def imports(self, code_model, async_mode: bool) -> FileImport: file_import = super(PagingOperation, self).imports(code_model, async_mode) diff --git a/autorest/codegen/templates/lro_operation.py.jinja2 b/autorest/codegen/templates/lro_operation.py.jinja2 index 02bc8a4a50f..9be6ac74e52 100644 --- a/autorest/codegen/templates/lro_operation.py.jinja2 +++ b/autorest/codegen/templates/lro_operation.py.jinja2 @@ -1,13 +1,10 @@ -{% import 'keywords.jinja2' as keywords with context %} {% import 'operation_tools.jinja2' as op_tools %} +{% import 'lro_operation_helper.jinja2' as helper %} {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %} -{% set async_prefix = "Async" if async_mode else "" %} -{% set poller = "AsyncLROPoller" if async_mode else "LROPoller" %} {% set operation_name = "begin_"+operation.python_name %} {% macro return_docstring(async_mode) %} :return: An instance of {{ "Async" if async_mode }}LROPoller that returns either {{ operation.responses[0].schema.docstring_text if operation.responses[0].has_body else "None"}} or the result of cls(response) :rtype: ~azure.core.polling.{{ "Async" if async_mode }}LROPoller[{{ operation.responses[0].schema.docstring_type if operation.responses[0].has_body else "None" }}]{% endmacro %} -{% macro param_documentation_string(parameter) %}:param {{ parameter.serialized_name }}: {{ parameter.description }}{% endmacro %} {% macro response_headers(response) %} response_headers = { {% for response_header in response.headers %} @@ -16,61 +13,21 @@ response_headers = { } {% endmacro %} {% macro operation_docstring(async_mode) %} -"""{{ operation.summary if operation.summary else operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }} -{% if operation.summary and operation.description %} - -{{ operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }} -{% endif %} - -{% if operation.deprecated -%} -.. warning:: - This method is deprecated - -{% endif -%} -{% for parameter in operation.parameters.method %} -{%- for doc_string in param_documentation_string(parameter).replace('\n', '\n ').split('\n') %} -{{ doc_string | wordwrap(width=95, break_long_words=False, wrapstring='\n ')}} -{% endfor %} -:type {{ parameter.serialized_name }}: {{ parameter.schema.docstring_type }} -{% endfor %} -:keyword callable cls: A custom type or function that will be passed the direct response -:keyword str continuation_token: A continuation token to restart a poller from a saved state. -:keyword polling: True for ARMPolling, False for no polling, or a - polling object for personal polling strategy -:paramtype polling: bool or ~azure.core.polling.{{ "Async" if async_mode else "" }}PollingMethod -:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. +{{ helper.operation_docstring_helper(operation, async_mode) }} {{ return_docstring(async_mode) }} :raises ~azure.core.exceptions.HttpResponseError: """{% endmacro %} -{% set lro_options = (", lro_options={'final-state-via': '"+ operation.lro_options['final-state-via'] + "'}") if operation.lro_options else "" %} {# actual template starts here #} {% if code_model.options['tracing'] %} {{ trace_decorator }} {% endif %} -{% set return_type_wrapper = "AsyncLROPoller" if async_mode else "LROPoller" %} +{% set return_type_wrapper = ["AsyncLROPoller" if async_mode else "LROPoller"] %} {{ op_tools.method_signature(operation, operation_name, async_mode=async_mode, coroutine=async_mode, return_type_wrapper=return_type_wrapper) }} {%- if not async_mode %} {{ op_tools.sync_return_type_annotation(operation, return_type_wrapper) }} {% endif %} {{ operation_docstring(async_mode) | indent }} - polling = kwargs.pop('polling', {{ "True" if code_model.options['azure_arm'] else "False" }}) # type: Union[bool, {{ "Async" if async_mode else "" }}PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[{{ op_tools.return_type_annotation(operation) }}] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] - if cont_token is None: - raw_result = {{ keywords.await }}self._{{ operation.name }}_initial( - {% for parameter in operation.parameters.method %} - {{ parameter.serialized_name }}={{ parameter.serialized_name }}, - {% endfor %} - cls=lambda x,y,z: x, - **kwargs - ) - - kwargs.pop('error_map', None) - kwargs.pop('content_type', None) +{{ helper.lro_operation(code_model, operation, async_mode) }} def get_long_running_output(pipeline_response): {% if operation.lro_response.has_headers %} @@ -86,20 +43,4 @@ response_headers = { return deserialized {% endif %} - {% if code_model.options['azure_arm'] %} - if polling is True: polling_method = {{ async_prefix }}ARMPolling(lro_delay{{ lro_options }}, **kwargs) - {% else %} - if polling is True: polling_method = {{ async_prefix }}LROBasePolling(lro_delay{{ lro_options }}, **kwargs) - {% endif %} - elif polling is False: polling_method = {{ async_prefix }}NoPolling() - else: polling_method = polling - if cont_token: - return {{ poller }}.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output - ) - else: - return {{ poller }}(self._client, raw_result, get_long_running_output, polling_method) -{{ operation_name }}.metadata = {'url': '{{ operation.url }}'} # type: ignore \ No newline at end of file +{{ helper.lro_operation_return(code_model, operation, async_mode) }} \ No newline at end of file diff --git a/autorest/codegen/templates/lro_operation_helper.jinja2 b/autorest/codegen/templates/lro_operation_helper.jinja2 new file mode 100644 index 00000000000..d7d3b087dd6 --- /dev/null +++ b/autorest/codegen/templates/lro_operation_helper.jinja2 @@ -0,0 +1,76 @@ +{% import 'operation_tools.jinja2' as op_tools %} + +{% macro param_documentation_string(parameter) %}:param {{ parameter.serialized_name }}: {{ parameter.description }}{% endmacro %} + +{% macro operation_docstring_helper(operation, async_mode) %} +"""{{ operation.summary if operation.summary else operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }} +{% if operation.summary and operation.description %} + +{{ operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }} +{% endif %} + +{% if operation.deprecated -%} +.. warning:: + This method is deprecated + +{% endif -%} +{% for parameter in operation.parameters.method %} +{%- for doc_string in param_documentation_string(parameter).replace('\n', '\n ').split('\n') %} +{{ doc_string | wordwrap(width=95, break_long_words=False, wrapstring='\n ')}} +{% endfor %} +:type {{ parameter.serialized_name }}: {{ parameter.schema.docstring_type }} +{% endfor %} +:keyword callable cls: A custom type or function that will be passed the direct response +:keyword str continuation_token: A continuation token to restart a poller from a saved state. +:keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy +:paramtype polling: bool or ~azure.core.polling.{{ "Async" if async_mode else "" }}PollingMethod +:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. +{%- endmacro -%} + + +{% macro lro_operation(code_model, operation, async_mode) %} +{% import 'keywords.jinja2' as keywords with context %} + polling = kwargs.pop('polling', {{ "True" if code_model.options['azure_arm'] else "False" }}) # type: Union[bool, {{ "Async" if async_mode else "" }}PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[{{ op_tools.return_type_annotation(operation) }}] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = {{ keywords.await }}self._{{ operation.name }}_initial( + {% for parameter in operation.parameters.method %} + {{ parameter.serialized_name }}={{ parameter.serialized_name }}, + {% endfor %} + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + {%- endmacro -%} + + {% macro lro_operation_return(code_model, operation, async_mode) %} + {% set async_prefix = "Async" if async_mode else "" %} + {% set lro_options = (", lro_options={'final-state-via': '"+ operation.lro_options['final-state-via'] + "'}") if operation.lro_options else "" %} + {% set poller = "AsyncLROPoller" if async_mode else "LROPoller" %} + {% set operation_name = "begin_"+operation.python_name %} + {% if code_model.options['azure_arm'] %} + if polling is True: polling_method = {{ async_prefix }}ARMPolling(lro_delay{{ lro_options }}, **kwargs) + {% else %} + if polling is True: polling_method = {{ async_prefix }}LROBasePolling(lro_delay{{ lro_options }}, **kwargs) + {% endif %} + elif polling is False: polling_method = {{ async_prefix }}NoPolling() + else: polling_method = polling + if cont_token: + return {{ poller }}.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return {{ poller }}(self._client, raw_result, get_long_running_output, polling_method) +{{ operation_name }}.metadata = {'url': '{{ operation.url }}'} # type: ignore +{%- endmacro -%} \ No newline at end of file diff --git a/autorest/codegen/templates/lro_paging_operation.py.jinja2 b/autorest/codegen/templates/lro_paging_operation.py.jinja2 new file mode 100644 index 00000000000..dd65f969181 --- /dev/null +++ b/autorest/codegen/templates/lro_paging_operation.py.jinja2 @@ -0,0 +1,38 @@ +{% import 'operation_tools.jinja2' as op_tools %} +{% import 'keywords.jinja2' as keywords with context %} +{% import 'lro_operation_helper.jinja2' as lro_helper %} +{% import 'paging_operation_helper.jinja2' as paging_helper %} +{% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %} +{% set operation_name = "begin_"+operation.python_name %} +{% macro return_docstring(async_mode) %} +:return: An instance of {{ "Async" if async_mode }}LROPoller that returns an iterator like instance of either {{ operation.responses[0].schema.docstring_text if operation.responses[0].has_body else "None"}} or the result of cls(response) +:rtype: ~azure.core.polling.{{ "Async" if async_mode }}LROPoller[~azure.core.{{ "async_" if async_mode else "" }}paging.{{ "Async" if async_mode }}ItemPaged[{{ operation.responses[0].schema.docstring_type if operation.responses[0].has_body else "None" }}]]{% endmacro %} +{% macro operation_docstring(async_mode) %} +{{ lro_helper.operation_docstring_helper(operation, async_mode) }} +{{ return_docstring(async_mode) }} +:raises ~azure.core.exceptions.HttpResponseError: +"""{% endmacro %} +{# actual template starts here #} +{% if code_model.options['tracing'] %} +{{ trace_decorator }} +{% endif %} +{% set return_type_wrapper = [("Async" if async_mode else "") ~ "LROPoller", ("Async" if async_mode else "") ~ "ItemPaged"] %} +{{ op_tools.method_signature(operation, operation_name, async_mode=async_mode, coroutine=async_mode, return_type_wrapper=return_type_wrapper) }} +{%- if not async_mode %} + {{ op_tools.sync_return_type_annotation(operation, return_type_wrapper) }} +{% endif %} + {{ operation_docstring(async_mode) | indent }} + {{ paging_helper.paging_operation(code_model, operation, async_mode) }} + +{{ lro_helper.lro_operation(code_model, operation, async_mode) }} + def get_long_running_output(pipeline_response): + {{ keywords.def }} internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return {{ keywords.await }}get_next(next_link) + + return {{ "Async" if async_mode }}ItemPaged( + internal_get_next, extract_data + ) +{{ lro_helper.lro_operation_return(code_model, operation, async_mode) }} \ No newline at end of file diff --git a/autorest/codegen/templates/metadata.json.jinja2 b/autorest/codegen/templates/metadata.json.jinja2 index b37209af2a6..7230e0dbef1 100644 --- a/autorest/codegen/templates/metadata.json.jinja2 +++ b/autorest/codegen/templates/metadata.json.jinja2 @@ -55,29 +55,39 @@ {% set operation_name = "begin_" + operation.name if is_lro(operation) else operation.name %} {{ operation_name | tojson }} : { "sync": { - {% set sync_return_type_wrapper = "LROPoller" if is_lro(operation) else ("ItemPaged" if is_paging(operation) else "") %} - "signature": {{ op_tools.method_signature(operation, operation_name, False, False, sync_return_type_wrapper) | tojson }}, - {% if is_lro(operation) %} + {% if is_lro(operation) and is_paging(operation) %} + {% from "lro_paging_operation.py.jinja2" import operation_docstring with context %} + {% set sync_return_type_wrapper = ["LROPoller", "ItemPaged"] %} + {% elif is_lro(operation) %} {% from "lro_operation.py.jinja2" import operation_docstring with context %} + {% set sync_return_type_wrapper = ["LROPoller"] %} {% elif is_paging(operation) %} {% from "paging_operation.py.jinja2" import operation_docstring with context %} + {% set sync_return_type_wrapper = ["ItemPaged"] %} {% else %} {% from "operation.py.jinja2" import operation_docstring with context %} + {% set sync_return_type_wrapper = "" %} {% endif %} + "signature": {{ op_tools.method_signature(operation, operation_name, False, False, sync_return_type_wrapper) | tojson }}, "doc": {{ operation_docstring(async_mode=False) | tojson }} }, "async": { {% set coroutine = False if is_paging(operation) else True %} - {% set async_return_type_wrapper = "AsyncLROPoller" if is_lro(operation) else ("AsyncItemPaged" if is_paging(operation) else "") %} - "signature": {{ op_tools.method_signature(operation, operation_name, True, coroutine, async_return_type_wrapper) | tojson }}, "coroutine": {{ coroutine | tojson }}, - {% if is_lro(operation) %} + {% if is_lro(operation) and is_paging(operation) %} + {% from "lro_paging_operation.py.jinja2" import operation_docstring with context %} + {% set async_return_type_wrapper = ["AsyncLROPoller", "AsyncItemPaged"] %} + {% elif is_lro(operation) %} {% from "lro_operation.py.jinja2" import operation_docstring with context %} + {% set async_return_type_wrapper = ["AsyncLROPoller"] %} {% elif is_paging(operation) %} {% from "paging_operation.py.jinja2" import operation_docstring with context %} + {% set async_return_type_wrapper = ["AsyncItemPaged"] %} {% else %} {% from "operation.py.jinja2" import operation_docstring with context %} + {% set async_return_type_wrapper = "" %} {% endif %} + "signature": {{ op_tools.method_signature(operation, operation_name, True, coroutine, async_return_type_wrapper) | tojson }}, "doc": {{ operation_docstring(async_mode=True) | tojson }} }, "call": {{ operation.parameters.method | map(attribute="serialized_name") | join(', ') | tojson }} diff --git a/autorest/codegen/templates/operation.py.jinja2 b/autorest/codegen/templates/operation.py.jinja2 index 5401629a54d..308f38e1257 100644 --- a/autorest/codegen/templates/operation.py.jinja2 +++ b/autorest/codegen/templates/operation.py.jinja2 @@ -57,7 +57,7 @@ {% if operation.want_description_docstring %} {{ operation_docstring(async_mode, return_type=return_type)|indent }} {% endif %} - cls = kwargs.pop('cls', None) # type: {{ op_tools.return_type_annotation(operation, "ClsType") }} + cls = kwargs.pop('cls', None) # type: {{ op_tools.return_type_annotation(operation, ["ClsType"]) }} {% if operation.deprecated %} warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning) {% endif %} diff --git a/autorest/codegen/templates/operation_tools.jinja2 b/autorest/codegen/templates/operation_tools.jinja2 index 80a413e8930..fa0d3d90a8a 100644 --- a/autorest/codegen/templates/operation_tools.jinja2 +++ b/autorest/codegen/templates/operation_tools.jinja2 @@ -2,11 +2,11 @@ {%- if return_type -%} {{ return_type }} {%- else -%} -{{ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ +{{ ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ (operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | join(', ')) ~ -("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ("]" if operation.has_optional_return_type else "") ~ ( "]" if return_type_wrapper else "") +("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ("]" if operation.has_optional_return_type else "") ~ ( ("]" * return_type_wrapper | count ) if return_type_wrapper else "") if operation.responses | selectattr('has_body') | first -else ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ "None" ~ ("]" if operation.has_optional_return_type else "") ~ ( "]" if return_type_wrapper else "") }}{%- endif -%}{% endmacro %} +else ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ "None" ~ ("]" if operation.has_optional_return_type else "") ~ ( ("]" * return_type_wrapper | count ) if return_type_wrapper else "") }}{%- endif -%}{% endmacro %} {# get async mypy typing #} {% macro async_return_type_annotation(operation, return_type_wrapper, return_type=None) %} {{ " -> " + return_type_annotation(operation, return_type_wrapper, return_type) }}{% endmacro %} diff --git a/autorest/codegen/templates/operations_container.py.jinja2 b/autorest/codegen/templates/operations_container.py.jinja2 index a7ad3c3b090..d1c06449d4e 100644 --- a/autorest/codegen/templates/operations_container.py.jinja2 +++ b/autorest/codegen/templates/operations_container.py.jinja2 @@ -35,7 +35,9 @@ class {{ operation_group.class_name }}{{ object_base_class }}: self._config = config {% for operation in operation_group.operations %} - {% if is_lro(operation) %} + {% if is_lro(operation) and is_paging(operation) %} + {% macro someop() %}{% include "lro_paging_operation.py.jinja2" %}{% endmacro %} + {% elif is_lro(operation) %} {% macro someop() %}{% include "lro_operation.py.jinja2" %}{% endmacro %} {% elif is_paging(operation) %} {% macro someop() %}{% include "paging_operation.py.jinja2" %}{% endmacro %} diff --git a/autorest/codegen/templates/operations_container_mixin.py.jinja2 b/autorest/codegen/templates/operations_container_mixin.py.jinja2 index d8ba24651ca..cff9347387c 100644 --- a/autorest/codegen/templates/operations_container_mixin.py.jinja2 +++ b/autorest/codegen/templates/operations_container_mixin.py.jinja2 @@ -9,7 +9,9 @@ class {{ operation_group.class_name }}{{ object_base_class }}: {% for operation in operation_group.operations %} - {% if is_lro(operation) %} + {% if is_lro(operation) and is_paging(operation) %} + {%- macro someop() %}{% include "lro_paging_operation.py.jinja2" %}{% endmacro %} + {% elif is_lro(operation) %} {%- macro someop() %}{% include "lro_operation.py.jinja2" %}{% endmacro %} {% elif is_paging(operation) %} {% macro someop() %}{% include "paging_operation.py.jinja2" %}{% endmacro %} diff --git a/autorest/codegen/templates/paging_operation.py.jinja2 b/autorest/codegen/templates/paging_operation.py.jinja2 index 1262310e43b..8514bfc2943 100644 --- a/autorest/codegen/templates/paging_operation.py.jinja2 +++ b/autorest/codegen/templates/paging_operation.py.jinja2 @@ -1,8 +1,7 @@ -{% import 'keywords.jinja2' as keywords with context %} {% import 'operation_tools.jinja2' as op_tools %} +{% import 'paging_operation_helper.jinja2' as helper %} {% set send_xml = "xml" if operation.parameters.has_body and "xml" in operation.request_content_type %} {% set request_as_xml = ", is_xml=True" if send_xml else "" %} -{% set stream_request_parameter = "stream=" ~ ("True" if operation.is_stream_response else "False") %} {% set item_paged = "AsyncItemPaged" if async_mode else "ItemPaged" %} {% macro return_docstring(async_mode) %} {% if operation.responses | selectattr('has_body') | first %} @@ -35,12 +34,11 @@ :raises: ~azure.core.exceptions.HttpResponseError """{% endmacro %} {% macro param_documentation_string(parameter) %}:param {{ parameter.serialized_name }}: {{ parameter.description }}{% endmacro %} -{% set next_link_str = "deserialized." + operation.next_link_name + " or None" if operation.next_link_name else "None" %} {# actual template starts here #} {% if code_model.options['tracing'] and operation.want_tracing %} @distributed_trace {% endif %} -{% set return_type_wrapper = "AsyncIterable" if async_mode else "Iterable" %} +{% set return_type_wrapper = ["AsyncIterable" if async_mode else "Iterable"] %} {{ op_tools.method_signature(operation, operation.python_name, async_mode=async_mode, coroutine=False, return_type_wrapper=return_type_wrapper) }} {%- if not async_mode %} {{ op_tools.sync_return_type_annotation(operation, return_type_wrapper) }} @@ -51,89 +49,7 @@ {% if operation.deprecated %} warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning) {% endif %} - cls = kwargs.pop('cls', None) # type: ClsType[{{ op_tools.return_type_annotation(operation) }}] - {{ op_tools.error_map(operation, code_model)|indent }} -{% if operation.parameters.grouped %} - {{ op_tools.grouped_parameters(operation)|indent }} -{%- endif -%} -{% if operation.parameters.is_flattened %} - {{ operation.parameters.build_flattened_object() }} -{% endif %} -{% if operation.parameters.constant|selectattr("implementation", "equalto", "Method") %} - {% for constant_parameter in operation.parameters.constant|selectattr("implementation", "equalto", "Method") %} - {{ constant_parameter.serialized_name }} = {{ constant_parameter.schema.constant_value }} - {% endfor %} -{% endif %} - - def prepare_request(next_link=None): - {{ op_tools.header_parameters(code_model, operation, async_mode)|indent(8) }} - if not next_link: - # Construct URL - url = self.{{ operation.python_name }}.metadata['url'] # type: ignore - {% if operation.parameters.path %} - path_format_arguments = { - {% for path_parameter in operation.parameters.path %} - '{{ path_parameter.rest_api_name }}': {{ operation.build_serialize_data_call(path_parameter, "url") }}, - {% endfor %} - } - url = self._client.format_url(url, **path_format_arguments) - {% endif %} - {{ op_tools.query_parameters(operation, async_mode)|indent(12) }} - {{ op_tools.body_parameters(operation)|indent(12) }} - else: -{% if operation.next_operation %} - url = '{{ operation.next_operation.url }}' - {% if operation.next_operation.parameters.path %} - path_format_arguments = { - {% for path_parameter in operation.next_operation.parameters.path %} - '{{ path_parameter.rest_api_name }}': {{ operation.next_operation.build_serialize_data_call(path_parameter, "url") }}, - {% endfor %} - } - url = self._client.format_url(url, **path_format_arguments) - {% endif %} - {{ op_tools.query_parameters(operation.next_operation, async_mode)|indent(12) }} - {{ op_tools.body_parameters(operation.next_operation)|indent(12) }} -{% else %} - url = next_link - query_parameters = {} # type: Dict[str, Any] - {% if operation.parameters.path and not code_model.base_url%} - path_format_arguments = { - {% for path_parameter in operation.parameters.path %} - '{{ path_parameter.rest_api_name }}': {{ operation.build_serialize_data_call(path_parameter, "url") }}, - {% endfor %} - } - url = self._client.format_url(url, **path_format_arguments) - {% endif %} - {{ op_tools.body_parameters(operation, http_verb="get")|indent(12) }} -{% endif %} - return request - - {{ keywords.def }} extract_data(pipeline_response): - {% set response = operation.responses[0] %} - deserialized = self._deserialize('{{ response.schema.serialization_type }}', pipeline_response) - list_of_elem = deserialized.{{ operation.item_name }} - if cls: - list_of_elem = cls(list_of_elem) - {% if async_mode %} - return {{ next_link_str }}, AsyncList(list_of_elem) - {% else %} - return {{ next_link_str }}, iter(list_of_elem) - {% endif %} - - {{ keywords.def }} get_next(next_link=None): - request = prepare_request(next_link) - - pipeline_response = {{ keywords.await }}self._client._pipeline.run(request, {{ stream_request_parameter }}, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in {{ operation.success_status_code|string() }}: - {% if operation.default_exception %} - error = self._deserialize({{ operation.default_exception }}, response) - {% endif %} - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response{{ ", model=error" if operation.default_exception else "" }}{{ ", error_format=ARMErrorFormat" if code_model.options['azure_arm'] else "" }}) - - return pipeline_response + {{ helper.paging_operation(code_model, operation, async_mode) }} return {{ item_paged }}( get_next, extract_data diff --git a/autorest/codegen/templates/paging_operation_helper.jinja2 b/autorest/codegen/templates/paging_operation_helper.jinja2 new file mode 100644 index 00000000000..d8fde5fccc7 --- /dev/null +++ b/autorest/codegen/templates/paging_operation_helper.jinja2 @@ -0,0 +1,89 @@ +{% import 'operation_tools.jinja2' as op_tools %} +{% macro paging_operation(code_model, operation, async_mode) %} +{% import 'keywords.jinja2' as keywords with context %} +{% set next_link_str = "deserialized." + operation.next_link_name + " or None" if operation.next_link_name else "None" %} +{% set stream_request_parameter = "stream=" ~ ("True" if operation.is_stream_response else "False") %} +cls = kwargs.pop('cls', None) # type: ClsType[{{ op_tools.return_type_annotation(operation) }}] + {{ op_tools.error_map(operation, code_model)|indent }} +{% if operation.parameters.grouped %} + {{ op_tools.grouped_parameters(operation)|indent }} +{%- endif -%} +{% if operation.parameters.is_flattened %} + {{ operation.parameters.build_flattened_object() }} +{% endif %} +{% if operation.parameters.constant|selectattr("implementation", "equalto", "Method") %} + {% for constant_parameter in operation.parameters.constant|selectattr("implementation", "equalto", "Method") %} + {{ constant_parameter.serialized_name }} = {{ constant_parameter.schema.constant_value }} + {% endfor %} +{% endif %} + + def prepare_request(next_link=None): + {{ op_tools.header_parameters(code_model, operation, async_mode)|indent(8) }} + if not next_link: + # Construct URL + url = self.{{ operation.python_name }}.metadata['url'] # type: ignore + {% if operation.parameters.path %} + path_format_arguments = { + {% for path_parameter in operation.parameters.path %} + '{{ path_parameter.rest_api_name }}': {{ operation.build_serialize_data_call(path_parameter, "url") }}, + {% endfor %} + } + url = self._client.format_url(url, **path_format_arguments) + {% endif %} + {{ op_tools.query_parameters(operation, async_mode)|indent(12) }} + {{ op_tools.body_parameters(operation)|indent(12) }} + else: +{% if operation.next_operation %} + url = '{{ operation.next_operation.url }}' + {% if operation.next_operation.parameters.path %} + path_format_arguments = { + {% for path_parameter in operation.next_operation.parameters.path %} + '{{ path_parameter.rest_api_name }}': {{ operation.next_operation.build_serialize_data_call(path_parameter, "url") }}, + {% endfor %} + } + url = self._client.format_url(url, **path_format_arguments) + {% endif %} + {{ op_tools.query_parameters(operation.next_operation, async_mode)|indent(12) }} + {{ op_tools.body_parameters(operation.next_operation)|indent(12) }} +{% else %} + url = next_link + query_parameters = {} # type: Dict[str, Any] + {% if operation.parameters.path and not code_model.base_url%} + path_format_arguments = { + {% for path_parameter in operation.parameters.path %} + '{{ path_parameter.rest_api_name }}': {{ operation.build_serialize_data_call(path_parameter, "url") }}, + {% endfor %} + } + url = self._client.format_url(url, **path_format_arguments) + {% endif %} + {{ op_tools.body_parameters(operation, http_verb="get")|indent(12) }} +{% endif %} + return request + + {{ keywords.def }} extract_data(pipeline_response): + {% set response = operation.responses[0] %} + deserialized = self._deserialize('{{ response.schema.serialization_type }}', pipeline_response) + list_of_elem = deserialized.{{ operation.item_name }} + if cls: + list_of_elem = cls(list_of_elem) + {% if async_mode %} + return {{ next_link_str }}, AsyncList(list_of_elem) + {% else %} + return {{ next_link_str }}, iter(list_of_elem) + {% endif %} + + {{ keywords.def }} get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = {{ keywords.await }}self._client._pipeline.run(request, {{ stream_request_parameter }}, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in {{ operation.success_status_code|string() }}: + {% if operation.default_exception %} + error = self._deserialize({{ operation.default_exception }}, response) + {% endif %} + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response{{ ", model=error" if operation.default_exception else "" }}{{ ", error_format=ARMErrorFormat" if code_model.options['azure_arm'] else "" }}) + + return pipeline_response +{%- endmacro -%} \ No newline at end of file diff --git a/package.json b/package.json index 494eea10582..fb227a60662 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "devDependencies": { "@autorest/autorest": "^3.0.0", - "@microsoft.azure/autorest.testserver": "2.10.42" + "@microsoft.azure/autorest.testserver": "^2.10.43" }, "files": [ "autorest/**/*.py", diff --git a/test/azure/AcceptanceTests/asynctests/test_paging.py b/test/azure/AcceptanceTests/asynctests/test_paging.py index d7433e65b8a..138cbda9063 100644 --- a/test/azure/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/AcceptanceTests/asynctests/test_paging.py @@ -212,18 +212,16 @@ async def test_custom_url_get_pages_partial_url_operation(custom_url_client): @pytest.mark.asyncio async def test_get_multiple_pages_lro(client): """LRO + Paging at the same time. - - Python decides to poll, but not follow paging. Check that at least you get read the first page. """ - from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling - polling = AsyncARMPolling(0, lro_options={'final-state-via': 'location'}) - # FIXME Location should be the default once 1.0.0b2 is out - - poller = await client.paging.begin_get_multiple_pages_lro(polling=polling) - page1 = await poller.result() - assert len(page1.values) == 1 - assert page1.values[0].properties.id == 1 - assert page1.next_link.endswith("paging/multiple/page/2") + poller = await client.paging.begin_get_multiple_pages_lro() + pager = await poller.result() + items = [] + async for item in pager: + items.append(item) + + assert len(items) == 10 + assert items[0].properties.id == 1 + assert items[1].properties.id == 2 @pytest.mark.asyncio async def test_item_name_with_xms_client_name(client): diff --git a/test/azure/AcceptanceTests/test_paging.py b/test/azure/AcceptanceTests/test_paging.py index 05f4709ba09..8904e8f9815 100644 --- a/test/azure/AcceptanceTests/test_paging.py +++ b/test/azure/AcceptanceTests/test_paging.py @@ -158,18 +158,16 @@ def test_custom_url_get_pages_partial_url_operation(custom_url_client): def test_get_multiple_pages_lro(client): """LRO + Paging at the same time. - - Python decides to poll, but not follow paging. Check that at least you get read the first page. """ - from azure.mgmt.core.polling.arm_polling import ARMPolling - polling = ARMPolling(0, lro_options={'final-state-via': 'location'}) - # FIXME Location should be the default once 1.0.0b2 is out - - poller = client.paging.begin_get_multiple_pages_lro(polling=polling) - page1 = poller.result() - assert len(page1.values) == 1 - assert page1.values[0].properties.id == 1 - assert page1.next_link.endswith("paging/multiple/page/2") + + poller = client.paging.begin_get_multiple_pages_lro() + pager = poller.result() + + items = list(pager) + + assert len(items) == 10 + assert items[0].properties.id == 1 + assert items[1].properties.id == 2 def test_item_name_with_xms_client_name(client): pages = client.paging.get_paging_model_with_item_name_with_xms_client_name() diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py index 0d0472bafab..406d495f370 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py @@ -1025,7 +1025,7 @@ async def begin_get_multiple_pages_lro( client_request_id: Optional[str] = None, paging_get_multiple_pages_lro_options: Optional["models.PagingGetMultiplePagesLroOptions"] = None, **kwargs - ) -> AsyncLROPoller["models.ProductResult"]: + ) -> AsyncLROPoller[AsyncItemPaged["models.ProductResult"]]: """A long-running paging operation that includes a nextLink that has 10 pages. :param client_request_id: @@ -1038,10 +1038,63 @@ async def begin_get_multiple_pages_lro( polling object for personal polling strategy :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either ProductResult or the result of cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~paging.models.ProductResult] + :return: An instance of AsyncLROPoller that returns an iterator like instance of either ProductResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~paging.models.ProductResult]] :raises ~azure.core.exceptions.HttpResponseError: """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.get_multiple_pages_lro.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + 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(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 + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResult"] lro_delay = kwargs.pop( @@ -1059,14 +1112,16 @@ async def begin_get_multiple_pages_lro( kwargs.pop('error_map', None) kwargs.pop('content_type', None) - def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ProductResult', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - return deserialized - + async def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return await get_next(next_link) + + return AsyncItemPaged( + internal_get_next, extract_data + ) if polling is True: polling_method = AsyncARMPolling(lro_delay, **kwargs) elif polling is False: polling_method = AsyncNoPolling() else: polling_method = polling diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py index f363600e3fa..7e006fe1041 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py @@ -1044,7 +1044,7 @@ def begin_get_multiple_pages_lro( paging_get_multiple_pages_lro_options=None, # type: Optional["models.PagingGetMultiplePagesLroOptions"] **kwargs # type: Any ): - # type: (...) -> LROPoller["models.ProductResult"] + # type: (...) -> LROPoller[ItemPaged["models.ProductResult"]] """A long-running paging operation that includes a nextLink that has 10 pages. :param client_request_id: @@ -1057,10 +1057,63 @@ def begin_get_multiple_pages_lro( polling object for personal polling strategy :paramtype polling: bool or ~azure.core.polling.PollingMethod :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. - :return: An instance of LROPoller that returns either ProductResult or the result of cls(response) - :rtype: ~azure.core.polling.LROPoller[~paging.models.ProductResult] + :return: An instance of LROPoller that returns an iterator like instance of either ProductResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~paging.models.ProductResult]] :raises ~azure.core.exceptions.HttpResponseError: """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.get_multiple_pages_lro.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + 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(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 + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResult"] lro_delay = kwargs.pop( @@ -1078,14 +1131,16 @@ def begin_get_multiple_pages_lro( kwargs.pop('error_map', None) kwargs.pop('content_type', None) - def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ProductResult', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - return deserialized - + def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return get_next(next_link) + + return ItemPaged( + internal_get_next, extract_data + ) if polling is True: polling_method = ARMPolling(lro_delay, **kwargs) elif polling is False: polling_method = NoPolling() else: polling_method = polling diff --git a/test/multiapi/AcceptanceTests/asynctests/multiapi_base.py b/test/multiapi/AcceptanceTests/asynctests/multiapi_base.py index 23fec594ef0..0efdfd54bf7 100644 --- a/test/multiapi/AcceptanceTests/asynctests/multiapi_base.py +++ b/test/multiapi/AcceptanceTests/asynctests/multiapi_base.py @@ -194,3 +194,17 @@ async def test_paging(self, default_client, namespace_models): assert len(items) == 1 assert isinstance(items[0], namespace_models.ModelThree) assert items[0].optional_property == "paged" + + @pytest.mark.parametrize('api_version', ["1.0.0"]) + @pytest.mark.asyncio + async def test_lro_and_paging(self, client, namespace_models): + poller = await client.begin_test_lro_and_paging() + pager = await poller.result() + + items = [] + async for item in pager: + items.append(item) + + assert len(items) == 1 + assert isinstance(items[0], namespace_models.Product) + assert items[0].id == 100 diff --git a/test/multiapi/AcceptanceTests/multiapi_base.py b/test/multiapi/AcceptanceTests/multiapi_base.py index 6b476951142..b880f4b782c 100644 --- a/test/multiapi/AcceptanceTests/multiapi_base.py +++ b/test/multiapi/AcceptanceTests/multiapi_base.py @@ -172,3 +172,14 @@ def test_paging(self, default_client, namespace_models): assert len(items) == 1 assert isinstance(items[0], namespace_models.ModelThree) assert items[0].optional_property == "paged" + + @pytest.mark.parametrize('api_version', ["1.0.0"]) + def test_lro_and_paging(self, client, namespace_models): + poller = client.begin_test_lro_and_paging() + pager = poller.result() + + items = list(pager) + + assert len(items) == 1 + assert isinstance(items[0], namespace_models.Product) + assert items[0].id == 100 diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_multiapi_service_client.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_multiapi_service_client.py index e02065d25c8..96022c805c5 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_multiapi_service_client.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_multiapi_service_client.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py index 66beebd67a2..fb8f59e3370 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py @@ -57,6 +57,40 @@ def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapi.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + def test_one( self, id, # type: int diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_multiapi_service_client_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_multiapi_service_client_async.py index dfa13e5b3c0..a80c613b9a2 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_multiapi_service_client_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_multiapi_service_client_async.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py index f26d76ec639..dd694ae2f57 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py @@ -53,6 +53,40 @@ async def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return await mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapi.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from ..v1.aio.operations_async import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + async def test_one( self, id: int, diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json index adcfb2ca2b6..a987e14e2f6 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json @@ -43,8 +43,8 @@ "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" @@ -55,8 +55,8 @@ "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "product" @@ -67,13 +67,37 @@ "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~multiapi.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "async": { - "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~multiapi.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "call": "product" + }, + "_test_lro_and_paging_initial" : { + "sync": { + "signature": "def _test_lro_and_paging_initial(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapi.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "async": { + "coroutine": true, + "signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e \"models.PagingResult\":\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapi.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" + }, + "begin_test_lro_and_paging" : { + "sync": { + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapi.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "async": { + "coroutine": false, + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"models.PagingResult\"]]:\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapi.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" } }, - "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}", - "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"], \"azure.core.paging\": [\"ItemPaged\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Iterable\", \"Optional\", \"TypeVar\", \"Union\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"], \"azure.core.async_paging\": [\"AsyncItemPaged\", \"AsyncList\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"AsyncIterable\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" } \ No newline at end of file diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py index eb0e6ff06c0..5f6391c45f4 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -5,9 +5,10 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union import warnings +from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest @@ -173,3 +174,167 @@ def get_long_running_output(pipeline_response): else: return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + async def _test_lro_and_paging_initial( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> "models.PagingResult": + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + async def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapi.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + async def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return await get_next(next_link) + + return AsyncItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = AsyncLROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/__init__.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/__init__.py index cfec3d6aba5..2a41a9b7475 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/__init__.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/__init__.py @@ -8,12 +8,18 @@ try: from ._models_py3 import Error + from ._models_py3 import PagingResult from ._models_py3 import Product + from ._models_py3 import TestLroAndPagingOptions except (SyntaxError, ImportError): from ._models import Error # type: ignore + from ._models import PagingResult # type: ignore from ._models import Product # type: ignore + from ._models import TestLroAndPagingOptions # type: ignore __all__ = [ 'Error', + 'PagingResult', 'Product', + 'TestLroAndPagingOptions', ] diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models.py index e61e5c0be95..a305ce8e24b 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models.py @@ -33,6 +33,29 @@ def __init__( self.message = kwargs.get('message', None) +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapi.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = kwargs.get('values', None) + self.next_link = kwargs.get('next_link', None) + + class Product(msrest.serialization.Model): """Product. @@ -50,3 +73,27 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = kwargs.get('id', None) + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = kwargs.get('maxresults', None) + self.timeout = kwargs.get('timeout', 30) diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models_py3.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models_py3.py index 8de2526c72c..8471e3aa0e5 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models_py3.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/models/_models_py3.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Optional +from typing import List, Optional from azure.core.exceptions import HttpResponseError import msrest.serialization @@ -38,6 +38,32 @@ def __init__( self.message = message +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapi.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + values: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = values + self.next_link = next_link + + class Product(msrest.serialization.Model): """Product. @@ -57,3 +83,30 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = id + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + *, + maxresults: Optional[int] = None, + timeout: Optional[int] = 30, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = maxresults + self.timeout = timeout 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 312744edd76..93aa5d28f2b 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 @@ -9,6 +9,7 @@ import warnings from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpRequest, HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -18,7 +19,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -180,3 +181,169 @@ def get_long_running_output(pipeline_response): else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + def _test_lro_and_paging_initial( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.PagingResult" + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> LROPoller[ItemPaged["models.PagingResult"]] + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapi.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapi.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return get_next(next_link) + + return ItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = LROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v2/_metadata.json b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v2/_metadata.json index 78688bf9c04..38474588ff9 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v2/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v2/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapi.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapi.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/_metadata.json b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/_metadata.json index c1d220aea76..2268cd7d9cc 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v3/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.paging.ItemPaged[~multiapi.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "coroutine": false, + "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.async_paging.AsyncItemPaged[~multiapi.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_multiapi_service_client.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_multiapi_service_client.py index 90842b4af3f..2b3740d27ba 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_multiapi_service_client.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_multiapi_service_client.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_operations_mixin.py index 28db425f2fb..e9743228dd5 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/_operations_mixin.py @@ -57,6 +57,40 @@ def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + def test_one( self, id, # type: int diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_multiapi_service_client_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_multiapi_service_client_async.py index b6db4fd613d..70dc41daa5d 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_multiapi_service_client_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_multiapi_service_client_async.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_operations_mixin_async.py index 9a940077b7e..fb9098e4e36 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/aio/_operations_mixin_async.py @@ -53,6 +53,40 @@ async def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return await mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from ..v1.aio.operations_async import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + async def test_one( self, id: int, diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/_metadata.json index 7ec5283b5ad..a53f3b8b81c 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/_metadata.json @@ -43,8 +43,8 @@ "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" @@ -55,8 +55,8 @@ "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapicredentialdefaultpolicy.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapicredentialdefaultpolicy.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "product" @@ -67,13 +67,37 @@ "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapicredentialdefaultpolicy.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~multiapicredentialdefaultpolicy.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "async": { - "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapicredentialdefaultpolicy.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~multiapicredentialdefaultpolicy.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "call": "product" + }, + "_test_lro_and_paging_initial" : { + "sync": { + "signature": "def _test_lro_and_paging_initial(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "async": { + "coroutine": true, + "signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e \"models.PagingResult\":\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" + }, + "begin_test_lro_and_paging" : { + "sync": { + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "async": { + "coroutine": false, + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"models.PagingResult\"]]:\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" } }, - "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}", - "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"], \"azure.core.paging\": [\"ItemPaged\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Iterable\", \"Optional\", \"TypeVar\", \"Union\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"], \"azure.core.async_paging\": [\"AsyncItemPaged\", \"AsyncList\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"AsyncIterable\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" } \ No newline at end of file diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations_async/_multiapi_service_client_operations_async.py index 6d4f48a0695..8c48474fc4f 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -5,9 +5,10 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union import warnings +from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest @@ -173,3 +174,167 @@ def get_long_running_output(pipeline_response): else: return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + async def _test_lro_and_paging_initial( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> "models.PagingResult": + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + async def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + async def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return await get_next(next_link) + + return AsyncItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = AsyncLROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/__init__.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/__init__.py index cfec3d6aba5..2a41a9b7475 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/__init__.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/__init__.py @@ -8,12 +8,18 @@ try: from ._models_py3 import Error + from ._models_py3 import PagingResult from ._models_py3 import Product + from ._models_py3 import TestLroAndPagingOptions except (SyntaxError, ImportError): from ._models import Error # type: ignore + from ._models import PagingResult # type: ignore from ._models import Product # type: ignore + from ._models import TestLroAndPagingOptions # type: ignore __all__ = [ 'Error', + 'PagingResult', 'Product', + 'TestLroAndPagingOptions', ] diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models.py index e61e5c0be95..140f130ef19 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models.py @@ -33,6 +33,29 @@ def __init__( self.message = kwargs.get('message', None) +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapicredentialdefaultpolicy.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = kwargs.get('values', None) + self.next_link = kwargs.get('next_link', None) + + class Product(msrest.serialization.Model): """Product. @@ -50,3 +73,27 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = kwargs.get('id', None) + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = kwargs.get('maxresults', None) + self.timeout = kwargs.get('timeout', 30) diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models_py3.py b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models_py3.py index 8de2526c72c..9bcbbe5cce2 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models_py3.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v1/models/_models_py3.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Optional +from typing import List, Optional from azure.core.exceptions import HttpResponseError import msrest.serialization @@ -38,6 +38,32 @@ def __init__( self.message = message +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapicredentialdefaultpolicy.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + values: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = values + self.next_link = next_link + + class Product(msrest.serialization.Model): """Product. @@ -57,3 +83,30 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = id + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + *, + maxresults: Optional[int] = None, + timeout: Optional[int] = 30, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = maxresults + self.timeout = timeout 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 ee6b72ef7b3..8a9b401b8e7 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 @@ -9,6 +9,7 @@ import warnings from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpRequest, HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -18,7 +19,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -180,3 +181,169 @@ def get_long_running_output(pipeline_response): else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + def _test_lro_and_paging_initial( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.PagingResult" + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> LROPoller[ItemPaged["models.PagingResult"]] + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapicredentialdefaultpolicy.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapicredentialdefaultpolicy.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return get_next(next_link) + + return ItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = LROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v2/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v2/_metadata.json index bb83f93dcbf..d41499ddda0 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v2/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v2/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapicredentialdefaultpolicy.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/_metadata.json index 7ecd0c15b03..7e6e943eb24 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiCredentialDefaultPolicy/multiapicredentialdefaultpolicy/v3/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.paging.ItemPaged[~multiapicredentialdefaultpolicy.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "coroutine": false, + "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.async_paging.AsyncItemPaged[~multiapicredentialdefaultpolicy.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_multiapi_service_client.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_multiapi_service_client.py index e5fe9f1f594..128bbad18c7 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_multiapi_service_client.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_multiapi_service_client.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py index 9d92eb3e422..5e9b1875b60 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py @@ -57,6 +57,40 @@ def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapinoasync.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + def test_one( self, id, # type: int diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json index b2162b9ea04..d35b09d12a7 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json @@ -43,8 +43,8 @@ "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" @@ -55,8 +55,8 @@ "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "product" @@ -67,13 +67,37 @@ "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~multiapinoasync.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "async": { - "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~multiapinoasync.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "call": "product" + }, + "_test_lro_and_paging_initial" : { + "sync": { + "signature": "def _test_lro_and_paging_initial(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "async": { + "coroutine": true, + "signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e \"models.PagingResult\":\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" + }, + "begin_test_lro_and_paging" : { + "sync": { + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapinoasync.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "async": { + "coroutine": false, + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"models.PagingResult\"]]:\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapinoasync.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" } }, - "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}", - "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"], \"azure.core.paging\": [\"ItemPaged\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Iterable\", \"Optional\", \"TypeVar\", \"Union\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"], \"azure.core.async_paging\": [\"AsyncItemPaged\", \"AsyncList\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"AsyncIterable\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" } \ No newline at end of file diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/__init__.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/__init__.py index cfec3d6aba5..2a41a9b7475 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/__init__.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/__init__.py @@ -8,12 +8,18 @@ try: from ._models_py3 import Error + from ._models_py3 import PagingResult from ._models_py3 import Product + from ._models_py3 import TestLroAndPagingOptions except (SyntaxError, ImportError): from ._models import Error # type: ignore + from ._models import PagingResult # type: ignore from ._models import Product # type: ignore + from ._models import TestLroAndPagingOptions # type: ignore __all__ = [ 'Error', + 'PagingResult', 'Product', + 'TestLroAndPagingOptions', ] diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models.py index e61e5c0be95..904d3eb3a08 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models.py @@ -33,6 +33,29 @@ def __init__( self.message = kwargs.get('message', None) +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapinoasync.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = kwargs.get('values', None) + self.next_link = kwargs.get('next_link', None) + + class Product(msrest.serialization.Model): """Product. @@ -50,3 +73,27 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = kwargs.get('id', None) + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = kwargs.get('maxresults', None) + self.timeout = kwargs.get('timeout', 30) diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models_py3.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models_py3.py index 8de2526c72c..8a9ae2edb2a 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models_py3.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/models/_models_py3.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Optional +from typing import List, Optional from azure.core.exceptions import HttpResponseError import msrest.serialization @@ -38,6 +38,32 @@ def __init__( self.message = message +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapinoasync.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + values: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = values + self.next_link = next_link + + class Product(msrest.serialization.Model): """Product. @@ -57,3 +83,30 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = id + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + *, + maxresults: Optional[int] = None, + timeout: Optional[int] = 30, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = maxresults + self.timeout = timeout 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 f68b937190b..9b12a347ea1 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 @@ -9,6 +9,7 @@ import warnings from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpRequest, HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -18,7 +19,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -180,3 +181,169 @@ def get_long_running_output(pipeline_response): else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + def _test_lro_and_paging_initial( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.PagingResult" + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> LROPoller[ItemPaged["models.PagingResult"]] + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapinoasync.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapinoasync.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return get_next(next_link) + + return ItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = LROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v2/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v2/_metadata.json index 257c251a767..bbe4e9a7dcc 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v2/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v2/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapinoasync.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapinoasync.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/_metadata.json index bbc72153d7b..2122f1e79e7 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v3/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.paging.ItemPaged[~multiapinoasync.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "coroutine": false, + "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.async_paging.AsyncItemPaged[~multiapinoasync.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_multiapi_service_client.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_multiapi_service_client.py index b83b820552c..d0e33cfa9cd 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_multiapi_service_client.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_multiapi_service_client.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py index 800b4dbf8aa..4a988d71ec3 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py @@ -57,6 +57,40 @@ def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + def test_one( self, id, # type: int diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_multiapi_service_client_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_multiapi_service_client_async.py index ce5870e503a..e15b5a30a29 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_multiapi_service_client_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_multiapi_service_client_async.py @@ -50,6 +50,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient _PROFILE_TAG: { None: DEFAULT_API_VERSION, 'begin_test_lro': '1.0.0', + 'begin_test_lro_and_paging': '1.0.0', 'test_one': '2.0.0', }}, _PROFILE_TAG + " latest" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py index f3f102ff0da..6e4a0cb7b38 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py @@ -53,6 +53,40 @@ async def begin_test_lro( mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) return await mixin_instance.begin_test_lro(product, **kwargs) + def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + api_version = self._get_api_version('begin_test_lro_and_paging') + if api_version == '1.0.0': + from ..v1.aio.operations_async import MultiapiServiceClientOperationsMixin as OperationClass + else: + raise NotImplementedError("APIVersion {} is not available".format(api_version)) + mixin_instance = OperationClass() + mixin_instance._client = self._client + mixin_instance._config = self._config + mixin_instance._serialize = Serializer(self._models_dict(api_version)) + mixin_instance._deserialize = Deserializer(self._models_dict(api_version)) + return mixin_instance.begin_test_lro_and_paging(client_request_id, test_lro_and_paging_options, **kwargs) + async def test_one( self, id: int, diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json index 326632aa45c..1a4ed7cbd49 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json @@ -43,8 +43,8 @@ "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n", "doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" @@ -55,8 +55,8 @@ "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "product" @@ -67,13 +67,37 @@ "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~multiapiwithsubmodule.submodule.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "async": { - "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "coroutine": true, + "signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n", "doc": "\"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~multiapiwithsubmodule.submodule.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" }, "call": "product" + }, + "_test_lro_and_paging_initial" : { + "sync": { + "signature": "def _test_lro_and_paging_initial(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "async": { + "coroutine": true, + "signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e \"models.PagingResult\":\n", + "doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" + }, + "begin_test_lro_and_paging" : { + "sync": { + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id=None, # type: Optional[str]\n test_lro_and_paging_options=None, # type: Optional[\"models.TestLroAndPagingOptions\"]\n **kwargs # type: Any\n):\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.PollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "async": { + "coroutine": false, + "signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"models.PagingResult\"]]:\n", + "doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: True for ARMPolling, False for no polling, or a\n polling object for personal polling strategy\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\"" + }, + "call": "client_request_id, test_lro_and_paging_options" } }, - "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}", - "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"HttpRequest\", \"HttpResponse\"], \"azure.core.polling\": [\"LROPoller\", \"NoPolling\", \"PollingMethod\"], \"azure.core.polling.base_polling\": [\"LROBasePolling\"], \"azure.core.paging\": [\"ItemPaged\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Callable\", \"Dict\", \"Generic\", \"Iterable\", \"Optional\", \"TypeVar\", \"Union\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.exceptions\": [\"HttpResponseError\", \"ResourceExistsError\", \"ResourceNotFoundError\", \"map_error\"], \"azure.core.pipeline\": [\"PipelineResponse\"], \"azure.core.pipeline.transport\": [\"AsyncHttpResponse\", \"HttpRequest\"], \"azure.core.polling\": [\"AsyncLROPoller\", \"AsyncNoPolling\", \"AsyncPollingMethod\"], \"azure.core.polling.async_base_polling\": [\"AsyncLROBasePolling\"], \"azure.core.async_paging\": [\"AsyncItemPaged\", \"AsyncList\"]}, \"stdlib\": {\"warnings\": [null]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"AsyncIterable\", \"Callable\", \"Dict\", \"Generic\", \"Optional\", \"TypeVar\", \"Union\"]}}}" } \ No newline at end of file diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py index 8bf3b6c04ab..a5c39038da5 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -5,9 +5,10 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union import warnings +from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest @@ -173,3 +174,167 @@ def get_long_running_output(pipeline_response): else: return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + async def _test_lro_and_paging_initial( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> "models.PagingResult": + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + async def begin_test_lro_and_paging( + self, + client_request_id: Optional[str] = None, + test_lro_and_paging_options: Optional["models.TestLroAndPagingOptions"] = None, + **kwargs + ) -> AsyncLROPoller[AsyncItemPaged["models.PagingResult"]]: + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + async def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return await get_next(next_link) + + return AsyncItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = AsyncLROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/__init__.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/__init__.py index cfec3d6aba5..2a41a9b7475 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/__init__.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/__init__.py @@ -8,12 +8,18 @@ try: from ._models_py3 import Error + from ._models_py3 import PagingResult from ._models_py3 import Product + from ._models_py3 import TestLroAndPagingOptions except (SyntaxError, ImportError): from ._models import Error # type: ignore + from ._models import PagingResult # type: ignore from ._models import Product # type: ignore + from ._models import TestLroAndPagingOptions # type: ignore __all__ = [ 'Error', + 'PagingResult', 'Product', + 'TestLroAndPagingOptions', ] diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models.py index e61e5c0be95..4ae70117b8c 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models.py @@ -33,6 +33,29 @@ def __init__( self.message = kwargs.get('message', None) +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapiwithsubmodule.submodule.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = kwargs.get('values', None) + self.next_link = kwargs.get('next_link', None) + + class Product(msrest.serialization.Model): """Product. @@ -50,3 +73,27 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = kwargs.get('id', None) + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = kwargs.get('maxresults', None) + self.timeout = kwargs.get('timeout', 30) diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models_py3.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models_py3.py index 8de2526c72c..cf0a3dc034a 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models_py3.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/models/_models_py3.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Optional +from typing import List, Optional from azure.core.exceptions import HttpResponseError import msrest.serialization @@ -38,6 +38,32 @@ def __init__( self.message = message +class PagingResult(msrest.serialization.Model): + """PagingResult. + + :param values: + :type values: list[~multiapiwithsubmodule.submodule.v1.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'values': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + values: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(PagingResult, self).__init__(**kwargs) + self.values = values + self.next_link = next_link + + class Product(msrest.serialization.Model): """Product. @@ -57,3 +83,30 @@ def __init__( ): super(Product, self).__init__(**kwargs) self.id = id + + +class TestLroAndPagingOptions(msrest.serialization.Model): + """Parameter group. + + :param maxresults: Sets the maximum number of items to return in the response. + :type maxresults: int + :param timeout: Sets the maximum time that the server can spend processing the request, in + seconds. The default is 30 seconds. + :type timeout: int + """ + + _attribute_map = { + 'maxresults': {'key': 'maxresults', 'type': 'int'}, + 'timeout': {'key': 'timeout', 'type': 'int'}, + } + + def __init__( + self, + *, + maxresults: Optional[int] = None, + timeout: Optional[int] = 30, + **kwargs + ): + super(TestLroAndPagingOptions, self).__init__(**kwargs) + self.maxresults = maxresults + self.timeout = timeout 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 6db34d42c88..317bb2b479e 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 @@ -9,6 +9,7 @@ import warnings from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpRequest, HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -18,7 +19,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -180,3 +181,169 @@ def get_long_running_output(pipeline_response): else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_test_lro.metadata = {'url': '/multiapi/lro'} # type: ignore + + def _test_lro_and_paging_initial( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.PagingResult" + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + # Construct URL + url = self._test_lro_and_paging_initial.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = self._client._pipeline.run(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) + + deserialized = self._deserialize('PagingResult', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + _test_lro_and_paging_initial.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore + + def begin_test_lro_and_paging( + self, + client_request_id=None, # type: Optional[str] + test_lro_and_paging_options=None, # type: Optional["models.TestLroAndPagingOptions"] + **kwargs # type: Any + ): + # type: (...) -> LROPoller[ItemPaged["models.PagingResult"]] + """A long-running paging operation that includes a nextLink that has 10 pages. + + :param client_request_id: + :type client_request_id: str + :param test_lro_and_paging_options: Parameter group. + :type test_lro_and_paging_options: ~multiapiwithsubmodule.submodule.v1.models.TestLroAndPagingOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + :return: An instance of LROPoller that returns an iterator like instance of either PagingResult or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~multiapiwithsubmodule.submodule.v1.models.PagingResult]] + :raises ~azure.core.exceptions.HttpResponseError: + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + _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 + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if client_request_id is not None: + header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str') + if _maxresults is not None: + header_parameters['maxresults'] = self._serialize.header("maxresults", _maxresults, 'int') + if _timeout is not None: + header_parameters['timeout'] = self._serialize.header("timeout", _timeout, 'int') + header_parameters['Accept'] = 'application/json' + + if not next_link: + # Construct URL + url = self.test_lro_and_paging.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PagingResult', 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(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 + + polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["models.PagingResult"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._test_lro_and_paging_initial( + client_request_id=client_request_id, + test_lro_and_paging_options=test_lro_and_paging_options, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + def get_long_running_output(pipeline_response): + def internal_get_next(next_link=None): + if next_link is None: + return pipeline_response + else: + return get_next(next_link) + + return ItemPaged( + internal_get_next, extract_data + ) + if polling is True: polling_method = LROBasePolling(lro_delay, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_test_lro_and_paging.metadata = {'url': '/multiapi/lroAndPaging'} # type: ignore diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v2/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v2/_metadata.json index 507b3ccc827..a4719d0fe3a 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v2/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v2/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "coroutine": true, + "signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n", "doc": "\"\"\"TestOne should be in an SecondVersionOperationsMixin. Returns ModelTwo.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: ModelTwo, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v2.models.ModelTwo\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": "id, message" diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/_metadata.json index c5d90dc7cd1..717955b0905 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v3/_metadata.json @@ -44,8 +44,8 @@ "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.paging.ItemPaged[~multiapiwithsubmodule.submodule.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "async": { - "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "coroutine": false, + "signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n", "doc": "\"\"\"Returns ModelThree with optionalProperty \u0027paged\u0027.\n\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: An iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.async_paging.AsyncItemPaged[~multiapiwithsubmodule.submodule.v3.models.PagingResult]\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"" }, "call": ""