Skip to content

Commit

Permalink
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python
Browse files Browse the repository at this point in the history
…into no_host

* 'autorestv3' of https://github.com/Azure/autorest.python:
  regen and move code model specific args to metadata.json (#867)
  • Loading branch information
iscai-msft committed Jan 20, 2021
2 parents 24b46f8 + 4420fd2 commit 542073c
Show file tree
Hide file tree
Showing 74 changed files with 2,818 additions and 173 deletions.
6 changes: 6 additions & 0 deletions autorest/codegen/models/code_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,9 @@ def has_lro_operations(self) -> bool:
for operation_group in self.operation_groups
for operation in operation_group.operations
])

@staticmethod
def base_url_method_signature(async_mode: bool) -> str:
if async_mode:
return "base_url: Optional[str] = None,"
return "base_url=None, # type: Optional[str]"
30 changes: 15 additions & 15 deletions autorest/codegen/templates/metadata.json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": {{ code_model.class_name | tojson }},
"filename": {{ ("_" + code_model.module_name) | tojson }},
"description": {{ code_model.description | tojson }},
"base_url": {{ (keywords.escape_str(code_model.base_url) if base_url else None) | tojson }},
"base_url": {{ (keywords.escape_str(code_model.base_url) if code_model.base_url else None) | tojson }},
"custom_base_url": {{ (keywords.escape_str(code_model.custom_base_url) if code_model.custom_base_url else None) | tojson }},
"azure_arm": {{ code_model.options["azure_arm"] | tojson }},
"has_lro_operations": {{ code_model.has_lro_operations | tojson }},
Expand Down Expand Up @@ -44,9 +44,15 @@
"call": {{ code_model.global_parameters.method | map(attribute="serialized_name") | join(', ') | tojson }},
"service_client_specific": {
"sync": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
},
{% if not code_model.custom_base_url %}
"base_url": {
"signature": {{ code_model.base_url_parameter(False) | tojson }},
"signature": {{ code_model.base_url_method_signature(False) | tojson }},
"description": "Service URL",
"docstring_type": "str",
"required": {{ code_model.required_base_url | tojson }}
Expand All @@ -57,34 +63,28 @@
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
}
},
"async": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
},
"async": {
},
{% if not code_model.custom_base_url %}
"base_url": {
"signature": {{ code_model.base_url_parameter(True) | tojson }},
"signature": {{ code_model.base_url_method_signature(True) | tojson }},
"description": "Service URL",
"docstring_type": "str",
"required": {{ code_model.required_base_url | tojson }}
},
{% endif %}
"profile": {
"signature": "profile=KnownProfiles.default, # type: KnownProfiles",
"signature": "profile: KnownProfiles = KnownProfiles.default,",
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
"api_version": {
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions autorest/codegen/templates/service_client.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ def __init__(
{% for param_signature in code_model.global_parameters.async_method_signature %}
{{ param_signature }},
{% endfor %}
{% if code_model.base_url or code_model.required_base_url %}
{{ code_model.base_url_parameter(True) }}
{% if not code_model.custom_base_url %}
{{ code_model.base_url_method_signature(True) }}
{% endif %}
**kwargs: Any
{% else %}
{% for param_signature in code_model.global_parameters.sync_method_signature %}
{{ param_signature }}
{% endfor %}
{% if not code_model.custom_base_url %}
{{ code_model.base_url_parameter(False) }}
{{ code_model.base_url_method_signature(False) }}
{% endif %}
**kwargs # type: Any
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion autorest/multiapi/models/code_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
self.config = Config(default_version_metadata)
self.operation_mixin_group = OperationMixinGroup(version_path_to_metadata, default_api_version)
self.global_parameters = GlobalParameters(
default_version_metadata["global_parameters"], self.service_client
default_version_metadata["global_parameters"]
)
self.user_specified_default_api = user_specified_default_api

Expand Down
30 changes: 14 additions & 16 deletions autorest/multiapi/models/global_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List
from .global_parameter import GlobalParameter
from .constant_global_parameter import ConstantGlobalParameter

def _convert_global_parameters(sync_metadata, async_metadata):
global_parameters = [
GlobalParameter(
name=parameter_name,
global_parameter_metadata_sync=gp_sync,
global_parameter_metadata_async=async_metadata[parameter_name]
)
for parameter_name, gp_sync in sync_metadata.items()
]
return global_parameters

class GlobalParameters:
def __init__(
self,
global_parameters_metadata: Dict[str, Any],
service_client,
):
self.call = global_parameters_metadata["call"]
self.global_parameters_metadata = global_parameters_metadata
self.service_client = service_client

@property
def service_client_specific_global_parameters(self) -> List[GlobalParameter]:
Expand All @@ -25,7 +34,7 @@ def service_client_specific_global_parameters(self) -> List[GlobalParameter]:
service_client_params_sync = self.global_parameters_metadata["service_client_specific"]["sync"]
service_client_params_async = self.global_parameters_metadata["service_client_specific"]["async"]

return self._convert_global_parameters(
return _convert_global_parameters(
service_client_params_sync,
service_client_params_async
)
Expand All @@ -35,22 +44,11 @@ def parameters(self) -> List[GlobalParameter]:
global_parameters_metadata_sync = self.global_parameters_metadata["sync"]
global_parameters_metadata_async = self.global_parameters_metadata["async"]

return self._convert_global_parameters(
return _convert_global_parameters(
global_parameters_metadata_sync,
global_parameters_metadata_async
)

def _convert_global_parameters(self, sync_metadata, async_metadata):
global_parameters = [
GlobalParameter(
name=parameter_name,
global_parameter_metadata_sync=gp_sync,
global_parameter_metadata_async=async_metadata[parameter_name]
)
for parameter_name, gp_sync in sync_metadata.items()
]
return global_parameters

@property
def constant_parameters(self) -> List[ConstantGlobalParameter]:
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:param base_url: Service URL
:type base_url: str
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

Expand All @@ -69,11 +69,13 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
def __init__(
self,
credential, # type: "TokenCredential"
api_version=None, # type: Optional[str]
base_url=None, # type: Optional[str]
profile=KnownProfiles.default, # type: KnownProfiles
api_version=None, # type: Optional[str]
**kwargs # type: Any
):
if not base_url:
base_url = 'http://localhost:3000'
self._config = MultiapiServiceClientConfiguration(credential, **kwargs)
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
super(MultiapiServiceClient, self).__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:param base_url: Service URL
:type base_url: str
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

Expand All @@ -67,11 +67,13 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
def __init__(
self,
credential: "AsyncTokenCredential",
base_url: Optional[str] = None,
profile=KnownProfiles.default, # type: KnownProfiles
api_version: Optional[str] = None,
base_url: Optional[str] = None,
profile: KnownProfiles = KnownProfiles.default,
**kwargs # type: Any
) -> None:
if not base_url:
base_url = 'http://localhost:3000'
self._config = MultiapiServiceClientConfiguration(credential, **kwargs)
self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
super(MultiapiServiceClient, self).__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "MultiapiServiceClient",
"filename": "_multiapi_service_client",
"description": "Service client for multiapi client testing.",
"base_url": null,
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true,
"has_lro_operations": true,
Expand Down Expand Up @@ -35,6 +35,12 @@
"call": "credential",
"service_client_specific": {
"sync": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
},
"base_url": {
"signature": "base_url=None, # type: Optional[str]",
"description": "Service URL",
Expand All @@ -46,32 +52,26 @@
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
}
},
"async": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
},
"async": {
},
"base_url": {
"signature": "base_url: Optional[str] = None,",
"description": "Service URL",
"docstring_type": "str",
"required": false
},
"profile": {
"signature": "profile=KnownProfiles.default, # type: KnownProfiles",
"signature": "profile: KnownProfiles = KnownProfiles.default,",
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
"api_version": {
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "MultiapiServiceClient",
"filename": "_multiapi_service_client",
"description": "Service client for multiapi client testing.",
"base_url": null,
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true,
"has_lro_operations": false,
Expand Down Expand Up @@ -35,6 +35,12 @@
"call": "credential",
"service_client_specific": {
"sync": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
},
"base_url": {
"signature": "base_url=None, # type: Optional[str]",
"description": "Service URL",
Expand All @@ -46,32 +52,26 @@
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
}
},
"async": {
"api_version": {
"signature": "api_version=None, # type: Optional[str]",
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
},
"async": {
},
"base_url": {
"signature": "base_url: Optional[str] = None,",
"description": "Service URL",
"docstring_type": "str",
"required": false
},
"profile": {
"signature": "profile=KnownProfiles.default, # type: KnownProfiles",
"signature": "profile: KnownProfiles = KnownProfiles.default,",
"description": "A profile definition, from KnownProfiles to dict.",
"docstring_type": "azure.profiles.KnownProfiles",
"required": false
},
"api_version": {
"signature": "api_version: Optional[str] = None,",
"description": "API version to use if no profile is provided, or if missing in profile.",
"docstring_type": "str",
"required": false
}
}
}
Expand Down
Loading

0 comments on commit 542073c

Please sign in to comment.