@autorest/python 6.2.6 → 6.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/black/__init__.py +3 -2
- package/autorest/codegen/__init__.py +1 -1
- package/autorest/codegen/models/base.py +9 -1
- package/autorest/codegen/models/client.py +4 -2
- package/autorest/codegen/models/operation.py +6 -6
- package/autorest/codegen/models/operation_group.py +0 -6
- package/autorest/codegen/models/primitive_types.py +50 -0
- package/autorest/codegen/serializers/__init__.py +17 -8
- package/autorest/codegen/serializers/builder_serializer.py +61 -24
- package/autorest/codegen/serializers/client_serializer.py +4 -3
- package/autorest/codegen/serializers/metadata_serializer.py +7 -1
- package/autorest/codegen/serializers/model_serializer.py +8 -12
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -0
- package/autorest/codegen/serializers/parameter_serializer.py +3 -3
- package/autorest/codegen/serializers/patch_serializer.py +2 -4
- package/autorest/codegen/serializers/sample_serializer.py +23 -14
- package/autorest/codegen/serializers/utils.py +6 -0
- package/autorest/codegen/templates/client.py.jinja2 +3 -12
- package/autorest/codegen/templates/config.py.jinja2 +2 -5
- package/autorest/codegen/templates/keywords.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
- package/autorest/codegen/templates/model_base.py.jinja2 +2 -4
- package/autorest/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +286 -325
- package/autorest/jsonrpc/stdstream.py +1 -1
- package/autorest/m2r/__init__.py +2 -2
- package/autorest/multiapi/models/imports.py +13 -5
- package/autorest/multiapi/serializers/import_serializer.py +1 -1
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +2 -8
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +1 -1
- package/autorest/postprocess/__init__.py +5 -4
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# license information.
|
|
6
6
|
# --------------------------------------------------------------------------
|
|
7
7
|
import logging
|
|
8
|
-
from typing import Dict, Any
|
|
8
|
+
from typing import Dict, Any, Union
|
|
9
9
|
from jinja2 import Environment
|
|
10
10
|
|
|
11
11
|
from autorest.codegen.models.credential_types import AzureKeyCredentialType
|
|
@@ -13,6 +13,7 @@ from autorest.codegen.models.credential_types import TokenCredentialType
|
|
|
13
13
|
from autorest.codegen.models.imports import FileImport, ImportType
|
|
14
14
|
from autorest.codegen.models.operation import OperationBase
|
|
15
15
|
from autorest.codegen.models.operation_group import OperationGroup
|
|
16
|
+
from autorest.codegen.models.parameter import Parameter, BodyParameter
|
|
16
17
|
from autorest.codegen.serializers.import_serializer import FileImportSerializer
|
|
17
18
|
from ..models import CodeModel
|
|
18
19
|
|
|
@@ -28,7 +29,6 @@ class SampleSerializer:
|
|
|
28
29
|
operation: OperationBase[Any],
|
|
29
30
|
sample: Dict[str, Any],
|
|
30
31
|
file_name: str,
|
|
31
|
-
sample_origin_name: str,
|
|
32
32
|
) -> None:
|
|
33
33
|
self.code_model = code_model
|
|
34
34
|
self.env = env
|
|
@@ -36,7 +36,6 @@ class SampleSerializer:
|
|
|
36
36
|
self.operation = operation
|
|
37
37
|
self.sample = sample
|
|
38
38
|
self.file_name = file_name
|
|
39
|
-
self.sample_origin_name = sample_origin_name
|
|
40
39
|
|
|
41
40
|
def _imports(self) -> FileImportSerializer:
|
|
42
41
|
imports = FileImport()
|
|
@@ -55,6 +54,13 @@ class SampleSerializer:
|
|
|
55
54
|
imports.add_submodule_import(
|
|
56
55
|
"azure.core.credentials", "AzureKeyCredential", ImportType.THIRDPARTY
|
|
57
56
|
)
|
|
57
|
+
for param in self.operation.parameters.positional:
|
|
58
|
+
if (
|
|
59
|
+
not param.client_default_value
|
|
60
|
+
and not param.optional
|
|
61
|
+
and param.rest_api_name in self.sample["parameters"]
|
|
62
|
+
):
|
|
63
|
+
imports.merge(param.type.imports_for_sample())
|
|
58
64
|
return FileImportSerializer(imports, True)
|
|
59
65
|
|
|
60
66
|
def _client_params(self) -> Dict[str, Any]:
|
|
@@ -88,13 +94,12 @@ class SampleSerializer:
|
|
|
88
94
|
return client_params
|
|
89
95
|
|
|
90
96
|
@staticmethod
|
|
91
|
-
def handle_param(param: Any) -> str:
|
|
92
|
-
if isinstance(
|
|
93
|
-
if any(i in
|
|
94
|
-
return f'"""{
|
|
95
|
-
return f'"{param}"'
|
|
97
|
+
def handle_param(param: Union[Parameter, BodyParameter], param_value: Any) -> str:
|
|
98
|
+
if isinstance(param_value, str):
|
|
99
|
+
if any(i in param_value for i in '\r\n"'):
|
|
100
|
+
return f'"""{param_value}"""'
|
|
96
101
|
|
|
97
|
-
return
|
|
102
|
+
return param.type.serialize_sample_value(param_value)
|
|
98
103
|
|
|
99
104
|
# prepare operation parameters
|
|
100
105
|
def _operation_params(self) -> Dict[str, Any]:
|
|
@@ -103,15 +108,17 @@ class SampleSerializer:
|
|
|
103
108
|
for p in self.operation.parameters.positional
|
|
104
109
|
if not p.client_default_value
|
|
105
110
|
]
|
|
106
|
-
failure_info = "fail to find required param named {}
|
|
111
|
+
failure_info = "fail to find required param named {}"
|
|
107
112
|
operation_params = {}
|
|
108
113
|
for param in params_positional:
|
|
109
114
|
name = param.rest_api_name
|
|
110
115
|
param_value = self.sample["parameters"].get(name)
|
|
111
116
|
if not param.optional:
|
|
112
117
|
if not param_value:
|
|
113
|
-
raise Exception(failure_info.format(name
|
|
114
|
-
operation_params[param.client_name] = self.handle_param(
|
|
118
|
+
raise Exception(failure_info.format(name))
|
|
119
|
+
operation_params[param.client_name] = self.handle_param(
|
|
120
|
+
param, param_value
|
|
121
|
+
)
|
|
115
122
|
return operation_params
|
|
116
123
|
|
|
117
124
|
def _operation_group_name(self) -> str:
|
|
@@ -135,8 +142,10 @@ class SampleSerializer:
|
|
|
135
142
|
return f".{self.operation.name}"
|
|
136
143
|
|
|
137
144
|
def _origin_file(self) -> str:
|
|
138
|
-
name = self.sample.get("x-ms-original-file", "")
|
|
139
|
-
|
|
145
|
+
name = self.sample.get("x-ms-original-file", "")
|
|
146
|
+
if "specification" in name:
|
|
147
|
+
return "specification" + name.split("specification")[-1]
|
|
148
|
+
return ""
|
|
140
149
|
|
|
141
150
|
def serialize(self) -> str:
|
|
142
151
|
return self.env.get_template("sample.py.jinja2").render(
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def method_signature_and_response_type_annotation_template(
|
|
@@ -11,3 +12,8 @@ def method_signature_and_response_type_annotation_template(
|
|
|
11
12
|
response_type_annotation: str,
|
|
12
13
|
) -> str:
|
|
13
14
|
return f"{method_signature} -> {response_type_annotation}:"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def extract_sample_name(file_path: str) -> str:
|
|
18
|
+
file = file_path.split("specification")[-1]
|
|
19
|
+
return Path(file).parts[-1].replace(".json", "")
|
|
@@ -26,21 +26,12 @@
|
|
|
26
26
|
{% endif %}
|
|
27
27
|
return self._client.send_request(request_copy, **kwargs)
|
|
28
28
|
|
|
29
|
-
{{ keywords.def }} close(self)
|
|
30
|
-
{% if not async_mode %}
|
|
31
|
-
# type: () -> None
|
|
32
|
-
{% endif %}
|
|
29
|
+
{{ keywords.def }} close(self) -> None:
|
|
33
30
|
{{ keywords.await }}self._client.close()
|
|
34
31
|
|
|
35
|
-
{{ keywords.def }} __{{ keywords.async_prefix }}enter__(self){{
|
|
36
|
-
{% if not async_mode %}
|
|
37
|
-
# type: () -> {{ client.name }}
|
|
38
|
-
{% endif %}
|
|
32
|
+
{{ keywords.def }} __{{ keywords.async_prefix }}enter__(self){{ " -> \"" + client.name + "\"" }}:
|
|
39
33
|
{{ keywords.await }}self._client.__{{ keywords.async_prefix }}enter__()
|
|
40
34
|
return self
|
|
41
35
|
|
|
42
|
-
{{ keywords.def }} __{{ keywords.async_prefix }}exit__(self, *exc_details)
|
|
43
|
-
{% if not async_mode %}
|
|
44
|
-
# type: (Any) -> None
|
|
45
|
-
{% endif %}
|
|
36
|
+
{{ keywords.def }} __{{ keywords.async_prefix }}exit__(self, *exc_details) -> None:
|
|
46
37
|
{{ keywords.await }}self._client.__{{ keywords.async_prefix }}exit__(*exc_details)
|
|
@@ -30,11 +30,8 @@ class {{ client.name }}Configuration(Configuration): # pylint: disable=too-many
|
|
|
30
30
|
|
|
31
31
|
def _configure(
|
|
32
32
|
self,
|
|
33
|
-
**kwargs
|
|
34
|
-
)
|
|
35
|
-
{% if not async_mode %}
|
|
36
|
-
# type: (...) -> None
|
|
37
|
-
{% endif %}
|
|
33
|
+
**kwargs: Any
|
|
34
|
+
) -> None:
|
|
38
35
|
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
|
|
39
36
|
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
|
|
40
37
|
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
{% set await = "await " if async_mode else "" %}
|
|
4
4
|
{% set async_class = "Async" if async_mode else "" %}
|
|
5
5
|
{% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
|
|
6
|
-
{% set kwargs_declaration = "**kwargs: Any"
|
|
6
|
+
{% set kwargs_declaration = "**kwargs: Any" %}
|
|
7
7
|
{% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__])" %}
|
|
8
8
|
{% macro patch_imports(try_except=False) %}
|
|
9
9
|
{% set indentation = " " if try_except else "" %}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
try:
|
|
12
12
|
{% endif %}
|
|
13
13
|
{{ indentation }}from ._patch import __all__ as _patch_all
|
|
14
|
-
{{ indentation }}from ._patch import * #
|
|
14
|
+
{{ indentation }}from ._patch import * # pylint: disable=unused-wildcard-import
|
|
15
15
|
{% if try_except %}
|
|
16
16
|
except ImportError:
|
|
17
17
|
_patch_all = []
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"service_client_specific": {
|
|
46
46
|
"sync": {
|
|
47
47
|
"api_version": {
|
|
48
|
-
"signature": "api_version
|
|
48
|
+
"signature": "api_version: Optional[str]=None,",
|
|
49
49
|
"description": "API version to use if no profile is provided, or if missing in profile.",
|
|
50
50
|
"docstring_type": "str",
|
|
51
51
|
"required": false
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
{% endif %}
|
|
61
61
|
"profile": {
|
|
62
|
-
"signature": "profile=KnownProfiles.default,
|
|
62
|
+
"signature": "profile: KnownProfiles=KnownProfiles.default,",
|
|
63
63
|
"description": "A profile definition, from KnownProfiles to dict.",
|
|
64
64
|
"docstring_type": "azure.profiles.KnownProfiles",
|
|
65
65
|
"required": false
|
|
@@ -41,8 +41,7 @@ with no data. This gets serialized to `null` on the wire.
|
|
|
41
41
|
"""
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def _timedelta_as_isostr(td):
|
|
45
|
-
# type: (timedelta) -> str
|
|
44
|
+
def _timedelta_as_isostr(td: timedelta) -> str:
|
|
46
45
|
"""Converts a datetime.timedelta object into an ISO 8601 formatted string, e.g. 'P4DT12H30M05S'
|
|
47
46
|
|
|
48
47
|
Function adapted from the Tin Can Python project: https://github.com/RusticiSoftware/TinCanPython
|
|
@@ -92,8 +91,7 @@ def _timedelta_as_isostr(td):
|
|
|
92
91
|
return "P" + date_str + time_str
|
|
93
92
|
|
|
94
93
|
|
|
95
|
-
def _datetime_as_isostr(dt):
|
|
96
|
-
# type: (typing.Union[datetime, date, time, timedelta]) -> str
|
|
94
|
+
def _datetime_as_isostr(dt: typing.Union[datetime, date, time, timedelta]) -> str:
|
|
97
95
|
"""Converts a datetime.(datetime|date|time|timedelta) object into an ISO 8601 formatted string"""
|
|
98
96
|
# First try datetime.datetime
|
|
99
97
|
if hasattr(dt, "year") and hasattr(dt, "hour"):
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
{% endif %}
|
|
10
10
|
{% if model.has_readonly_or_constant_property %}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Readonly variables are only populated by the server, and will be ignored when sending a request.
|
|
13
13
|
{% endif %}
|
|
14
14
|
{% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
|
|
15
15
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
{{ request_builder_serializer.construct_url(request_builder) }}
|
|
16
16
|
{% if request_builder.parameters.path %}
|
|
17
17
|
{{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
|
|
18
|
-
_url = _format_url_section(_url, **path_format_arguments)
|
|
18
|
+
_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
|
|
19
19
|
{% endif %}
|
|
20
20
|
|
|
21
21
|
{% if request_builder.parameters.query %}
|