diff --git a/ChangeLog.md b/ChangeLog.md index 5f8dfb65c0a..e7407bf25ed 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 - Fix name in setup.py to default to `package-name` if set #721 ### 2020-07-07 - 5.1.0-preview.4 diff --git a/autorest/multiapi/__init__.py b/autorest/multiapi/__init__.py index d687acfbe22..70b1af5b5eb 100644 --- a/autorest/multiapi/__init__.py +++ b/autorest/multiapi/__init__.py @@ -169,7 +169,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 => { @@ -212,8 +241,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_custom_base_url_to_api_version( self, paths_to_versions: List[Path] @@ -317,7 +352,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() 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)