@autorest/python 6.38.2 → 6.39.0
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/README.md +2 -27
- package/autorest/codegen.py +0 -1
- package/autorest/jsonrpc/server.py +0 -3
- package/generator/build/lib/pygen/__init__.py +7 -21
- package/generator/build/lib/pygen/codegen/__init__.py +4 -4
- package/generator/build/lib/pygen/codegen/models/__init__.py +2 -2
- package/generator/build/lib/pygen/codegen/models/base.py +9 -12
- package/generator/build/lib/pygen/codegen/models/base_builder.py +4 -6
- package/generator/build/lib/pygen/codegen/models/client.py +61 -102
- package/generator/build/lib/pygen/codegen/models/code_model.py +29 -29
- package/generator/build/lib/pygen/codegen/models/combined_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/constant_type.py +4 -11
- package/generator/build/lib/pygen/codegen/models/credential_types.py +9 -11
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/build/lib/pygen/codegen/models/enum_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/imports.py +24 -29
- package/generator/build/lib/pygen/codegen/models/list_type.py +15 -14
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/build/lib/pygen/codegen/models/model_type.py +11 -11
- package/generator/build/lib/pygen/codegen/models/operation.py +26 -56
- package/generator/build/lib/pygen/codegen/models/operation_group.py +11 -22
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/build/lib/pygen/codegen/models/parameter.py +12 -21
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/build/lib/pygen/codegen/models/property.py +10 -10
- package/generator/build/lib/pygen/codegen/models/request_builder.py +7 -8
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/build/lib/pygen/codegen/models/response.py +15 -40
- package/generator/build/lib/pygen/codegen/models/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +15 -40
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +101 -94
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +46 -60
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/build/lib/pygen/codegen/serializers/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +7 -0
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/build/lib/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/build/lib/pygen/preprocess/__init__.py +47 -30
- package/generator/build/lib/pygen/preprocess/helpers.py +2 -2
- package/generator/build/lib/pygen/utils.py +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +7 -21
- package/generator/pygen/codegen/__init__.py +4 -4
- package/generator/pygen/codegen/models/__init__.py +2 -2
- package/generator/pygen/codegen/models/base.py +9 -12
- package/generator/pygen/codegen/models/base_builder.py +4 -6
- package/generator/pygen/codegen/models/client.py +61 -102
- package/generator/pygen/codegen/models/code_model.py +29 -29
- package/generator/pygen/codegen/models/combined_type.py +7 -7
- package/generator/pygen/codegen/models/constant_type.py +4 -11
- package/generator/pygen/codegen/models/credential_types.py +9 -11
- package/generator/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/pygen/codegen/models/enum_type.py +7 -7
- package/generator/pygen/codegen/models/imports.py +24 -29
- package/generator/pygen/codegen/models/list_type.py +15 -14
- package/generator/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/pygen/codegen/models/model_type.py +11 -11
- package/generator/pygen/codegen/models/operation.py +26 -56
- package/generator/pygen/codegen/models/operation_group.py +11 -22
- package/generator/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/pygen/codegen/models/parameter.py +12 -21
- package/generator/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/pygen/codegen/models/property.py +10 -10
- package/generator/pygen/codegen/models/request_builder.py +7 -8
- package/generator/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/pygen/codegen/models/response.py +15 -40
- package/generator/pygen/codegen/models/utils.py +2 -2
- package/generator/pygen/codegen/serializers/__init__.py +15 -40
- package/generator/pygen/codegen/serializers/builder_serializer.py +101 -94
- package/generator/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/pygen/codegen/serializers/general_serializer.py +46 -60
- package/generator/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/pygen/codegen/serializers/utils.py +2 -2
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +7 -0
- package/generator/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/pygen/preprocess/__init__.py +47 -30
- package/generator/pygen/preprocess/helpers.py +2 -2
- package/generator/pygen/utils.py +6 -6
- package/generator/pygen.egg-info/SOURCES.txt +0 -2
- package/package.json +2 -2
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/autorest/multiapi/__init__.py +0 -185
- package/autorest/multiapi/models/__init__.py +0 -16
- package/autorest/multiapi/models/client.py +0 -68
- package/autorest/multiapi/models/code_model.py +0 -142
- package/autorest/multiapi/models/config.py +0 -24
- package/autorest/multiapi/models/constant_global_parameter.py +0 -11
- package/autorest/multiapi/models/global_parameter.py +0 -34
- package/autorest/multiapi/models/global_parameters.py +0 -53
- package/autorest/multiapi/models/imports.py +0 -181
- package/autorest/multiapi/models/mixin_operation.py +0 -38
- package/autorest/multiapi/models/operation_group.py +0 -29
- package/autorest/multiapi/models/operation_mixin_group.py +0 -89
- package/autorest/multiapi/serializers/__init__.py +0 -145
- package/autorest/multiapi/serializers/import_serializer.py +0 -181
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +0 -89
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +0 -22
- package/autorest/multiapi/templates/multiapi_models.py.jinja2 +0 -9
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +0 -39
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +0 -163
- package/autorest/multiapi/templates/multiapi_version.py.jinja2 +0 -8
- package/autorest/multiapi/utils.py +0 -51
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +0 -167
- package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
|
@@ -3,7 +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 typing import
|
|
6
|
+
from typing import Sequence, Union, Optional
|
|
7
7
|
from enum import Enum, auto
|
|
8
8
|
|
|
9
9
|
from ..models import (
|
|
@@ -17,6 +17,7 @@ from ..models import (
|
|
|
17
17
|
ParameterType,
|
|
18
18
|
)
|
|
19
19
|
from ..models.parameter import _ParameterBase
|
|
20
|
+
from ..models.parameter_list import BodyParameterType
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
class PopKwargType(Enum):
|
|
@@ -25,7 +26,7 @@ class PopKwargType(Enum):
|
|
|
25
26
|
CASE_INSENSITIVE = auto()
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
SPECIAL_HEADER_SERIALIZATION:
|
|
29
|
+
SPECIAL_HEADER_SERIALIZATION: dict[str, list[str]] = {
|
|
29
30
|
"repeatability-request-id": [
|
|
30
31
|
"""if "Repeatability-Request-ID" not in _headers:""",
|
|
31
32
|
""" _headers["Repeatability-Request-ID"] = str(uuid.uuid4())""",
|
|
@@ -51,6 +52,11 @@ SPECIAL_HEADER_SERIALIZATION: Dict[str, List[str]] = {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
|
|
55
|
+
def check_body_optional(body_parameter: Optional[BodyParameterType]) -> bool:
|
|
56
|
+
"""Check if the body parameter is optional."""
|
|
57
|
+
return body_parameter.optional if body_parameter and body_parameter.in_method_signature else False
|
|
58
|
+
|
|
59
|
+
|
|
54
60
|
class ParameterSerializer:
|
|
55
61
|
|
|
56
62
|
def __init__(self, serialize_namespace: str) -> None:
|
|
@@ -113,13 +119,13 @@ class ParameterSerializer:
|
|
|
113
119
|
def serialize_path(
|
|
114
120
|
self,
|
|
115
121
|
parameters: Union[
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
list[Parameter],
|
|
123
|
+
list[RequestBuilderParameter],
|
|
124
|
+
list[ClientParameter],
|
|
125
|
+
list[ConfigParameter],
|
|
120
126
|
],
|
|
121
127
|
serializer_name: str,
|
|
122
|
-
) ->
|
|
128
|
+
) -> list[str]:
|
|
123
129
|
retval = ["path_format_arguments = {"]
|
|
124
130
|
retval.extend(
|
|
125
131
|
[
|
|
@@ -143,7 +149,7 @@ class ParameterSerializer:
|
|
|
143
149
|
kwarg_name: str,
|
|
144
150
|
serializer_name: str,
|
|
145
151
|
is_legacy: bool,
|
|
146
|
-
) ->
|
|
152
|
+
) -> list[str]:
|
|
147
153
|
if (
|
|
148
154
|
not is_legacy
|
|
149
155
|
and param.location == ParameterLocation.HEADER
|
|
@@ -172,8 +178,9 @@ class ParameterSerializer:
|
|
|
172
178
|
pop_headers_kwarg: PopKwargType,
|
|
173
179
|
pop_params_kwarg: PopKwargType,
|
|
174
180
|
check_client_input: bool = False,
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
*,
|
|
182
|
+
body_parameter: Optional[BodyParameterType] = None,
|
|
183
|
+
) -> list[str]:
|
|
177
184
|
retval = []
|
|
178
185
|
|
|
179
186
|
def append_pop_kwarg(key: str, pop_type: PopKwargType) -> None:
|
|
@@ -184,10 +191,17 @@ class ParameterSerializer:
|
|
|
184
191
|
|
|
185
192
|
append_pop_kwarg("headers", pop_headers_kwarg)
|
|
186
193
|
append_pop_kwarg("params", pop_params_kwarg)
|
|
194
|
+
is_body_optional = check_body_optional(body_parameter)
|
|
187
195
|
if pop_headers_kwarg != PopKwargType.NO or pop_params_kwarg != PopKwargType.NO:
|
|
188
196
|
retval.append("")
|
|
189
197
|
for kwarg in parameters:
|
|
198
|
+
is_content_type_optional = getattr(kwarg, "is_content_type", False) and is_body_optional
|
|
190
199
|
type_annotation = kwarg.type_annotation()
|
|
200
|
+
type_annotation = (
|
|
201
|
+
"Optional[" + kwarg.type_annotation() + "]"
|
|
202
|
+
if is_content_type_optional and not type_annotation.startswith("Optional[")
|
|
203
|
+
else type_annotation
|
|
204
|
+
)
|
|
191
205
|
if kwarg.client_default_value is not None or kwarg.optional:
|
|
192
206
|
if check_client_input and kwarg.check_client_input:
|
|
193
207
|
default_value = f"self._config.{kwarg.client_name}"
|
|
@@ -195,12 +209,6 @@ class ParameterSerializer:
|
|
|
195
209
|
default_value = kwarg.client_default_value_declaration
|
|
196
210
|
if check_kwarg_dict and (kwarg.location in [ParameterLocation.HEADER, ParameterLocation.QUERY]):
|
|
197
211
|
kwarg_dict = "headers" if kwarg.location == ParameterLocation.HEADER else "params"
|
|
198
|
-
if (
|
|
199
|
-
kwarg.client_name == "api_version"
|
|
200
|
-
and kwarg.code_model.options["multiapi"]
|
|
201
|
-
and operation_name is not None
|
|
202
|
-
):
|
|
203
|
-
default_value = f"self._api_version{operation_name} or {default_value}"
|
|
204
212
|
default_value = f"_{kwarg_dict}.pop('{kwarg.wire_name}', {default_value})"
|
|
205
213
|
|
|
206
214
|
retval.append(
|
|
@@ -208,6 +216,8 @@ class ParameterSerializer:
|
|
|
208
216
|
)
|
|
209
217
|
else:
|
|
210
218
|
retval.append(f"{kwarg.client_name}: {type_annotation} = kwargs.pop('{kwarg.client_name}')")
|
|
219
|
+
if is_content_type_optional and body_parameter:
|
|
220
|
+
retval.append(f"content_type = content_type if {body_parameter.client_name} else None")
|
|
211
221
|
return retval
|
|
212
222
|
|
|
213
223
|
@staticmethod
|
|
@@ -216,10 +226,10 @@ class ParameterSerializer:
|
|
|
216
226
|
function_def: str,
|
|
217
227
|
method_name: str,
|
|
218
228
|
need_self_param: bool,
|
|
219
|
-
method_param_signatures:
|
|
229
|
+
method_param_signatures: list[str],
|
|
220
230
|
pylint_disable: str = "",
|
|
221
231
|
):
|
|
222
|
-
lines:
|
|
232
|
+
lines: list[str] = []
|
|
223
233
|
first_line = f"{function_def} {method_name}({pylint_disable}"
|
|
224
234
|
lines.append(first_line)
|
|
225
235
|
if need_self_param:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from .import_serializer import FileImportSerializer
|
|
7
|
-
from ..models import
|
|
7
|
+
from ..models import FileImport
|
|
8
8
|
from .base_serializer import BaseSerializer
|
|
9
9
|
|
|
10
10
|
|
|
@@ -12,7 +12,6 @@ class PatchSerializer(BaseSerializer):
|
|
|
12
12
|
def serialize(self) -> str:
|
|
13
13
|
template = self.env.get_template("patch.py.jinja2")
|
|
14
14
|
imports = FileImport(self.code_model)
|
|
15
|
-
imports.add_submodule_import("typing", "List", ImportType.STDLIB)
|
|
16
15
|
return template.render(
|
|
17
16
|
code_model=self.code_model,
|
|
18
17
|
imports=FileImportSerializer(imports),
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import List
|
|
7
6
|
from jinja2 import Environment
|
|
8
7
|
|
|
9
8
|
from ..models import FileImport
|
|
@@ -19,7 +18,7 @@ class RequestBuildersSerializer(BaseSerializer):
|
|
|
19
18
|
self,
|
|
20
19
|
code_model: CodeModel,
|
|
21
20
|
env: Environment,
|
|
22
|
-
request_builders:
|
|
21
|
+
request_builders: list[RequestBuilderType],
|
|
23
22
|
) -> None:
|
|
24
23
|
super().__init__(code_model, env)
|
|
25
24
|
self.request_builders = request_builders
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Any, Union
|
|
8
8
|
from jinja2 import Environment
|
|
9
9
|
|
|
10
10
|
from ..models.operation import OperationBase
|
|
@@ -20,7 +20,6 @@ from ..models import (
|
|
|
20
20
|
BodyParameter,
|
|
21
21
|
FileImport,
|
|
22
22
|
)
|
|
23
|
-
from .._utils import get_parent_namespace
|
|
24
23
|
|
|
25
24
|
_LOGGER = logging.getLogger(__name__)
|
|
26
25
|
|
|
@@ -32,7 +31,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
32
31
|
env: Environment,
|
|
33
32
|
operation_group: OperationGroup,
|
|
34
33
|
operation: OperationBase[Any],
|
|
35
|
-
sample:
|
|
34
|
+
sample: dict[str, Any],
|
|
36
35
|
file_name: str,
|
|
37
36
|
) -> None:
|
|
38
37
|
super().__init__(code_model, env)
|
|
@@ -45,11 +44,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
45
44
|
def _imports(self) -> FileImportSerializer:
|
|
46
45
|
imports = FileImport(self.code_model)
|
|
47
46
|
client = self.operation_group.client
|
|
48
|
-
namespace =
|
|
49
|
-
get_parent_namespace(client.client_namespace)
|
|
50
|
-
if self.code_model.options["multiapi"]
|
|
51
|
-
else client.client_namespace
|
|
52
|
-
)
|
|
47
|
+
namespace = client.client_namespace
|
|
53
48
|
imports.add_submodule_import(namespace, client.name, ImportType.LOCAL)
|
|
54
49
|
credential_type = getattr(client.credential, "type", None)
|
|
55
50
|
if isinstance(credential_type, TokenCredentialType):
|
|
@@ -66,14 +61,14 @@ class SampleSerializer(BaseSerializer):
|
|
|
66
61
|
imports.merge(param.type.imports_for_sample())
|
|
67
62
|
return FileImportSerializer(imports, True)
|
|
68
63
|
|
|
69
|
-
def _client_params(self) ->
|
|
64
|
+
def _client_params(self) -> dict[str, Any]:
|
|
70
65
|
# client params
|
|
71
|
-
special_param = {}
|
|
66
|
+
special_param: dict[str, str] = {}
|
|
72
67
|
credential_type = getattr(self.operation_group.client.credential, "type", None)
|
|
73
68
|
if isinstance(credential_type, TokenCredentialType):
|
|
74
|
-
special_param
|
|
69
|
+
special_param |= {"credential": "DefaultAzureCredential()"}
|
|
75
70
|
elif isinstance(credential_type, KeyCredentialType):
|
|
76
|
-
special_param
|
|
71
|
+
special_param |= {"credential": 'AzureKeyCredential(key=os.getenv("AZURE_KEY"))'}
|
|
77
72
|
|
|
78
73
|
params = [
|
|
79
74
|
p
|
|
@@ -101,7 +96,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
101
96
|
return param.type.serialize_sample_value(param_value)
|
|
102
97
|
|
|
103
98
|
# prepare operation parameters
|
|
104
|
-
def _operation_params(self) ->
|
|
99
|
+
def _operation_params(self) -> dict[str, Any]:
|
|
105
100
|
params = [
|
|
106
101
|
p
|
|
107
102
|
for p in (self.operation.parameters.positional + self.operation.parameters.keyword_only)
|
|
@@ -122,7 +117,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
122
117
|
return ""
|
|
123
118
|
return f".{self.operation_group.property_name}"
|
|
124
119
|
|
|
125
|
-
def _operation_result(self) ->
|
|
120
|
+
def _operation_result(self) -> tuple[str, str]:
|
|
126
121
|
is_response_none = "None" in self.operation.response_type_annotation(async_mode=False)
|
|
127
122
|
lro = ".result()"
|
|
128
123
|
if is_response_none:
|
|
@@ -3,7 +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 typing import
|
|
6
|
+
from typing import Any, Optional
|
|
7
7
|
from jinja2 import Environment
|
|
8
8
|
|
|
9
9
|
from .import_serializer import FileImportSerializer
|
|
@@ -68,8 +68,8 @@ class TestName:
|
|
|
68
68
|
class TestCase:
|
|
69
69
|
def __init__(
|
|
70
70
|
self,
|
|
71
|
-
operation_groups:
|
|
72
|
-
params:
|
|
71
|
+
operation_groups: list[OperationGroup],
|
|
72
|
+
params: dict[str, Any],
|
|
73
73
|
operation: OperationType,
|
|
74
74
|
*,
|
|
75
75
|
async_mode: bool = False,
|
|
@@ -125,7 +125,7 @@ class Test(TestName):
|
|
|
125
125
|
code_model: CodeModel,
|
|
126
126
|
client_name: str,
|
|
127
127
|
operation_group: OperationGroup,
|
|
128
|
-
testcases:
|
|
128
|
+
testcases: list[TestCase],
|
|
129
129
|
test_class_name: str,
|
|
130
130
|
*,
|
|
131
131
|
async_mode: bool = False,
|
|
@@ -143,7 +143,7 @@ class TestGeneralSerializer(BaseSerializer):
|
|
|
143
143
|
return ".aio" if self.async_mode else ""
|
|
144
144
|
|
|
145
145
|
@property
|
|
146
|
-
def test_names(self) ->
|
|
146
|
+
def test_names(self) -> list[TestName]:
|
|
147
147
|
return [TestName(self.code_model, c.name, async_mode=self.async_mode) for c in self.code_model.clients]
|
|
148
148
|
|
|
149
149
|
def add_import_client(self, imports: FileImport) -> None:
|
|
@@ -215,7 +215,7 @@ class TestSerializer(TestGeneralSerializer):
|
|
|
215
215
|
return FileImportSerializer(imports, self.async_mode)
|
|
216
216
|
|
|
217
217
|
@property
|
|
218
|
-
def breadth_search_operation_group(self) ->
|
|
218
|
+
def breadth_search_operation_group(self) -> list[list[OperationGroup]]:
|
|
219
219
|
result = []
|
|
220
220
|
queue = [[self.operation_group]]
|
|
221
221
|
while queue:
|
|
@@ -239,7 +239,7 @@ class TestSerializer(TestGeneralSerializer):
|
|
|
239
239
|
return param_type.target_model_subtype((ModelType,))
|
|
240
240
|
return None
|
|
241
241
|
|
|
242
|
-
def get_operation_params(self, operation: OperationType) ->
|
|
242
|
+
def get_operation_params(self, operation: OperationType) -> dict[str, Any]:
|
|
243
243
|
operation_params = {}
|
|
244
244
|
required_params = [p for p in operation.parameters.method if not p.optional]
|
|
245
245
|
for param in required_params:
|
|
@@ -25,8 +25,8 @@ def strip_end(namespace: str) -> str:
|
|
|
25
25
|
return ".".join(namespace.split(".")[:-1])
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def get_namespace_config(namespace: str
|
|
29
|
-
return
|
|
28
|
+
def get_namespace_config(namespace: str) -> str:
|
|
29
|
+
return namespace
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
def get_namespace_from_package_name(package_name: Optional[str]) -> str:
|
|
@@ -342,7 +342,7 @@ _UNSET = object()
|
|
|
342
342
|
|
|
343
343
|
|
|
344
344
|
class _MyMutableMapping(MutableMapping[str, typing.Any]):
|
|
345
|
-
def __init__(self, data:
|
|
345
|
+
def __init__(self, data: dict[str, typing.Any]) -> None:
|
|
346
346
|
self._data = data
|
|
347
347
|
|
|
348
348
|
def __contains__(self, key: typing.Any) -> bool:
|
|
@@ -422,7 +422,7 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
|
|
|
422
422
|
return self._data.pop(key)
|
|
423
423
|
return self._data.pop(key, default)
|
|
424
424
|
|
|
425
|
-
def popitem(self) ->
|
|
425
|
+
def popitem(self) -> tuple[str, typing.Any]:
|
|
426
426
|
"""
|
|
427
427
|
Removes and returns some (key, value) pair
|
|
428
428
|
:returns: The (key, value) pair.
|
|
@@ -511,7 +511,7 @@ def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-m
|
|
|
511
511
|
|
|
512
512
|
|
|
513
513
|
def _get_rest_field(
|
|
514
|
-
attr_to_rest_field:
|
|
514
|
+
attr_to_rest_field: dict[str, "_RestField"], rest_name: str
|
|
515
515
|
) -> typing.Optional["_RestField"]:
|
|
516
516
|
try:
|
|
517
517
|
return next(rf for rf in attr_to_rest_field.values() if rf._rest_name == rest_name)
|
|
@@ -535,7 +535,7 @@ class Model(_MyMutableMapping):
|
|
|
535
535
|
_is_model = True
|
|
536
536
|
# label whether current class's _attr_to_rest_field has been calculated
|
|
537
537
|
# could not see _attr_to_rest_field directly because subclass inherits it from parent class
|
|
538
|
-
_calculated:
|
|
538
|
+
_calculated: set[str] = set()
|
|
539
539
|
|
|
540
540
|
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
|
|
541
541
|
class_name = self.__class__.__name__
|
|
@@ -620,7 +620,7 @@ class Model(_MyMutableMapping):
|
|
|
620
620
|
# we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
|
|
621
621
|
# 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
|
|
622
622
|
mros = cls.__mro__[:-9][::-1] # ignore parents, and reverse the mro order
|
|
623
|
-
attr_to_rest_field:
|
|
623
|
+
attr_to_rest_field: dict[str, _RestField] = { # map attribute name to rest_field property
|
|
624
624
|
k: v for mro_class in mros for k, v in mro_class.__dict__.items() if k[0] != "_" and hasattr(v, "_type")
|
|
625
625
|
}
|
|
626
626
|
annotations = {
|
|
@@ -635,7 +635,7 @@ class Model(_MyMutableMapping):
|
|
|
635
635
|
rf._type = rf._get_deserialize_callable_from_annotation(annotations.get(attr, None))
|
|
636
636
|
if not rf._rest_name_input:
|
|
637
637
|
rf._rest_name_input = attr
|
|
638
|
-
cls._attr_to_rest_field:
|
|
638
|
+
cls._attr_to_rest_field: dict[str, _RestField] = dict(attr_to_rest_field.items())
|
|
639
639
|
cls._calculated.add(f"{cls.__module__}.{cls.__qualname__}")
|
|
640
640
|
|
|
641
641
|
return super().__new__(cls)
|
|
@@ -677,7 +677,7 @@ class Model(_MyMutableMapping):
|
|
|
677
677
|
mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore # pylint: disable=no-member
|
|
678
678
|
return mapped_cls._deserialize(data, exist_discriminators)
|
|
679
679
|
|
|
680
|
-
def as_dict(self, *, exclude_readonly: bool = False) ->
|
|
680
|
+
def as_dict(self, *, exclude_readonly: bool = False) -> dict[str, typing.Any]:
|
|
681
681
|
"""Return a dict that can be turned into json using json.dump.
|
|
682
682
|
|
|
683
683
|
:keyword bool exclude_readonly: Whether to remove the readonly properties.
|
|
@@ -737,7 +737,7 @@ def _deserialize_with_union(deserializers, obj):
|
|
|
737
737
|
def _deserialize_dict(
|
|
738
738
|
value_deserializer: typing.Optional[typing.Callable],
|
|
739
739
|
module: typing.Optional[str],
|
|
740
|
-
obj:
|
|
740
|
+
obj: dict[typing.Any, typing.Any],
|
|
741
741
|
):
|
|
742
742
|
if obj is None:
|
|
743
743
|
return obj
|
|
@@ -747,7 +747,7 @@ def _deserialize_dict(
|
|
|
747
747
|
|
|
748
748
|
|
|
749
749
|
def _deserialize_multiple_sequence(
|
|
750
|
-
entry_deserializers:
|
|
750
|
+
entry_deserializers: list[typing.Optional[typing.Callable]],
|
|
751
751
|
module: typing.Optional[str],
|
|
752
752
|
obj,
|
|
753
753
|
):
|
|
@@ -768,13 +768,13 @@ def _deserialize_sequence(
|
|
|
768
768
|
return type(obj)(_deserialize(deserializer, entry, module) for entry in obj)
|
|
769
769
|
|
|
770
770
|
|
|
771
|
-
def _sorted_annotations(types:
|
|
771
|
+
def _sorted_annotations(types: list[typing.Any]) -> list[typing.Any]:
|
|
772
772
|
return sorted(
|
|
773
773
|
types,
|
|
774
774
|
key=lambda x: hasattr(x, "__name__") and x.__name__.lower() in ("str", "float", "int", "bool"),
|
|
775
775
|
)
|
|
776
776
|
|
|
777
|
-
def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-return-statements, too-many-branches
|
|
777
|
+
def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-return-statements, too-many-statements, too-many-branches
|
|
778
778
|
annotation: typing.Any,
|
|
779
779
|
module: typing.Optional[str],
|
|
780
780
|
rf: typing.Optional["_RestField"] = None,
|
|
@@ -839,7 +839,10 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
|
|
|
839
839
|
return functools.partial(_deserialize_with_union, deserializers)
|
|
840
840
|
|
|
841
841
|
try:
|
|
842
|
-
|
|
842
|
+
annotation_name = (
|
|
843
|
+
annotation.__name__ if hasattr(annotation, "__name__") else annotation._name # pyright: ignore
|
|
844
|
+
)
|
|
845
|
+
if annotation_name.lower() == "dict":
|
|
843
846
|
value_deserializer = _get_deserialize_callable_from_annotation(
|
|
844
847
|
annotation.__args__[1], module, rf # pyright: ignore
|
|
845
848
|
)
|
|
@@ -852,7 +855,10 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
|
|
|
852
855
|
except (AttributeError, IndexError):
|
|
853
856
|
pass
|
|
854
857
|
try:
|
|
855
|
-
|
|
858
|
+
annotation_name = (
|
|
859
|
+
annotation.__name__ if hasattr(annotation, "__name__") else annotation._name # pyright: ignore
|
|
860
|
+
)
|
|
861
|
+
if annotation_name.lower() in ["list", "set", "tuple", "sequence"]:
|
|
856
862
|
if len(annotation.__args__) > 1: # pyright: ignore
|
|
857
863
|
entry_deserializers = [
|
|
858
864
|
_get_deserialize_callable_from_annotation(dt, module, rf)
|
|
@@ -972,11 +978,11 @@ class _RestField:
|
|
|
972
978
|
name: typing.Optional[str] = None,
|
|
973
979
|
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
|
|
974
980
|
is_discriminator: bool = False,
|
|
975
|
-
visibility: typing.Optional[
|
|
981
|
+
visibility: typing.Optional[list[str]] = None,
|
|
976
982
|
default: typing.Any = _UNSET,
|
|
977
983
|
format: typing.Optional[str] = None,
|
|
978
984
|
is_multipart_file_input: bool = False,
|
|
979
|
-
xml: typing.Optional[
|
|
985
|
+
xml: typing.Optional[dict[str, typing.Any]] = None,
|
|
980
986
|
):
|
|
981
987
|
self._type = type
|
|
982
988
|
self._rest_name_input = name
|
|
@@ -1034,11 +1040,11 @@ def rest_field(
|
|
|
1034
1040
|
*,
|
|
1035
1041
|
name: typing.Optional[str] = None,
|
|
1036
1042
|
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
|
|
1037
|
-
visibility: typing.Optional[
|
|
1043
|
+
visibility: typing.Optional[list[str]] = None,
|
|
1038
1044
|
default: typing.Any = _UNSET,
|
|
1039
1045
|
format: typing.Optional[str] = None,
|
|
1040
1046
|
is_multipart_file_input: bool = False,
|
|
1041
|
-
xml: typing.Optional[
|
|
1047
|
+
xml: typing.Optional[dict[str, typing.Any]] = None,
|
|
1042
1048
|
) -> typing.Any:
|
|
1043
1049
|
return _RestField(
|
|
1044
1050
|
name=name,
|
|
@@ -1055,8 +1061,8 @@ def rest_discriminator(
|
|
|
1055
1061
|
*,
|
|
1056
1062
|
name: typing.Optional[str] = None,
|
|
1057
1063
|
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
|
|
1058
|
-
visibility: typing.Optional[
|
|
1059
|
-
xml: typing.Optional[
|
|
1064
|
+
visibility: typing.Optional[list[str]] = None,
|
|
1065
|
+
xml: typing.Optional[dict[str, typing.Any]] = None,
|
|
1060
1066
|
) -> typing.Any:
|
|
1061
1067
|
return _RestField(name=name, type=type, is_discriminator=True, visibility=visibility, xml=xml)
|
|
1062
1068
|
|
|
@@ -1075,9 +1081,9 @@ def serialize_xml(model: Model, exclude_readonly: bool = False) -> str:
|
|
|
1075
1081
|
def _get_element(
|
|
1076
1082
|
o: typing.Any,
|
|
1077
1083
|
exclude_readonly: bool = False,
|
|
1078
|
-
parent_meta: typing.Optional[
|
|
1084
|
+
parent_meta: typing.Optional[dict[str, typing.Any]] = None,
|
|
1079
1085
|
wrapped_element: typing.Optional[ET.Element] = None,
|
|
1080
|
-
) -> typing.Union[ET.Element,
|
|
1086
|
+
) -> typing.Union[ET.Element, list[ET.Element]]:
|
|
1081
1087
|
if _is_model(o):
|
|
1082
1088
|
model_meta = getattr(o, "_xml", {})
|
|
1083
1089
|
|
|
@@ -1166,7 +1172,7 @@ def _get_element(
|
|
|
1166
1172
|
def _get_wrapped_element(
|
|
1167
1173
|
v: typing.Any,
|
|
1168
1174
|
exclude_readonly: bool,
|
|
1169
|
-
meta: typing.Optional[
|
|
1175
|
+
meta: typing.Optional[dict[str, typing.Any]],
|
|
1170
1176
|
) -> ET.Element:
|
|
1171
1177
|
wrapped_element = _create_xml_element(
|
|
1172
1178
|
meta.get("name") if meta else None, meta.get("prefix") if meta else None, meta.get("ns") if meta else None
|
|
@@ -1209,7 +1215,7 @@ def _deserialize_xml(
|
|
|
1209
1215
|
def _convert_element(e: ET.Element):
|
|
1210
1216
|
# dict case
|
|
1211
1217
|
if len(e.attrib) > 0 or len({child.tag for child in e}) > 1:
|
|
1212
|
-
dict_result:
|
|
1218
|
+
dict_result: dict[str, typing.Any] = {}
|
|
1213
1219
|
for child in e:
|
|
1214
1220
|
if dict_result.get(child.tag) is not None:
|
|
1215
1221
|
if isinstance(dict_result[child.tag], list):
|
|
@@ -1222,7 +1228,7 @@ def _convert_element(e: ET.Element):
|
|
|
1222
1228
|
return dict_result
|
|
1223
1229
|
# array case
|
|
1224
1230
|
if len(e) > 0:
|
|
1225
|
-
array_result:
|
|
1231
|
+
array_result: list[typing.Any] = []
|
|
1226
1232
|
for child in e:
|
|
1227
1233
|
array_result.append(_convert_element(child))
|
|
1228
1234
|
return array_result
|
|
@@ -35,13 +35,10 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
|
|
|
35
35
|
self._config: {{ operation_group.client.name }}Configuration = input_args.pop(0) if input_args else kwargs.pop("config")
|
|
36
36
|
self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer")
|
|
37
37
|
self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer")
|
|
38
|
-
{% if code_model.options["multiapi"] %}
|
|
39
|
-
self._api_version = input_args.pop(0) if input_args else kwargs.pop("api_version")
|
|
40
|
-
{% endif %}
|
|
41
38
|
|
|
42
39
|
{% for og in operation_group.operation_groups %}
|
|
43
40
|
self.{{ og.property_name }} = {{ og.class_name }}(
|
|
44
|
-
self._client, self._config, self._serialize, self._deserialize
|
|
41
|
+
self._client, self._config, self._serialize, self._deserialize
|
|
45
42
|
)
|
|
46
43
|
{% endfor %}
|
|
47
44
|
|
|
@@ -51,13 +48,6 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
|
|
|
51
48
|
def __init__(self) -> None:
|
|
52
49
|
{{ check_abstract_methods() }}
|
|
53
50
|
{% endif %}
|
|
54
|
-
{% if operation_group.is_mixin and code_model.options["multiapi"] %}
|
|
55
|
-
def _api_version(self, op_name: str) -> str: # pylint: disable=unused-argument
|
|
56
|
-
try:
|
|
57
|
-
return self._config.api_version
|
|
58
|
-
except: # pylint: disable=bare-except
|
|
59
|
-
return ""
|
|
60
|
-
{% endif %}
|
|
61
51
|
{% for operation in operation_group.operations if not operation.abstract %}
|
|
62
52
|
|
|
63
53
|
{% set request_builder = operation.request_builder %}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
{{ keywords.patch_imports() }}
|
|
11
11
|
__all__ = [
|
|
12
12
|
{% for operation_group in operation_groups %}
|
|
13
|
-
{% if not operation_group.is_mixin
|
|
13
|
+
{% if not operation_group.is_mixin %}
|
|
14
14
|
'{{ operation_group.class_name }}',
|
|
15
15
|
{% endif %}
|
|
16
16
|
{% endfor %}
|
package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2
CHANGED
|
@@ -111,3 +111,10 @@ pytyped = ["py.typed"]
|
|
|
111
111
|
{{ key }} = {{ val|tojson }}
|
|
112
112
|
{% endfor %}
|
|
113
113
|
{% endif %}
|
|
114
|
+
{% if KEEP_FIELDS and KEEP_FIELDS.get('packaging') %}
|
|
115
|
+
|
|
116
|
+
[packaging]
|
|
117
|
+
{% for key, val in KEEP_FIELDS.get('packaging').items() %}
|
|
118
|
+
{{ key }} = {{ val|tojson }}
|
|
119
|
+
{% endfor %}
|
|
120
|
+
{% endif %}
|
|
@@ -13,7 +13,7 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python
|
|
|
13
13
|
"""
|
|
14
14
|
{{ imports }}
|
|
15
15
|
|
|
16
|
-
__all__:
|
|
16
|
+
__all__: list[str] = [] # Add all objects you want publicly available to users at this package level
|
|
17
17
|
|
|
18
18
|
def patch_sdk():
|
|
19
19
|
"""Do not remove from this file.
|