From 8530acf8a07e775b74c36efd15bb5e78f761c4c3 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 15 Jul 2020 10:52:08 -0400 Subject: [PATCH 1/3] have operation mixin signature default to default API version --- autorest/multiapi/__init__.py | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/autorest/multiapi/__init__.py b/autorest/multiapi/__init__.py index ccfba508aa7..63c75ecaa24 100644 --- a/autorest/multiapi/__init__.py +++ b/autorest/multiapi/__init__.py @@ -155,7 +155,36 @@ def _get_paths_to_versions(self) -> List[Path]: paths_to_versions.append(Path(child.stem)) return paths_to_versions - def _build_operation_mixin_meta(self, paths_to_versions: List[Path]) -> Dict[str, Dict[str, Dict[str, Any]]]: + def _make_signature_of_mixin_based_on_default_api_version( + self, + mixin_operations: Dict[str, Dict[str, Dict[str, Any]]], + last_api_version_path: Path + ) -> Dict[str, Dict[str, Dict[str, Any]]]: + metadata_json = json.loads(self._autorestapi.read_file(last_api_version_path / "_metadata.json")) + if not metadata_json.get('operation_mixins'): + return mixin_operations + for func_name, func in metadata_json['operation_mixins'].items(): + if func_name.startswith("_"): + continue + + mixin_operations.setdefault(func_name, {}).setdefault('sync', {}) + mixin_operations.setdefault(func_name, {}).setdefault('async', {}) + mixin_operations[func_name]['sync'].update({ + "signature": func['sync']['signature'], + "doc": func['sync']['doc'], + "call": func['call'] + }) + mixin_operations[func_name]['async'].update({ + "signature": func['async']['signature'], + "coroutine": func['async']['coroutine'], + "doc": func['async']['doc'], + "call": func['call'] + }) + return mixin_operations + + def _build_operation_mixin_meta( + self, paths_to_versions: List[Path], last_api_version: str + ) -> Dict[str, Dict[str, Dict[str, Any]]]: """Introspect the client: version_dict => { @@ -198,8 +227,14 @@ def _build_operation_mixin_meta(self, paths_to_versions: List[Path]) -> Dict[str "available_apis", [] ).append(version_path.name) - - return mixin_operations + # make sure that the signature, doc, call, and coroutine is based off of the default api version, + # if the default api version has a definition for it. + # will hopefully get this removed once we deal with mixin operations with different signatures + # for different api versions + last_api_version_path = [ + version_path for version_path in paths_to_versions if version_path.name == last_api_version + ][0] + return self._make_signature_of_mixin_based_on_default_api_version(mixin_operations, last_api_version_path) def _build_operation_meta( self, paths_to_versions: List[Path] @@ -302,7 +337,7 @@ def process(self) -> bool: # Detect if this client is using an operation mixin (Network) # Operation mixins are available since Autorest.Python 4.x - mixin_operations = self._build_operation_mixin_meta(paths_to_versions) + mixin_operations = self._build_operation_mixin_meta(paths_to_versions, last_api_version) # get client name from default api version path_to_default_version = Path() From 5cdd244a49d6c44eda1111fb6eb8f587db3da94a Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 15 Jul 2020 11:02:25 -0400 Subject: [PATCH 2/3] update changelog --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 64243819970..10855729a5f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,6 +9,7 @@ Modelerfour version: 4.15.378 - Correctly have default behavior of csv for array query parameters when collection format is not specified in the swagger (taken from m4 update - perks PR #118) - Fix bug when generating parameters with client default value and constant schema #707 +- Make operation mixin signatures for multiapi default to default api version #715 ### 2020-07-07 - 5.1.0-preview.4 Modelerfour version: 4.15.378 From 95abebaa059c18ac98b45782508f0343d935263a Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 23 Jul 2020 16:21:29 -0400 Subject: [PATCH 3/3] regenerate and getting sarangan's testserver change --- .../subscriptionidapiversion/_microsoft_azure_test_url.py | 2 +- .../aio/_microsoft_azure_test_url_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/_microsoft_azure_test_url.py b/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/_microsoft_azure_test_url.py index ed1fe35b9c8..f04614ffb4b 100644 --- a/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/_microsoft_azure_test_url.py +++ b/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/_microsoft_azure_test_url.py @@ -44,7 +44,7 @@ def __init__( ): # type: (...) -> None if not base_url: - base_url = 'https://management.azure.com' + base_url = 'http://localhost:3000' self._config = MicrosoftAzureTestUrlConfiguration(credential, subscription_id, **kwargs) self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) diff --git a/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/aio/_microsoft_azure_test_url_async.py b/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/aio/_microsoft_azure_test_url_async.py index d43ea134833..02496effde8 100644 --- a/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/aio/_microsoft_azure_test_url_async.py +++ b/test/azure/Expected/AcceptanceTests/SubscriptionIdApiVersion/subscriptionidapiversion/aio/_microsoft_azure_test_url_async.py @@ -41,7 +41,7 @@ def __init__( **kwargs: Any ) -> None: if not base_url: - base_url = 'https://management.azure.com' + base_url = 'http://localhost:3000' self._config = MicrosoftAzureTestUrlConfiguration(credential, subscription_id, **kwargs) self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)