diff --git a/docs/client/models.md b/docs/client/models.md index d71e50aff1e..2ee9f87f86f 100644 --- a/docs/client/models.md +++ b/docs/client/models.md @@ -26,4 +26,4 @@ It accepts optional parameter `api_version`. If specified, it will retrieve the default API version the code was generated with. -[models_ex]: https://github.com/Azure/autorest.python/blob/autorestv3/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_multiapi_service_client.py#L91 +[models_ex]: ../samples/specification/multiapi/generated/azure/multiapi/sample/_multiapi_service_client.py#L91 diff --git a/docs/client/operations.md b/docs/client/operations.md index 671129d0e7a..30b1187d235 100644 --- a/docs/client/operations.md +++ b/docs/client/operations.md @@ -6,7 +6,7 @@ or directly on the client. ## Operation Group vs No Operation Group -If your swagger defines an operation group for your operation (for example, in this swagger, the operation `list` +If your swagger defines an operation group for your operation (for example, in [this][operation_group_example] swagger, the operation `list` is part of operation group `application`), you would access the operation through `client.application.list()`. If there's no operation group, as in [this][mixin_example] case, you would access the operation directly from the client diff --git a/docs/client/readme.md b/docs/client/readme.md index e4130bba741..f1ea82ba0f2 100644 --- a/docs/client/readme.md +++ b/docs/client/readme.md @@ -5,7 +5,7 @@ After [generating][generate] your client, this section tells you how to actually * [Initializing Your Python Client][initializing] * [Calling Operations with Your Python Client][operations] * [Accessing Models and Enums][models] -* [Error Handling][error_handling] +* [Troubleshooting][troubleshooting] * [Tracing][tracing] @@ -13,5 +13,5 @@ After [generating][generate] your client, this section tells you how to actually [initializing]: ./initializing.md [operations]: ./operations.md [models]: ./models.md -[error_handling]: ./error_handling.md +[troubleshooting]: ./troubleshooting.md [tracing]: ./tracing.md \ No newline at end of file diff --git a/docs/client/error_handling.md b/docs/client/troubleshooting.md similarity index 97% rename from docs/client/error_handling.md rename to docs/client/troubleshooting.md index 74bb1e1ae90..fd05bcdcd3a 100644 --- a/docs/client/error_handling.md +++ b/docs/client/troubleshooting.md @@ -1,6 +1,6 @@ -# Error Handling +# Troubleshooting -## General +## Error Handling Our generated clients raise [exceptions defined in `azure-core`][azure_core_exceptions]. While the base for all exceptions is [`AzureError`][azure_error], [`HttpResponseError`][http_response_error] is also a common base catch-all for exceptions, as these errors are thrown in the case of a request being made, and a non-successful diff --git a/docs/generate/troubleshooting.md b/docs/generate/troubleshooting.md new file mode 100644 index 00000000000..17bcdc67427 --- /dev/null +++ b/docs/generate/troubleshooting.md @@ -0,0 +1,52 @@ +# Troubleshooting + +## Generation Errors + +There are two broad kinds of errors you can run into when generating: one kind is thrown earlier in the AutoRest pipeline and has to do with malformed swaggers (see [our main docs][main_docs] for more information). The other kind is thrown by the Python generator itself. + +The general AutoRest errors are thrown like this + +``` +FATAL: Error: Enum types of 'object' and format 'undefined' are not supported. Correct your input (HdiNodeTypes). + Error: Plugin modelerfour reported failure. +``` + +While the Python generator throws Python errors, such as: + +``` +ERROR: [main.Process:52] Python generator raised an exception +Traceback (most recent call last): + ... +ValueError: --credential-scopes must be used with the --add-credential flag + Error: Plugin codegen reported failure. +``` + +Both of these issues should give you enough information to fix the error. If not, please let us know in either the [main repo][autorest_issues], or in the [Python repo][autorest_python_issues]. Also let us know if you believe +there are erroneous errors being thrown. + +## Debugging + +Our [main docs][main_debugging] show you how to pass in flags (`--verbose` / `--debug`) to get more debugging logs for your AutoRest calls. + +If you'd like to actually debug through our code, you need to first clone our [repo]. These debugging steps are specific to VS Code. + +Once debugging our code, you need to add this to the VSCode launch configuration (`launch.json`). This configuration tells VS Code to attach at port `5678`, the default port. + +``` +{ + "name": "Python: Attach", + "type": "python", + "request": "attach", + "port": 5678, + "host": "localhost" +} +``` + +Once this has been successfully added, all that's needed is to add flag `--python.debugger` on our command line. You should now be able to step through the Python generator's code base. + + +[main_docs]: https://github.com/Azure/autorest/tree/master/docs/generate/troubleshooting.md +[autorest_issues]: https://github.com/Azure/autorest/issues +[autorest_python_issues]: https://github.com/Azure/autorest.python/issues +[main_debugging]: https://github.com/Azure/autorest/tree/master/docs/generate/troubleshooting.md#debugging +[autorest_python_repo]: https://github.com/Azure/autorest.python/tree/autorestv3 \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md index 0a164a9de49..e172eb590e5 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -34,4 +34,4 @@ These documents are Python-specific, see [our main docs][main_docs] for more gen [main_dev]: https://github.com/Azure/autorest/tree/master/docs/dev/readme.md [sample]: ./samples/readme.md [faq]: ./faq.md -[trobleshooting]: ./troubleshooting.md \ No newline at end of file +[troubleshooting]: ./troubleshooting.md diff --git a/docs/samples/readme.md b/docs/samples/readme.md index 23291aed850..ef17cedfd25 100644 --- a/docs/samples/readme.md +++ b/docs/samples/readme.md @@ -5,11 +5,14 @@ Here are our samples for common generation scenarios | Scenario | README | Generated Code |------------------|-------------|------------- +|Generating most basic | [readme.md][basic_readme] | [generated][basic_generated] |Generating [management plane][mgmt] | [readme.md][mgmt_readme] | [generated][mgmt_generated] |Generating multi API code | [readme.md][multiapi_readme] | [generated][multiapi_generated] |Generating with [`AzureKeyCredential`][azure_key_credential] | [readme.md][azure_key_credential_readme] | [generated][azure_key_credential_generated] +[basic_readme]: ./specification/basic/readme.md +[basic_generated]: ./specification/basic/generated [mgmt]: https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/control-plane-and-data-plane#control-plane [mgmt_readme]: ./specification/management/readme.md [mgmt_generated]: ./specification/management/generated diff --git a/docs/samples/specification/basic/generated/azure/__init__.py b/docs/samples/specification/basic/generated/azure/__init__.py new file mode 100644 index 00000000000..5960c353a89 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/__init__.py @@ -0,0 +1 @@ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore \ No newline at end of file diff --git a/docs/samples/specification/basic/generated/azure/basic/__init__.py b/docs/samples/specification/basic/generated/azure/basic/__init__.py new file mode 100644 index 00000000000..5960c353a89 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/__init__.py @@ -0,0 +1 @@ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore \ No newline at end of file diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/__init__.py b/docs/samples/specification/basic/generated/azure/basic/sample/__init__.py new file mode 100644 index 00000000000..78354a67f97 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/__init__.py @@ -0,0 +1,19 @@ +# 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 ._auto_rest_head_test_service import AutoRestHeadTestService +from ._version import VERSION + +__version__ = VERSION +__all__ = ['AutoRestHeadTestService'] + +try: + from ._patch import patch_sdk # type: ignore + patch_sdk() +except ImportError: + pass diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/_auto_rest_head_test_service.py b/docs/samples/specification/basic/generated/azure/basic/sample/_auto_rest_head_test_service.py new file mode 100644 index 00000000000..b497da828e3 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/_auto_rest_head_test_service.py @@ -0,0 +1,60 @@ +# 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 TYPE_CHECKING + +from azure.core import PipelineClient +from msrest import Deserializer, Serializer + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Dict, Optional + +from ._configuration import AutoRestHeadTestServiceConfiguration +from .operations import HttpSuccessOperations + + +class AutoRestHeadTestService(object): + """Test Infrastructure for AutoRest. + + :ivar http_success: HttpSuccessOperations operations + :vartype http_success: azure.basic.sample.operations.HttpSuccessOperations + :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 = AutoRestHeadTestServiceConfiguration(**kwargs) + self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {} # type: Dict[str, Any] + self._serialize = Serializer(client_models) + self._serialize.client_side_validation = False + self._deserialize = Deserializer(client_models) + + self.http_success = HttpSuccessOperations( + self._client, self._config, self._serialize, self._deserialize) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> AutoRestHeadTestService + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/_configuration.py b/docs/samples/specification/basic/generated/azure/basic/sample/_configuration.py new file mode 100644 index 00000000000..5bcc364b7cd --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/_configuration.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 TYPE_CHECKING + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + +class AutoRestHeadTestServiceConfiguration(Configuration): + """Configuration for AutoRestHeadTestService. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__( + self, + **kwargs # type: Any + ): + # type: (...) -> None + super(AutoRestHeadTestServiceConfiguration, self).__init__(**kwargs) + + kwargs.setdefault('sdk_moniker', 'basic-sample/{}'.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.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**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/docs/samples/specification/basic/generated/azure/basic/sample/_version.py b/docs/samples/specification/basic/generated/azure/basic/sample/_version.py new file mode 100644 index 00000000000..eae7c95b6fb --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/_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/docs/samples/specification/basic/generated/azure/basic/sample/aio/__init__.py b/docs/samples/specification/basic/generated/azure/basic/sample/aio/__init__.py new file mode 100644 index 00000000000..6e499e6a6b1 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/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 ._auto_rest_head_test_service import AutoRestHeadTestService +__all__ = ['AutoRestHeadTestService'] diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/aio/_auto_rest_head_test_service.py b/docs/samples/specification/basic/generated/azure/basic/sample/aio/_auto_rest_head_test_service.py new file mode 100644 index 00000000000..7a5f74a7ff9 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/aio/_auto_rest_head_test_service.py @@ -0,0 +1,56 @@ +# 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, TYPE_CHECKING + +from azure.core import AsyncPipelineClient +from msrest import Deserializer, Serializer + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Dict + +from ._configuration import AutoRestHeadTestServiceConfiguration +from .operations import HttpSuccessOperations + + +class AutoRestHeadTestService(object): + """Test Infrastructure for AutoRest. + + :ivar http_success: HttpSuccessOperations operations + :vartype http_success: azure.basic.sample.aio.operations.HttpSuccessOperations + :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 = AutoRestHeadTestServiceConfiguration(**kwargs) + self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {} # type: Dict[str, Any] + self._serialize = Serializer(client_models) + self._serialize.client_side_validation = False + self._deserialize = Deserializer(client_models) + + self.http_success = HttpSuccessOperations( + self._client, self._config, self._serialize, self._deserialize) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "AutoRestHeadTestService": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/aio/_configuration.py b/docs/samples/specification/basic/generated/azure/basic/sample/aio/_configuration.py new file mode 100644 index 00000000000..7e46511ac0b --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/aio/_configuration.py @@ -0,0 +1,45 @@ +# 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 AutoRestHeadTestServiceConfiguration(Configuration): + """Configuration for AutoRestHeadTestService. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__( + self, + **kwargs: Any + ) -> None: + super(AutoRestHeadTestServiceConfiguration, self).__init__(**kwargs) + + kwargs.setdefault('sdk_moniker', 'basic-sample/{}'.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.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**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/docs/samples/specification/basic/generated/azure/basic/sample/aio/operations/__init__.py b/docs/samples/specification/basic/generated/azure/basic/sample/aio/operations/__init__.py new file mode 100644 index 00000000000..ab55c6fdc9f --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/aio/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 ._http_success_operations import HttpSuccessOperations + +__all__ = [ + 'HttpSuccessOperations', +] diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/aio/operations/_http_success_operations.py b/docs/samples/specification/basic/generated/azure/basic/sample/aio/operations/_http_success_operations.py new file mode 100644 index 00000000000..9092065ba58 --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/aio/operations/_http_success_operations.py @@ -0,0 +1,151 @@ +# 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 ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class HttpSuccessOperations: + """HttpSuccessOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def head200( + self, + **kwargs + ) -> None: + """Return 200 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head200.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head200.metadata = {'url': '/http/success/200'} # type: ignore + + async def head204( + self, + **kwargs + ) -> None: + """Return 204 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head204.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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 [204, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head204.metadata = {'url': '/http/success/204'} # type: ignore + + async def head404( + self, + **kwargs + ) -> None: + """Return 404 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head404.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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 [204, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head404.metadata = {'url': '/http/success/404'} # type: ignore diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/operations/__init__.py b/docs/samples/specification/basic/generated/azure/basic/sample/operations/__init__.py new file mode 100644 index 00000000000..ab55c6fdc9f --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/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 ._http_success_operations import HttpSuccessOperations + +__all__ = [ + 'HttpSuccessOperations', +] diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/operations/_http_success_operations.py b/docs/samples/specification/basic/generated/azure/basic/sample/operations/_http_success_operations.py new file mode 100644 index 00000000000..389b8e00ddf --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/operations/_http_success_operations.py @@ -0,0 +1,158 @@ +# 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 TYPE_CHECKING +import warnings + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Optional, TypeVar + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +class HttpSuccessOperations(object): + """HttpSuccessOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def head200( + self, + **kwargs # type: Any + ): + # type: (...) -> None + """Return 200 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head200.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head200.metadata = {'url': '/http/success/200'} # type: ignore + + def head204( + self, + **kwargs # type: Any + ): + # type: (...) -> None + """Return 204 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head204.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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 [204, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head204.metadata = {'url': '/http/success/204'} # type: ignore + + def head404( + self, + **kwargs # type: Any + ): + # type: (...) -> None + """Return 404 status code if successful. + + :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 = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + # Construct URL + url = self.head404.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + + request = self._client.head(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 [204, 404]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) + + head404.metadata = {'url': '/http/success/404'} # type: ignore diff --git a/docs/samples/specification/basic/generated/azure/basic/sample/py.typed b/docs/samples/specification/basic/generated/azure/basic/sample/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/docs/samples/specification/basic/generated/azure/basic/sample/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/docs/samples/specification/basic/generated/setup.py b/docs/samples/specification/basic/generated/setup.py new file mode 100644 index 00000000000..7ac2e486923 --- /dev/null +++ b/docs/samples/specification/basic/generated/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 = "azure-basic-sample" +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.18", "azure-core<2.0.0,>=1.8.2"] + +setup( + name=NAME, + version=VERSION, + description="azure-basic-sample", + author_email="", + url="", + keywords=["Swagger", "AutoRestHeadTestService"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + Test Infrastructure for AutoRest. + """ +) diff --git a/docs/samples/specification/basic/readme.md b/docs/samples/specification/basic/readme.md new file mode 100644 index 00000000000..c2cfc939b41 --- /dev/null +++ b/docs/samples/specification/basic/readme.md @@ -0,0 +1,13 @@ +# Sample Basic Generation + +### Settings + +``` yaml +input-file: ../../../../node_modules/@microsoft.azure/autorest.testserver/swagger/head.json +namespace: azure.basic.sample +package-name: azure-basic-sample +license-header: MICROSOFT_MIT_NO_VERSION +package-version: 0.1.0 +basic-setup-py: true +clear-output-folder: true +``` \ No newline at end of file diff --git a/tasks.py b/tasks.py index 357552df64c..a125aa18acd 100644 --- a/tasks.py +++ b/tasks.py @@ -346,6 +346,7 @@ def regenerate_samples(c, debug=False): }, "azure_key_credential": None, "directives": None, + "basic": None, } cmds = []