Skip to content

Commit

Permalink
have operation mixin signature default to default API version (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Jul 23, 2020
1 parent e5c551f commit 278f0db
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 39 additions & 4 deletions autorest/multiapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 278f0db

Please sign in to comment.