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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions autorest/codegen/templates/metadata.json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,16 @@
},
"operation_mixins": {
{% for operation in mixin_operations %}
{{ operation.name | tojson }} : {
{% set operation_name = "begin_" + operation.name if is_lro(operation) else operation.name %}
{{ operation_name | tojson }} : {
"sync": {
{% set sync_operation_name = "begin_" + operation.name if is_lro(operation) else operation.name %}
{% set sync_return_type_wrapper = "LROPoller" if is_lro(operation) else ("ItemPaged" if is_paging(operation) else "") %}
"operation_name": {{ sync_operation_name | tojson }},
"signature": {{ op_tools.method_signature(operation, sync_operation_name, False, False, sync_return_type_wrapper) | tojson }}
"signature": {{ op_tools.method_signature(operation, operation_name, False, False, sync_return_type_wrapper) | tojson }}
},
"async": {
{% set coroutine = False if is_paging(operation) else True %}
{% set async_return_type_wrapper = "AsyncItemPaged" if is_paging(operation) else "" %}
"operation_name": {{ operation.name | tojson }},
"signature": {{ op_tools.method_signature(operation, operation.name, True, coroutine, async_return_type_wrapper) | tojson }},
{% 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 }}
},
"doc": {{ op_tools.operation_docstring(operation) | tojson }},
Expand Down
6 changes: 2 additions & 4 deletions autorest/multiapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def there_is_a_rt_that_contains_api_version(rt_dict, api_version):
# Operations at client level
versioned_dict.update(
{
operation_metadata[sync_or_async]["operation_name"]: operation_metadata[sync_or_async]["available_apis"]
for operation_metadata in mixin_operations.values()
operation_name: operation_metadata[sync_or_async]["available_apis"]
for operation_name, operation_metadata in mixin_operations.items()
}
)
for operation, api_versions_list in versioned_dict.items():
Expand Down Expand Up @@ -181,13 +181,11 @@ def _build_operation_mixin_meta(self, paths_to_versions: List[Path]) -> Dict[str
mixin_operations.setdefault(func_name, {}).setdefault('async', {})
mixin_operations[func_name]['sync'].update({
"signature": func['sync']['signature'],
"operation_name": func['sync']['operation_name'],
"doc": func['doc'],
"call": func['call']
})
mixin_operations[func_name]['async'].update({
"signature": func['async']['signature'],
"operation_name": func['async']['operation_name'],
"coroutine": func['async']['coroutine'],
"doc": func['doc'],
"call": func['call']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ from msrest import Serializer, Deserializer


class {{ client_name }}OperationsMixin(object):
{% for _, metadata_sync_and_async in mixin_operations|dictsort %}
{% for operation_name, metadata_sync_and_async in mixin_operations|dictsort %}

{% set metadata = metadata_sync_and_async['async'] if async_mode else metadata_sync_and_async['sync'] %}
{{ metadata['signature'] | indent }} {{ metadata['doc'] | indent(8) }}
api_version = self._get_api_version('{{ metadata['operation_name'] }}')
api_version = self._get_api_version('{{ operation_name }}')
{% for api in metadata['available_apis']|sort %}
{% set if_statement = "if" if loop.first else "elif" %}
{{ if_statement }} api_version == '{{ mod_to_api_version[api] }}':
Expand All @@ -33,5 +33,5 @@ class {{ client_name }}OperationsMixin(object):
mixin_instance._config = self._config
mixin_instance._serialize = Serializer(self._models_dict(api_version))
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return {{ "await " if async_mode and metadata['coroutine'] else "" }}mixin_instance.{{ metadata['operation_name'] }}({{ metadata['call'] }}{{ ", **kwargs" if metadata['call'] else "**kwargs" }})
return {{ "await " if async_mode and metadata['coroutine'] else "" }}mixin_instance.{{ operation_name }}({{ metadata['call'] }}{{ ", **kwargs" if metadata['call'] else "**kwargs" }})
{% endfor %}
3 changes: 2 additions & 1 deletion test/multiapi/AcceptanceTests/asynctests/multiapi_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ async def test_version_two_operation_group_two(self, client):
@pytest.mark.parametrize('api_version', ["1.0.0"])
@pytest.mark.asyncio
async def test_lro(self, client, namespace_models):
product = await client.test_lro(namespace_models.Product())
poller = await client.begin_test_lro(namespace_models.Product())
product = await poller.result()
assert product.id == 100

@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'test_lro': '1.0.0',
'begin_test_lro': '1.0.0',
'test_one': '2.0.0',
}},
_PROFILE_TAG + " latest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

class MultiapiServiceClientOperationsMixin(object):

async def test_lro(
async def begin_test_lro(
self,
product: Optional["models.Product"] = None,
**kwargs
) -> "models.Product":
) -> AsyncLROPoller["models.Product"]:
"""Put in whatever shape of Product you want, will return a Product with id equal to 100.

:param product: Product to put.
Expand All @@ -34,7 +34,7 @@ async def test_lro(
:rtype: ~multiapi.v1.models.Product or None
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('test_lro')
api_version = self._get_api_version('begin_test_lro')
if api_version == '1.0.0':
from ..v1.aio.operations_async import MultiapiServiceClientOperationsMixin as OperationClass
else:
Expand All @@ -44,7 +44,7 @@ async def test_lro(
mixin_instance._config = self._config
mixin_instance._serialize = Serializer(self._models_dict(api_version))
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return await mixin_instance.test_lro(product, **kwargs)
return await mixin_instance.begin_test_lro(product, **kwargs)

async def test_one(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n",
"coroutine": true
},
Expand All @@ -50,25 +48,21 @@
},
"_test_lro_initial" : {
"sync": {
"operation_name": "_test_lro_initial",
"signature": "def _test_lro_initial(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "_test_lro_initial",
"signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"coroutine": true
},
"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"
},
"test_lro" : {
"begin_test_lro" : {
"sync": {
"operation_name": "begin_test_lro",
"signature": "def begin_test_lro(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_lro",
"signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n",
"coroutine": true
},
"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:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n",
"coroutine": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_paging" : {
"sync": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n",
"coroutine": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n",
"coroutine": true
},
Expand All @@ -50,25 +48,21 @@
},
"_test_lro_initial" : {
"sync": {
"operation_name": "_test_lro_initial",
"signature": "def _test_lro_initial(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "_test_lro_initial",
"signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"coroutine": true
},
"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"
},
"test_lro" : {
"begin_test_lro" : {
"sync": {
"operation_name": "begin_test_lro",
"signature": "def begin_test_lro(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_lro",
"signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n",
"coroutine": true
},
"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:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n",
"coroutine": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_paging" : {
"sync": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n",
"coroutine": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'test_lro': '1.0.0',
'begin_test_lro': '1.0.0',
'test_one': '2.0.0',
}},
_PROFILE_TAG + " latest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

class MultiapiServiceClientOperationsMixin(object):

async def test_lro(
async def begin_test_lro(
self,
product: Optional["models.Product"] = None,
**kwargs
) -> "models.Product":
) -> AsyncLROPoller["models.Product"]:
"""Put in whatever shape of Product you want, will return a Product with id equal to 100.

:param product: Product to put.
Expand All @@ -34,7 +34,7 @@ async def test_lro(
:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None
:raises: ~azure.core.exceptions.HttpResponseError
"""
api_version = self._get_api_version('test_lro')
api_version = self._get_api_version('begin_test_lro')
if api_version == '1.0.0':
from ..v1.aio.operations_async import MultiapiServiceClientOperationsMixin as OperationClass
else:
Expand All @@ -44,7 +44,7 @@ async def test_lro(
mixin_instance._config = self._config
mixin_instance._serialize = Serializer(self._models_dict(api_version))
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return await mixin_instance.test_lro(product, **kwargs)
return await mixin_instance.begin_test_lro(product, **kwargs)

async def test_one(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n",
"coroutine": true
},
Expand All @@ -50,25 +48,21 @@
},
"_test_lro_initial" : {
"sync": {
"operation_name": "_test_lro_initial",
"signature": "def _test_lro_initial(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "_test_lro_initial",
"signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"coroutine": true
},
"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"
},
"test_lro" : {
"begin_test_lro" : {
"sync": {
"operation_name": "begin_test_lro",
"signature": "def begin_test_lro(\n self,\n product=None, # type: Optional[\"models.Product\"]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_lro",
"signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n",
"signature": "async def begin_test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"models.Product\"]:\n",
"coroutine": true
},
"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:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_one" : {
"sync": {
"operation_name": "test_one",
"signature": "def test_one(\n self,\n id, # type: int\n message=None, # type: Optional[str]\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_one",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e \"models.ModelTwo\":\n",
"coroutine": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"operation_mixins": {
"test_paging" : {
"sync": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs # type: Any\n):\n"
},
"async": {
"operation_name": "test_paging",
"signature": "def test_paging(\n self,\n **kwargs\n) -\u003e AsyncItemPaged[\"models.PagingResult\"]:\n",
"coroutine": false
},
Expand Down