diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index 2f358a04739..24bfd5e5ad3 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -42,7 +42,7 @@ def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None: break @staticmethod - def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[Dict[str, Any]]: + def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[int]: exceptions_set = set() for group in yaml_data: for operation in group["operations"]: @@ -51,7 +51,7 @@ def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[Dict[str, Any] for exception in operation["exceptions"]: if not exception.get("schema"): continue - exceptions_set.add(exception["schema"]["language"]["python"]["name"]) + exceptions_set.add(id(exception["schema"])) return exceptions_set def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]) -> CodeModel: diff --git a/autorest/codegen/models/object_schema.py b/autorest/codegen/models/object_schema.py index be5465ff5d4..a8889551e87 100644 --- a/autorest/codegen/models/object_schema.py +++ b/autorest/codegen/models/object_schema.py @@ -137,7 +137,7 @@ def fill_instance_from_yaml(self, namespace: str, yaml_data: Dict[str, Any], **k is_exception = False exceptions_set = kwargs.pop("exceptions_set", None) if exceptions_set: - if yaml_data["language"]["python"]["name"] in exceptions_set: + if id(yaml_data) in exceptions_set: is_exception = True self.yaml_data = yaml_data diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 83d4cf603a8..d8bfe5e33ec 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -13,6 +13,7 @@ from .parameter_list import ParameterList from .base_schema import BaseSchema from .schema_request import SchemaRequest +from .object_schema import ObjectSchema _LOGGER = logging.getLogger(__name__) @@ -205,11 +206,16 @@ def success_status_code(self) -> List[Union[str, int]]: return [code for response in self.responses for code in response.status_codes if code != "default"] @property - def default_exception(self) -> Optional[SchemaResponse]: + def default_exception(self) -> Optional[str]: default_excp = [excp for excp in self.exceptions for code in excp.status_codes if code == "default"] - if default_excp: - return default_excp[0] - return None + if not default_excp: + return None + excep_schema = default_excp[0].schema + if isinstance(excep_schema, ObjectSchema): + return f"models.{excep_schema.name}" + # in this case, it's just an AnySchema + return "\'object\'" + @property def status_code_exceptions(self) -> List[SchemaResponse]: diff --git a/autorest/codegen/templates/operation.py.jinja2 b/autorest/codegen/templates/operation.py.jinja2 index 18549b75138..d7880f0b6f9 100644 --- a/autorest/codegen/templates/operation.py.jinja2 +++ b/autorest/codegen/templates/operation.py.jinja2 @@ -51,7 +51,7 @@ if response.status_code not in {{ operation.success_status_code|string() }}: map_error(status_code=response.status_code, response=response, error_map=error_map) {% if operation.default_exception %} - error = self._deserialize(models.{{ operation.default_exception.schema.name }}, response) + error = self._deserialize({{ operation.default_exception }}, response) {% endif %} raise HttpResponseError(response=response{{ ", model=error" if operation.default_exception else "" }}{{ ", error_format=ARMErrorFormat" if code_model.options['azure_arm'] else "" }}) diff --git a/autorest/codegen/templates/paging_operation.py.jinja2 b/autorest/codegen/templates/paging_operation.py.jinja2 index 7b84512bf1c..2b4ccc5a0a2 100644 --- a/autorest/codegen/templates/paging_operation.py.jinja2 +++ b/autorest/codegen/templates/paging_operation.py.jinja2 @@ -122,7 +122,7 @@ if response.status_code not in {{ operation.success_status_code|string() }}: {% if operation.default_exception %} - error = self._deserialize(models.{{ operation.default_exception.schema.name }}, response) + 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 "" }}) diff --git a/package.json b/package.json index 38b07aae91f..894e5f83e11 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "homepage": "https://github.com/Azure/autorest.python/blob/master/README.md", "devDependencies": { "@autorest/autorest": "^3.0.0", - "@microsoft.azure/autorest.testserver": "^2.10.15" + "@microsoft.azure/autorest.testserver": "^2.10.17" }, "files": [ "autorest/**/*.py", diff --git a/tasks.py b/tasks.py index eadbc249620..16a1de5fa3f 100644 --- a/tasks.py +++ b/tasks.py @@ -54,7 +54,8 @@ 'AcceptanceTests/Xml': ['xml-service.json', 'xmlservice'], 'AcceptanceTests/UrlMultiCollectionFormat' : 'url-multi-collectionFormat.json', 'AcceptanceTests/XmsErrorResponse': 'xms-error-responses.json', - 'AcceptanceTests/MediaTypes': ['media_types.json', 0] + 'AcceptanceTests/MediaTypes': ['media_types.json', 0], + 'AcceptanceTests/ObjectType': 'object-type.json' } default_azure_mappings = { diff --git a/test/vanilla/AcceptanceTests/asynctests/test_object_type.py b/test/vanilla/AcceptanceTests/asynctests/test_object_type.py new file mode 100644 index 00000000000..cec98006511 --- /dev/null +++ b/test/vanilla/AcceptanceTests/asynctests/test_object_type.py @@ -0,0 +1,54 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +from async_generator import yield_, async_generator +from objecttype.aio import ObjectTypeClient +from azure.core.exceptions import HttpResponseError + +import pytest + +@pytest.fixture +@async_generator +async def client(): + async with ObjectTypeClient(base_url="http://localhost:3000") as client: + await yield_(client) + +class TestObjectType(object): + + @pytest.mark.asyncio + async def test_get_object(self, client): + response = await client.get() + assert response == {"message": "An object was successfully returned"} + + @pytest.mark.asyncio + async def test_put_object_success(self, client): + response = await client.put({"foo": "bar"}) + assert response is None + + @pytest.mark.asyncio + async def test_put_object_fail(self, client): + with pytest.raises(HttpResponseError) as ex: + response = await client.put({"should": "fail"}) + assert ex.value.model == {"message": "The object you passed was incorrect"} \ No newline at end of file diff --git a/test/vanilla/AcceptanceTests/test_object_type.py b/test/vanilla/AcceptanceTests/test_object_type.py new file mode 100644 index 00000000000..ee7f21e598b --- /dev/null +++ b/test/vanilla/AcceptanceTests/test_object_type.py @@ -0,0 +1,50 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +from objecttype import ObjectTypeClient +from azure.core.exceptions import HttpResponseError + +import pytest + +@pytest.fixture +def client(): + with ObjectTypeClient(base_url="http://localhost:3000") as client: + yield client + +class TestObjectType(object): + + def test_get_object(self, client): + response = client.get() + assert response == {"message": "An object was successfully returned"} + + def test_put_object_success(self, client): + response = client.put({"foo": "bar"}) + assert response is None + + def test_put_object_fail(self, client): + with pytest.raises(HttpResponseError) as ex: + response = client.put({"should": "fail"}) + assert ex.value.model == {"message": "The object you passed was incorrect"} \ No newline at end of file diff --git a/test/vanilla/AcceptanceTests/test_zzz.py b/test/vanilla/AcceptanceTests/test_zzz.py index a1916dfe1fc..d9a823b4e8e 100644 --- a/test/vanilla/AcceptanceTests/test_zzz.py +++ b/test/vanilla/AcceptanceTests/test_zzz.py @@ -62,7 +62,6 @@ def test_ensure_coverage(self): if "Multiapi" in name: # multiapi is in a separate test folder missing_features_or_bugs[name] = 1 - print("Optional coverage:") self._print_report(optional_report, not_supported, missing_features_or_bugs) diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/__init__.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/__init__.py new file mode 100644 index 00000000000..bac33eb5e99 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._object_type_client import ObjectTypeClient +from ._version import VERSION + +__version__ = VERSION +__all__ = ['ObjectTypeClient'] diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_configuration.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_configuration.py new file mode 100644 index 00000000000..1833d293800 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_configuration.py @@ -0,0 +1,46 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from ._version import VERSION + + +class ObjectTypeClientConfiguration(Configuration): + """Configuration for ObjectTypeClient. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__( + self, + **kwargs # type: Any + ): + # type: (...) -> None + super(ObjectTypeClientConfiguration, self).__init__(**kwargs) + + kwargs.setdefault('sdk_moniker', 'objecttypeclient/{}'.format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, + **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get('authentication_policy') diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_object_type_client.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_object_type_client.py new file mode 100644 index 00000000000..bccfa2aae3d --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_object_type_client.py @@ -0,0 +1,51 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any, Optional + +from azure.core import PipelineClient +from msrest import Deserializer, Serializer + +from ._configuration import ObjectTypeClientConfiguration +from .operations import ObjectTypeClientOperationsMixin + + +class ObjectTypeClient(ObjectTypeClientOperationsMixin): + """Service client for testing basic type: object swaggers. + + :param str base_url: Service URL + """ + + def __init__( + self, + base_url=None, # type: Optional[str] + **kwargs # type: Any + ): + # type: (...) -> None + if not base_url: + base_url = 'http://localhost:3000' + self._config = ObjectTypeClientConfiguration(**kwargs) + self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> ObjectTypeClient + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_version.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_version.py new file mode 100644 index 00000000000..eae7c95b6fb --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.1.0" diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/__init__.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/__init__.py new file mode 100644 index 00000000000..90f2081c958 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/__init__.py @@ -0,0 +1,10 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._object_type_client_async import ObjectTypeClient +__all__ = ['ObjectTypeClient'] diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_configuration_async.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_configuration_async.py new file mode 100644 index 00000000000..e3ee9067801 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_configuration_async.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from .._version import VERSION + + +class ObjectTypeClientConfiguration(Configuration): + """Configuration for ObjectTypeClient. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__( + self, + **kwargs: Any + ) -> None: + super(ObjectTypeClientConfiguration, self).__init__(**kwargs) + + kwargs.setdefault('sdk_moniker', 'objecttypeclient/{}'.format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, + **kwargs: Any + ) -> None: + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get('retry_policy') or policies.AsyncRetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get('authentication_policy') diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_object_type_client_async.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_object_type_client_async.py new file mode 100644 index 00000000000..96eb9f65157 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/_object_type_client_async.py @@ -0,0 +1,47 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any, Optional + +from azure.core import AsyncPipelineClient +from msrest import Deserializer, Serializer + +from ._configuration_async import ObjectTypeClientConfiguration +from .operations_async import ObjectTypeClientOperationsMixin + + +class ObjectTypeClient(ObjectTypeClientOperationsMixin): + """Service client for testing basic type: object swaggers. + + :param str base_url: Service URL + """ + + def __init__( + self, + base_url: Optional[str] = None, + **kwargs: Any + ) -> None: + if not base_url: + base_url = 'http://localhost:3000' + self._config = ObjectTypeClientConfiguration(**kwargs) + self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "ObjectTypeClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/__init__.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/__init__.py new file mode 100644 index 00000000000..ba71759cba1 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._object_type_client_operations_async import ObjectTypeClientOperationsMixin + +__all__ = [ + 'ObjectTypeClientOperationsMixin', +] diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/_object_type_client_operations_async.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/_object_type_client_operations_async.py new file mode 100644 index 00000000000..015f655015b --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/aio/operations_async/_object_type_client_operations_async.py @@ -0,0 +1,109 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) 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 +import warnings + +from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.core.tracing.decorator_async import distributed_trace_async + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ObjectTypeClientOperationsMixin: + + @distributed_trace_async + async def get( + self, + **kwargs + ) -> object: + """Basic get that returns an object. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: object or the result of cls(response) + :rtype: object + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[object] + error_map = kwargs.pop('error_map', {404: ResourceNotFoundError, 409: ResourceExistsError}) + + # Construct URL + url = self.get.metadata['url'] + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(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) + error = self._deserialize('object', response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize('object', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get.metadata = {'url': '/objectType/get'} + + @distributed_trace_async + async def put( + self, + put_object: object, + **kwargs + ) -> None: + """Basic put that puts an object. + + :param put_object: + :type put_object: object + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = kwargs.pop('error_map', {404: ResourceNotFoundError, 409: ResourceExistsError}) + + # Construct URL + url = self.put.metadata['url'] + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = kwargs.pop('content_type', 'application/json') + + # Construct and send request + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(put_object, 'object') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + + 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) + error = self._deserialize('object', response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put.metadata = {'url': '/objectType/put'} diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/__init__.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/__init__.py new file mode 100644 index 00000000000..29266a8de5e --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._object_type_client_operations import ObjectTypeClientOperationsMixin + +__all__ = [ + 'ObjectTypeClientOperationsMixin', +] diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/_object_type_client_operations.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/_object_type_client_operations.py new file mode 100644 index 00000000000..8777f2a9fa1 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/operations/_object_type_client_operations.py @@ -0,0 +1,111 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) 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 +import warnings + +from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.core.tracing.decorator import distributed_trace + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +class ObjectTypeClientOperationsMixin(object): + + @distributed_trace + def get( + self, + **kwargs # type: Any + ): + # type: (...) -> object + """Basic get that returns an object. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: object or the result of cls(response) + :rtype: object + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[object] + error_map = kwargs.pop('error_map', {404: ResourceNotFoundError, 409: ResourceExistsError}) + + # Construct URL + url = self.get.metadata['url'] + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(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) + error = self._deserialize('object', response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize('object', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get.metadata = {'url': '/objectType/get'} + + @distributed_trace + def put( + self, + put_object, # type: object + **kwargs # type: Any + ): + # type: (...) -> None + """Basic put that puts an object. + + :param put_object: + :type put_object: object + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = kwargs.pop('error_map', {404: ResourceNotFoundError, 409: ResourceExistsError}) + + # Construct URL + url = self.put.metadata['url'] + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = kwargs.pop('content_type', 'application/json') + + # Construct and send request + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(put_object, 'object') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + + 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) + error = self._deserialize('object', response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put.metadata = {'url': '/objectType/put'} diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/py.typed b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/objecttype/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/test/vanilla/Expected/AcceptanceTests/ObjectType/setup.py b/test/vanilla/Expected/AcceptanceTests/ObjectType/setup.py new file mode 100644 index 00000000000..b5019ecc707 --- /dev/null +++ b/test/vanilla/Expected/AcceptanceTests/ObjectType/setup.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +# coding: utf-8 + +from setuptools import setup, find_packages + +NAME = "objecttypeclient" +VERSION = "0.1.0" + +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = ["msrest>=0.6.0", "azure-core<2.0.0,>=1.2.0"] + +setup( + name=NAME, + version=VERSION, + description="ObjectTypeClient", + author_email="", + url="", + keywords=["Swagger", "ObjectTypeClient"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + Service client for testing basic type: object swaggers. + """ +) diff --git a/test/vanilla/requirements.txt b/test/vanilla/requirements.txt index 80df2352011..f1f59b8d7ad 100644 --- a/test/vanilla/requirements.txt +++ b/test/vanilla/requirements.txt @@ -28,6 +28,7 @@ aiohttp;python_full_version>="3.5.2" -e ./Expected/AcceptanceTests/Http -e ./Expected/AcceptanceTests/MediaTypes -e ./Expected/AcceptanceTests/ModelFlattening +-e ./Expected/AcceptanceTests/ObjectType -e ./Expected/AcceptanceTests/ParameterFlattening -e ./Expected/AcceptanceTests/Report -e ./Expected/AcceptanceTests/RequiredOptional diff --git a/test/vanilla/tox.ini b/test/vanilla/tox.ini index 062f4341cc2..531e6450a77 100644 --- a/test/vanilla/tox.ini +++ b/test/vanilla/tox.ini @@ -49,6 +49,7 @@ commands = sphinx-apidoc -f -o . ../Expected/AcceptanceTests/Header sphinx-apidoc -f -o . ../Expected/AcceptanceTests/Http sphinx-apidoc -f -o . ../Expected/AcceptanceTests/ModelFlattening + sphinx-apidoc -f -o . ../Expected/AcceptanceTests/ObjectType sphinx-apidoc -f -o . ../Expected/AcceptanceTests/ParameterFlattening sphinx-apidoc -f -o . ../Expected/AcceptanceTests/Report sphinx-apidoc -f -o . ../Expected/AcceptanceTests/RequiredOptional