Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions autorest/codegen/models/code_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,11 @@ def generate_single_parameter_from_multiple_media_types(self) -> None:
raise ValueError("You are missing a parameter that has multiple media types")
chosen_parameter.multiple_media_types_type_annot = f"Union[{type_annot}]"
chosen_parameter.multiple_media_types_docstring_type = docstring_type

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally would've had this code in jinja2, but spent a long time and don't think I can get the jinja2 template to correctly filter by property 'has_lro'. Always defaults to what an Operation model has for this value: False

def has_lro_operations(self) -> bool:
return any([
isinstance(operation, LROOperation)
for operation_group in self.operation_groups
for operation in operation_group.operations
])
3 changes: 2 additions & 1 deletion autorest/codegen/templates/metadata.json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
{% set base_url = code_model.base_url if code_model.base_url else ('https://management.azure.com' if code_model.options["azure_arm"] else None )%}
"base_url": {{ (keywords.escape_str(base_url) if 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 }}
"azure_arm": {{ code_model.options["azure_arm"] | tojson }},
"has_lro_operations": {{ code_model.has_lro_operations | tojson }}
},
"global_parameters": {
"sync_method": {
Expand Down
2 changes: 2 additions & 0 deletions autorest/codegen/templates/service_client.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class {{ code_model.class_name }}({{ base_class }}):
{% if not code_model.custom_base_url %}
:param str base_url: Service URL
{% endif %}
{% if code_model.has_lro_operations %}
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
{% endif %}
"""

{{ method_signature()|indent }}
Expand Down
14 changes: 13 additions & 1 deletion autorest/multiapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ def _merge_mixin_imports_across_versions(

return imports

def _has_lro_operations(
self, paths_to_versions: List[Path]
) -> bool:
has_lro_operations = False
for version_path in paths_to_versions:
metadata_json = json.loads(self._autorestapi.read_file(version_path / "_metadata.json"))
current_client_has_lro_operations = metadata_json["client"]["has_lro_operations"]
if current_client_has_lro_operations:
has_lro_operations = True
return has_lro_operations

def process(self) -> bool:
_LOGGER.info("Generating multiapi client")
# If True, means the auto-profile will consider preview versions.
Expand Down Expand Up @@ -417,7 +428,8 @@ def process(self) -> bool:
"async_imports": str(FileImportSerializer(async_imports, is_python_3_file=True)),
"base_url": metadata_json["client"]["base_url"],
"custom_base_url_to_api_version": self._build_custom_base_url_to_api_version(paths_to_versions),
"azure_arm": metadata_json["client"]["azure_arm"]
"azure_arm": metadata_json["client"]["azure_arm"],
"has_lro_operations": self._has_lro_operations(paths_to_versions)
}

multiapi_serializer = MultiAPISerializer(
Expand Down
2 changes: 2 additions & 0 deletions autorest/multiapi/templates/multiapi_service_client.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class {{ client_name }}({% if mixin_operations %}{{ client_name }}OperationsMixi
{% endif %}
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
{% if has_lro_operations %}
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
{% endif %}
"""

DEFAULT_API_VERSION = '{{ last_api_version }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AutoRestDurationTestService(object):
:ivar duration: DurationOperations operations
:vartype duration: bodyduration.operations.DurationOperations
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class AutoRestDurationTestService(object):
:ivar duration: DurationOperations operations
:vartype duration: bodyduration.aio.operations_async.DurationOperations
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AutoRestParameterGroupingTestService(object):
:ivar parameter_grouping: ParameterGroupingOperations operations
:vartype parameter_grouping: azureparametergrouping.operations.ParameterGroupingOperations
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class AutoRestParameterGroupingTestService(object):
:ivar parameter_grouping: ParameterGroupingOperations operations
:vartype parameter_grouping: azureparametergrouping.aio.operations_async.ParameterGroupingOperations
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class AutoRestReportServiceForAzure(AutoRestReportServiceForAzureOperationsMixin
"""Test Infrastructure for AutoRest.

:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class AutoRestReportServiceForAzure(AutoRestReportServiceForAzureOperationsMixin
"""Test Infrastructure for AutoRest.

:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class AutoRestAzureSpecialParametersTestClient(object):
:param subscription_id: The subscription id, which appears in the path, always modeled in credentials. The value is always '1234-5678-9012-3456'.
:type subscription_id: str
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class AutoRestAzureSpecialParametersTestClient(object):
:param subscription_id: The subscription id, which appears in the path, always modeled in credentials. The value is always '1234-5678-9012-3456'.
:type subscription_id: str
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AutoRestParameterizedHostTestClient(object):
:vartype paths: custombaseurl.operations.PathsOperations
:param host: A string value that is used as a global part of the parameterized host.
:type host: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class AutoRestParameterizedHostTestClient(object):
:vartype paths: custombaseurl.aio.operations_async.PathsOperations
:param host: A string value that is used as a global part of the parameterized host.
:type host: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AutoRestParameterizedHostTestPagingClient(object):
:type credential: ~azure.core.credentials.TokenCredential
:param host: A string value that is used as a global part of the parameterized host.
:type host: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestParameterizedHostTestPagingClient(object):
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param host: A string value that is used as a global part of the parameterized host.
:type host: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadExceptionTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadExceptionTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AutoRestHeadTestService(object):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MicrosoftAzureTestUrl(object):
:param subscription_id: Subscription Id.
:type subscription_id: str
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MicrosoftAzureTestUrl(object):
:param subscription_id: Subscription Id.
:type subscription_id: str
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": true
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": false
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": false
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": true
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": false
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi client testing.",
"base_url": "\u0027http://localhost:3000\u0027",
"custom_base_url": null,
"azure_arm": true
"azure_arm": true,
"has_lro_operations": false
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin):
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class MultiapiCustomBaseUrlServiceClient(MultiapiCustomBaseUrlServiceClientOpera
missing in profile.
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '2.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class MultiapiCustomBaseUrlServiceClient(MultiapiCustomBaseUrlServiceClientOpera
missing in profile.
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '2.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"description": "Service client for multiapi custom base url testing.",
"base_url": null,
"custom_base_url": "\u0027{Endpoint}/multiapiCustomBaseUrl/v1\u0027",
"azure_arm": false
"azure_arm": false,
"has_lro_operations": false
},
"global_parameters": {
"sync_method": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class MultiapiCustomBaseUrlServiceClient(MultiapiCustomBaseUrlServiceClientOpera
:type credential: ~azure.core.credentials.TokenCredential
:param endpoint: Pass in https://localhost:3000.
:type endpoint: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MultiapiCustomBaseUrlServiceClient(MultiapiCustomBaseUrlServiceClientOpera
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:param endpoint: Pass in https://localhost:3000.
:type endpoint: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
Expand Down
Loading