@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
|
@@ -17,7 +17,6 @@ import re
|
|
|
17
17
|
import sys
|
|
18
18
|
import codecs
|
|
19
19
|
from typing import (
|
|
20
|
-
Dict,
|
|
21
20
|
Any,
|
|
22
21
|
cast,
|
|
23
22
|
Optional,
|
|
@@ -27,7 +26,6 @@ from typing import (
|
|
|
27
26
|
Mapping,
|
|
28
27
|
Callable,
|
|
29
28
|
MutableMapping,
|
|
30
|
-
List,
|
|
31
29
|
)
|
|
32
30
|
|
|
33
31
|
try:
|
|
@@ -225,12 +223,12 @@ class Model:
|
|
|
225
223
|
serialization and deserialization.
|
|
226
224
|
"""
|
|
227
225
|
|
|
228
|
-
_subtype_map:
|
|
229
|
-
_attribute_map:
|
|
230
|
-
_validation:
|
|
226
|
+
_subtype_map: dict[str, dict[str, Any]] = {}
|
|
227
|
+
_attribute_map: dict[str, dict[str, Any]] = {}
|
|
228
|
+
_validation: dict[str, dict[str, Any]] = {}
|
|
231
229
|
|
|
232
230
|
def __init__(self, **kwargs: Any) -> None:
|
|
233
|
-
self.additional_properties: Optional[
|
|
231
|
+
self.additional_properties: Optional[dict[str, Any]] = {}
|
|
234
232
|
for k in kwargs: # pylint: disable=consider-using-dict-items
|
|
235
233
|
if k not in self._attribute_map:
|
|
236
234
|
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
|
|
@@ -307,7 +305,7 @@ class Model:
|
|
|
307
305
|
def as_dict(
|
|
308
306
|
self,
|
|
309
307
|
keep_readonly: bool = True,
|
|
310
|
-
key_transformer: Callable[[str,
|
|
308
|
+
key_transformer: Callable[[str, dict[str, Any], Any], Any] = attribute_transformer,
|
|
311
309
|
**kwargs: Any
|
|
312
310
|
) -> JSON:
|
|
313
311
|
"""Return a dict that can be serialized using json.dump.
|
|
@@ -376,7 +374,7 @@ class Model:
|
|
|
376
374
|
def from_dict(
|
|
377
375
|
cls,
|
|
378
376
|
data: Any,
|
|
379
|
-
key_extractors: Optional[Callable[[str,
|
|
377
|
+
key_extractors: Optional[Callable[[str, dict[str, Any], Any], Any]] = None,
|
|
380
378
|
content_type: Optional[str] = None,
|
|
381
379
|
) -> Self:
|
|
382
380
|
"""Parse a dict using given key extractor return a model.
|
|
@@ -410,7 +408,7 @@ class Model:
|
|
|
410
408
|
return {}
|
|
411
409
|
result = dict(cls._subtype_map[key])
|
|
412
410
|
for valuetype in cls._subtype_map[key].values():
|
|
413
|
-
result
|
|
411
|
+
result |= objects[valuetype]._flatten_subtype(key, objects) # pylint: disable=protected-access
|
|
414
412
|
return result
|
|
415
413
|
|
|
416
414
|
@classmethod
|
|
@@ -524,7 +522,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
524
522
|
"[]": self.serialize_iter,
|
|
525
523
|
"{}": self.serialize_dict,
|
|
526
524
|
}
|
|
527
|
-
self.dependencies:
|
|
525
|
+
self.dependencies: dict[str, type] = dict(classes) if classes else {}
|
|
528
526
|
self.key_transformer = full_restapi_key_transformer
|
|
529
527
|
self.client_side_validation = True
|
|
530
528
|
|
|
@@ -575,7 +573,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
575
573
|
|
|
576
574
|
if attr_name == "additional_properties" and attr_desc["key"] == "":
|
|
577
575
|
if target_obj.additional_properties is not None:
|
|
578
|
-
serialized
|
|
576
|
+
serialized |= target_obj.additional_properties
|
|
579
577
|
continue
|
|
580
578
|
try:
|
|
581
579
|
|
|
@@ -1180,7 +1178,7 @@ def rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argumen
|
|
|
1180
1178
|
|
|
1181
1179
|
while "." in key:
|
|
1182
1180
|
# Need the cast, as for some reasons "split" is typed as list[str | Any]
|
|
1183
|
-
dict_keys = cast(
|
|
1181
|
+
dict_keys = cast(list[str], _FLATTEN.split(key))
|
|
1184
1182
|
if len(dict_keys) == 1:
|
|
1185
1183
|
key = _decode_attribute_map_key(dict_keys[0])
|
|
1186
1184
|
break
|
|
@@ -1382,7 +1380,7 @@ class Deserializer:
|
|
|
1382
1380
|
"duration": (isodate.Duration, datetime.timedelta),
|
|
1383
1381
|
"iso-8601": (datetime.datetime),
|
|
1384
1382
|
}
|
|
1385
|
-
self.dependencies:
|
|
1383
|
+
self.dependencies: dict[str, type] = dict(classes) if classes else {}
|
|
1386
1384
|
self.key_extractors = [rest_key_extractor, xml_key_extractor]
|
|
1387
1385
|
# Additional properties only works if the "rest_key_extractor" is used to
|
|
1388
1386
|
# extract the keys. Making it to work whatever the key extractor is too much
|
|
@@ -66,9 +66,9 @@ FileType = Union[
|
|
|
66
66
|
# file (or bytes)
|
|
67
67
|
FileContent,
|
|
68
68
|
# (filename, file (or bytes))
|
|
69
|
-
|
|
69
|
+
tuple[Optional[str], FileContent],
|
|
70
70
|
# (filename, file (or bytes), content_type)
|
|
71
|
-
|
|
71
|
+
tuple[Optional[str], FileContent, Optional[str]],
|
|
72
72
|
]
|
|
73
73
|
|
|
74
74
|
def serialize_multipart_data_entry(data_entry: Any) -> Any:
|
|
@@ -77,10 +77,10 @@ def serialize_multipart_data_entry(data_entry: Any) -> Any:
|
|
|
77
77
|
return data_entry
|
|
78
78
|
|
|
79
79
|
def prepare_multipart_form_data(
|
|
80
|
-
body: Mapping[str, Any], multipart_fields:
|
|
81
|
-
) ->
|
|
82
|
-
files:
|
|
83
|
-
data:
|
|
80
|
+
body: Mapping[str, Any], multipart_fields: list[str], data_fields: list[str]
|
|
81
|
+
) -> tuple[list[FileType], dict[str, Any]]:
|
|
82
|
+
files: list[FileType] = []
|
|
83
|
+
data: dict[str, Any] = {}
|
|
84
84
|
for multipart_field in multipart_fields:
|
|
85
85
|
multipart_entry = body.get(multipart_field)
|
|
86
86
|
if isinstance(multipart_entry, list):
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
"""The preprocessing autorest plugin."""
|
|
7
7
|
import copy
|
|
8
|
-
from typing import Callable,
|
|
8
|
+
from typing import Callable, Any, Optional
|
|
9
9
|
|
|
10
10
|
from ..utils import to_snake_case, extract_original_name
|
|
11
11
|
from .helpers import (
|
|
@@ -26,8 +26,8 @@ from ..utils import (
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def update_overload_section(
|
|
29
|
-
overload:
|
|
30
|
-
yaml_data:
|
|
29
|
+
overload: dict[str, Any],
|
|
30
|
+
yaml_data: dict[str, Any],
|
|
31
31
|
section: str,
|
|
32
32
|
):
|
|
33
33
|
try:
|
|
@@ -42,7 +42,7 @@ def update_overload_section(
|
|
|
42
42
|
raise ValueError(overload["name"]) from exc
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def add_overload(yaml_data:
|
|
45
|
+
def add_overload(yaml_data: dict[str, Any], body_type: dict[str, Any], for_flatten_params=False):
|
|
46
46
|
overload = copy.deepcopy(yaml_data)
|
|
47
47
|
overload["isOverload"] = True
|
|
48
48
|
overload["bodyParameter"]["type"] = body_type
|
|
@@ -80,7 +80,7 @@ def add_overload(yaml_data: Dict[str, Any], body_type: Dict[str, Any], for_flatt
|
|
|
80
80
|
return overload
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
def add_overloads_for_body_param(yaml_data:
|
|
83
|
+
def add_overloads_for_body_param(yaml_data: dict[str, Any]) -> None:
|
|
84
84
|
"""If we added a body parameter type, add overloads for that type"""
|
|
85
85
|
body_parameter = yaml_data["bodyParameter"]
|
|
86
86
|
if not (
|
|
@@ -121,7 +121,7 @@ def update_operation_group_class_name(prefix: str, class_name: str) -> str:
|
|
|
121
121
|
return class_name + "Operations"
|
|
122
122
|
|
|
123
123
|
|
|
124
|
-
def update_paging_response(yaml_data:
|
|
124
|
+
def update_paging_response(yaml_data: dict[str, Any]) -> None:
|
|
125
125
|
yaml_data["discriminator"] = "paging"
|
|
126
126
|
|
|
127
127
|
|
|
@@ -148,23 +148,35 @@ HEADERS_CONVERT_IN_METHOD = {
|
|
|
148
148
|
},
|
|
149
149
|
},
|
|
150
150
|
}
|
|
151
|
+
CLOUD_SETTING = {
|
|
152
|
+
"optional": True,
|
|
153
|
+
"description": "The cloud setting for which to get the ARM endpoint.",
|
|
154
|
+
"clientName": "cloud_setting",
|
|
155
|
+
"implementation": "Client",
|
|
156
|
+
"location": "keyword",
|
|
157
|
+
"type": {
|
|
158
|
+
"type": "sdkcore",
|
|
159
|
+
"name": "AzureClouds",
|
|
160
|
+
"isTypingOnly": True,
|
|
161
|
+
},
|
|
162
|
+
}
|
|
151
163
|
|
|
152
164
|
|
|
153
|
-
def get_wire_name_lower(parameter:
|
|
165
|
+
def get_wire_name_lower(parameter: dict[str, Any]) -> str:
|
|
154
166
|
return (parameter.get("wireName") or "").lower()
|
|
155
167
|
|
|
156
168
|
|
|
157
|
-
def headers_convert(yaml_data:
|
|
169
|
+
def headers_convert(yaml_data: dict[str, Any], replace_data: Any) -> None:
|
|
158
170
|
if isinstance(replace_data, dict):
|
|
159
171
|
for k, v in replace_data.items():
|
|
160
172
|
yaml_data[k] = v
|
|
161
173
|
|
|
162
174
|
|
|
163
|
-
def has_json_content_type(yaml_data:
|
|
175
|
+
def has_json_content_type(yaml_data: dict[str, Any]) -> bool:
|
|
164
176
|
return any(ct for ct in yaml_data.get("contentTypes", []) if JSON_REGEXP.match(ct))
|
|
165
177
|
|
|
166
178
|
|
|
167
|
-
def has_multi_part_content_type(yaml_data:
|
|
179
|
+
def has_multi_part_content_type(yaml_data: dict[str, Any]) -> bool:
|
|
168
180
|
return any(ct for ct in yaml_data.get("contentTypes", []) if ct == "multipart/form-data")
|
|
169
181
|
|
|
170
182
|
|
|
@@ -189,8 +201,8 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
189
201
|
|
|
190
202
|
def add_body_param_type(
|
|
191
203
|
self,
|
|
192
|
-
code_model:
|
|
193
|
-
body_parameter:
|
|
204
|
+
code_model: dict[str, Any],
|
|
205
|
+
body_parameter: dict[str, Any],
|
|
194
206
|
):
|
|
195
207
|
# only add overload for special content type
|
|
196
208
|
if ( # pylint: disable=too-many-boolean-expressions
|
|
@@ -231,7 +243,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
231
243
|
return name_prefix + name + pad_type
|
|
232
244
|
return name_prefix + name
|
|
233
245
|
|
|
234
|
-
def update_types(self, yaml_data:
|
|
246
|
+
def update_types(self, yaml_data: list[dict[str, Any]]) -> None:
|
|
235
247
|
for type in yaml_data:
|
|
236
248
|
for property in type.get("properties", []):
|
|
237
249
|
property["description"] = update_description(property.get("description", ""))
|
|
@@ -268,8 +280,9 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
268
280
|
for v in HEADERS_CONVERT_IN_METHOD.values():
|
|
269
281
|
if isinstance(v, dict) and "type" in v:
|
|
270
282
|
yaml_data.append(v["type"])
|
|
283
|
+
yaml_data.append(CLOUD_SETTING["type"]) # type: ignore
|
|
271
284
|
|
|
272
|
-
def update_client(self, yaml_data:
|
|
285
|
+
def update_client(self, yaml_data: dict[str, Any]) -> None:
|
|
273
286
|
yaml_data["description"] = update_description(yaml_data["description"], default_description=yaml_data["name"])
|
|
274
287
|
yaml_data["legacyFilename"] = to_snake_case(yaml_data["name"].replace(" ", "_"))
|
|
275
288
|
parameters = yaml_data["parameters"]
|
|
@@ -325,7 +338,11 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
325
338
|
o["hasEtag"] = True
|
|
326
339
|
yaml_data["hasEtag"] = True
|
|
327
340
|
|
|
328
|
-
|
|
341
|
+
# add client signature cloud_setting for arm
|
|
342
|
+
if self.azure_arm and yaml_data["parameters"]:
|
|
343
|
+
yaml_data["parameters"].append(CLOUD_SETTING)
|
|
344
|
+
|
|
345
|
+
def get_operation_updater(self, yaml_data: dict[str, Any]) -> Callable[[dict[str, Any], dict[str, Any]], None]:
|
|
329
346
|
if yaml_data["discriminator"] == "lropaging":
|
|
330
347
|
return self.update_lro_paging_operation
|
|
331
348
|
if yaml_data["discriminator"] == "lro":
|
|
@@ -334,7 +351,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
334
351
|
return self.update_paging_operation
|
|
335
352
|
return self.update_operation
|
|
336
353
|
|
|
337
|
-
def update_parameter(self, yaml_data:
|
|
354
|
+
def update_parameter(self, yaml_data: dict[str, Any]) -> None:
|
|
338
355
|
yaml_data["description"] = update_description(yaml_data.get("description", ""))
|
|
339
356
|
if not (yaml_data["location"] == "header" and yaml_data["clientName"] in ("content_type", "accept")):
|
|
340
357
|
yaml_data["clientName"] = self.pad_reserved_words(yaml_data["clientName"].lower(), PadType.PARAMETER)
|
|
@@ -358,8 +375,8 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
358
375
|
|
|
359
376
|
def update_operation(
|
|
360
377
|
self,
|
|
361
|
-
code_model:
|
|
362
|
-
yaml_data:
|
|
378
|
+
code_model: dict[str, Any],
|
|
379
|
+
yaml_data: dict[str, Any],
|
|
363
380
|
*,
|
|
364
381
|
is_overload: bool = False,
|
|
365
382
|
) -> None:
|
|
@@ -390,7 +407,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
390
407
|
self.add_body_param_type(code_model, body_parameter)
|
|
391
408
|
add_overloads_for_body_param(yaml_data)
|
|
392
409
|
|
|
393
|
-
def _update_lro_operation_helper(self, yaml_data:
|
|
410
|
+
def _update_lro_operation_helper(self, yaml_data: dict[str, Any]) -> None:
|
|
394
411
|
for response in yaml_data.get("responses", []):
|
|
395
412
|
response["discriminator"] = "lro"
|
|
396
413
|
response["pollerSync"] = response.get("pollerSync") or "azure.core.polling.LROPoller"
|
|
@@ -410,10 +427,10 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
410
427
|
|
|
411
428
|
def update_lro_paging_operation(
|
|
412
429
|
self,
|
|
413
|
-
code_model:
|
|
414
|
-
yaml_data:
|
|
430
|
+
code_model: dict[str, Any],
|
|
431
|
+
yaml_data: dict[str, Any],
|
|
415
432
|
is_overload: bool = False,
|
|
416
|
-
item_type: Optional[
|
|
433
|
+
item_type: Optional[dict[str, Any]] = None,
|
|
417
434
|
) -> None:
|
|
418
435
|
self.update_lro_operation(code_model, yaml_data, is_overload=is_overload)
|
|
419
436
|
self.update_paging_operation(code_model, yaml_data, is_overload=is_overload, item_type=item_type)
|
|
@@ -430,11 +447,11 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
430
447
|
|
|
431
448
|
def update_lro_operation(
|
|
432
449
|
self,
|
|
433
|
-
code_model:
|
|
434
|
-
yaml_data:
|
|
450
|
+
code_model: dict[str, Any],
|
|
451
|
+
yaml_data: dict[str, Any],
|
|
435
452
|
is_overload: bool = False,
|
|
436
453
|
) -> None:
|
|
437
|
-
def convert_initial_operation_response_type(data:
|
|
454
|
+
def convert_initial_operation_response_type(data: dict[str, Any]) -> None:
|
|
438
455
|
for response in data.get("responses", []):
|
|
439
456
|
response["type"] = KNOWN_TYPES["binary"]
|
|
440
457
|
|
|
@@ -449,10 +466,10 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
449
466
|
|
|
450
467
|
def update_paging_operation(
|
|
451
468
|
self,
|
|
452
|
-
code_model:
|
|
453
|
-
yaml_data:
|
|
469
|
+
code_model: dict[str, Any],
|
|
470
|
+
yaml_data: dict[str, Any],
|
|
454
471
|
is_overload: bool = False,
|
|
455
|
-
item_type: Optional[
|
|
472
|
+
item_type: Optional[dict[str, Any]] = None,
|
|
456
473
|
) -> None:
|
|
457
474
|
self.update_operation(code_model, yaml_data, is_overload=is_overload)
|
|
458
475
|
item_type = item_type or yaml_data["itemType"]["elementType"]
|
|
@@ -470,7 +487,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
470
487
|
for overload in yaml_data.get("overloads", []):
|
|
471
488
|
self.update_paging_operation(code_model, overload, is_overload=True, item_type=item_type)
|
|
472
489
|
|
|
473
|
-
def update_operation_groups(self, code_model:
|
|
490
|
+
def update_operation_groups(self, code_model: dict[str, Any], client: dict[str, Any]) -> None:
|
|
474
491
|
operation_groups_yaml_data = client.get("operationGroups", [])
|
|
475
492
|
for operation_group in operation_groups_yaml_data:
|
|
476
493
|
operation_group["identifyName"] = self.pad_reserved_words(
|
|
@@ -491,7 +508,7 @@ class PreProcessPlugin(YamlUpdatePlugin):
|
|
|
491
508
|
if operation_group.get("operationGroups"):
|
|
492
509
|
self.update_operation_groups(code_model, operation_group)
|
|
493
510
|
|
|
494
|
-
def update_yaml(self, yaml_data:
|
|
511
|
+
def update_yaml(self, yaml_data: dict[str, Any]) -> None:
|
|
495
512
|
"""Convert in place the YAML str."""
|
|
496
513
|
self.update_types(yaml_data["types"])
|
|
497
514
|
yaml_data["types"] += KNOWN_TYPES.values()
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import re
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
from .python_mappings import (
|
|
9
9
|
REDEFINED_BUILTINS,
|
|
10
10
|
BUILTIN_PACKAGES,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def add_redefined_builtin_info(name: str, yaml_data:
|
|
14
|
+
def add_redefined_builtin_info(name: str, yaml_data: dict[str, Any]) -> None:
|
|
15
15
|
if name in REDEFINED_BUILTINS:
|
|
16
16
|
yaml_data["pylintDisable"] = "redefined-builtin"
|
|
17
17
|
|
|
@@ -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 Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
import re
|
|
8
8
|
import argparse
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ TYPESPEC_PACKAGE_MODE = ["azure-mgmt", "azure-dataplane", "generic"]
|
|
|
12
12
|
VALID_PACKAGE_MODE = SWAGGER_PACKAGE_MODE + TYPESPEC_PACKAGE_MODE
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
def update_enum_value(name: str, value: Any, description: str, enum_type:
|
|
15
|
+
def update_enum_value(name: str, value: Any, description: str, enum_type: dict[str, Any]) -> dict[str, Any]:
|
|
16
16
|
return {
|
|
17
17
|
"name": name,
|
|
18
18
|
"type": "enumvalue",
|
|
@@ -49,7 +49,7 @@ def to_snake_case(name: str) -> str:
|
|
|
49
49
|
|
|
50
50
|
def parse_args(
|
|
51
51
|
need_tsp_file: bool = True,
|
|
52
|
-
) ->
|
|
52
|
+
) -> tuple[argparse.Namespace, dict[str, Any]]:
|
|
53
53
|
parser = argparse.ArgumentParser(
|
|
54
54
|
description="Run mypy against target folder. Add a local custom plugin to the path prior to execution. "
|
|
55
55
|
)
|
|
@@ -92,7 +92,7 @@ def parse_args(
|
|
|
92
92
|
return args, unknown_args_ret
|
|
93
93
|
|
|
94
94
|
|
|
95
|
-
def get_body_type_for_description(body_parameter:
|
|
95
|
+
def get_body_type_for_description(body_parameter: dict[str, Any]) -> str:
|
|
96
96
|
if body_parameter["type"]["type"] == "binary":
|
|
97
97
|
return "binary"
|
|
98
98
|
if body_parameter["type"]["type"] == "string":
|
|
@@ -101,7 +101,7 @@ def get_body_type_for_description(body_parameter: Dict[str, Any]) -> str:
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
# used if we want to get a string / binary type etc
|
|
104
|
-
KNOWN_TYPES:
|
|
104
|
+
KNOWN_TYPES: dict[str, dict[str, Any]] = {
|
|
105
105
|
"string": {"type": "string"},
|
|
106
106
|
"binary": {"type": "binary"},
|
|
107
107
|
"anydict": {"type": "dict", "elementType": {"type": "any"}},
|
|
@@ -118,7 +118,7 @@ def build_policies(
|
|
|
118
118
|
*,
|
|
119
119
|
is_azure_flavor: bool = False,
|
|
120
120
|
tracing: bool = True,
|
|
121
|
-
) ->
|
|
121
|
+
) -> list[str]:
|
|
122
122
|
if is_azure_flavor:
|
|
123
123
|
# for Azure
|
|
124
124
|
async_prefix = "Async" if async_mode else ""
|
|
Binary file
|
|
@@ -8,7 +8,7 @@ import logging
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
import json
|
|
10
10
|
from abc import ABC, abstractmethod
|
|
11
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, Iterator, Optional, Union
|
|
12
12
|
|
|
13
13
|
import yaml
|
|
14
14
|
from .utils import TYPESPEC_PACKAGE_MODE, VALID_PACKAGE_MODE
|
|
@@ -33,7 +33,6 @@ class OptionsDict(MutableMapping):
|
|
|
33
33
|
"head-as-boolean": True,
|
|
34
34
|
"keep-version-file": False,
|
|
35
35
|
"low-level-client": False,
|
|
36
|
-
"multiapi": False,
|
|
37
36
|
"no-async": False,
|
|
38
37
|
"no-namespace-folders": False,
|
|
39
38
|
"polymorphic-examples": 5,
|
|
@@ -42,7 +41,7 @@ class OptionsDict(MutableMapping):
|
|
|
42
41
|
"generation-subdir": None, # subdirectory to generate the code in
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
def __init__(self, options: Optional[
|
|
44
|
+
def __init__(self, options: Optional[dict[str, Any]] = None) -> None:
|
|
46
45
|
self._data = options.copy() if options else {}
|
|
47
46
|
self._validate_combinations()
|
|
48
47
|
|
|
@@ -148,16 +147,6 @@ class OptionsDict(MutableMapping):
|
|
|
148
147
|
"If you want operation files, pass in flag --show-operations"
|
|
149
148
|
)
|
|
150
149
|
|
|
151
|
-
if self.get("multiapi") and self.get("version-tolerant"):
|
|
152
|
-
raise ValueError(
|
|
153
|
-
"Can not currently generate version tolerant multiapi SDKs. "
|
|
154
|
-
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
# If multiapi, do not generate default pyproject.toml
|
|
158
|
-
if self.get("multiapi"):
|
|
159
|
-
self["keep-setup-py"] = True
|
|
160
|
-
|
|
161
150
|
if self.get("client-side-validation") and self.get("version-tolerant"):
|
|
162
151
|
raise ValueError("Can not generate version tolerant with --client-side-validation. ")
|
|
163
152
|
|
|
@@ -205,7 +194,7 @@ class OptionsDict(MutableMapping):
|
|
|
205
194
|
for key in self.DEFAULTS:
|
|
206
195
|
if key not in all_keys:
|
|
207
196
|
all_keys.add(key)
|
|
208
|
-
all_keys
|
|
197
|
+
all_keys |= self.DEFAULTS.keys()
|
|
209
198
|
return KeysView({key: None for key in all_keys})
|
|
210
199
|
|
|
211
200
|
def values(self) -> ValuesView[Any]:
|
|
@@ -218,7 +207,7 @@ class OptionsDict(MutableMapping):
|
|
|
218
207
|
class ReaderAndWriter:
|
|
219
208
|
def __init__(self, *, output_folder: Union[str, Path], **kwargs: Any) -> None:
|
|
220
209
|
self.output_folder = Path(output_folder)
|
|
221
|
-
self._list_file:
|
|
210
|
+
self._list_file: list[str] = []
|
|
222
211
|
try:
|
|
223
212
|
with open(
|
|
224
213
|
Path(self.output_folder) / Path("..") / Path("python.json"),
|
|
@@ -234,9 +223,6 @@ class ReaderAndWriter:
|
|
|
234
223
|
_LOGGER.warning("Loading python.json file. This behavior will be depreacted")
|
|
235
224
|
self.options.update(python_json)
|
|
236
225
|
|
|
237
|
-
def get_output_folder(self) -> Path:
|
|
238
|
-
return self.output_folder
|
|
239
|
-
|
|
240
226
|
def read_file(self, path: Union[str, Path]) -> str:
|
|
241
227
|
"""Directly reading from disk"""
|
|
242
228
|
# make path relative to output folder
|
|
@@ -262,7 +248,7 @@ class ReaderAndWriter:
|
|
|
262
248
|
except FileNotFoundError:
|
|
263
249
|
pass
|
|
264
250
|
|
|
265
|
-
def list_file(self) ->
|
|
251
|
+
def list_file(self) -> list[str]:
|
|
266
252
|
return [str(f.relative_to(self.output_folder)) for f in self.output_folder.glob("**/*") if f.is_file()]
|
|
267
253
|
|
|
268
254
|
|
|
@@ -286,7 +272,7 @@ class Plugin(ReaderAndWriter, ABC):
|
|
|
286
272
|
class YamlUpdatePlugin(Plugin):
|
|
287
273
|
"""A plugin that update the YAML as input."""
|
|
288
274
|
|
|
289
|
-
def get_yaml(self) ->
|
|
275
|
+
def get_yaml(self) -> dict[str, Any]:
|
|
290
276
|
# tsp file doesn't have to be relative to output folder
|
|
291
277
|
with open(self.options["tsp_file"], "r", encoding="utf-8-sig") as fd:
|
|
292
278
|
return yaml.safe_load(fd.read())
|
|
@@ -307,7 +293,7 @@ class YamlUpdatePlugin(Plugin):
|
|
|
307
293
|
return True
|
|
308
294
|
|
|
309
295
|
@abstractmethod
|
|
310
|
-
def update_yaml(self, yaml_data:
|
|
296
|
+
def update_yaml(self, yaml_data: dict[str, Any]) -> None:
|
|
311
297
|
"""The code-model-v4-no-tags yaml model tree.
|
|
312
298
|
|
|
313
299
|
:rtype: updated yaml
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Any
|
|
8
8
|
import yaml
|
|
9
9
|
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
20
20
|
class CodeGenerator(Plugin):
|
|
21
21
|
|
|
22
22
|
@staticmethod
|
|
23
|
-
def sort_exceptions(yaml_data:
|
|
23
|
+
def sort_exceptions(yaml_data: dict[str, Any]) -> None:
|
|
24
24
|
for client in yaml_data["clients"]:
|
|
25
25
|
for group in client.get("operationGroups", []):
|
|
26
26
|
for operation in group.get("operations", []):
|
|
@@ -37,7 +37,7 @@ class CodeGenerator(Plugin):
|
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
@staticmethod
|
|
40
|
-
def remove_cloud_errors(yaml_data:
|
|
40
|
+
def remove_cloud_errors(yaml_data: dict[str, Any]) -> None:
|
|
41
41
|
for client in yaml_data["clients"]:
|
|
42
42
|
for group in client.get("operationGroups", []):
|
|
43
43
|
for operation in group.get("operations", []):
|
|
@@ -60,7 +60,7 @@ class CodeGenerator(Plugin):
|
|
|
60
60
|
del yaml_data["schemas"]["objects"][i]
|
|
61
61
|
break
|
|
62
62
|
|
|
63
|
-
def get_yaml(self) ->
|
|
63
|
+
def get_yaml(self) -> dict[str, Any]:
|
|
64
64
|
# tsp file doesn't have to be relative to output folder
|
|
65
65
|
with open(self.options["tsp_file"], "r", encoding="utf-8-sig") as fd:
|
|
66
66
|
return yaml.safe_load(fd.read())
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Any,
|
|
7
|
+
from typing import Any, Union, Optional
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .base_builder import BaseBuilder, ParameterListType
|
|
10
10
|
from .code_model import CodeModel
|
|
@@ -155,7 +155,7 @@ TYPE_TO_OBJECT = {
|
|
|
155
155
|
_LOGGER = logging.getLogger(__name__)
|
|
156
156
|
|
|
157
157
|
|
|
158
|
-
def build_type(yaml_data:
|
|
158
|
+
def build_type(yaml_data: dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
159
159
|
yaml_id = id(yaml_data)
|
|
160
160
|
try:
|
|
161
161
|
return code_model.lookup_type(yaml_id)
|
|
@@ -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 Any,
|
|
6
|
+
from typing import Any, TYPE_CHECKING, Optional
|
|
7
7
|
from abc import ABC, abstractmethod
|
|
8
8
|
from .imports import FileImport
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ class BaseModel:
|
|
|
20
20
|
:type yaml_data: dict[str, Any]
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
def __init__(self, yaml_data:
|
|
23
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
24
24
|
self.yaml_data = yaml_data
|
|
25
25
|
self.code_model = code_model
|
|
26
26
|
|
|
@@ -39,21 +39,18 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
39
39
|
:type yaml_data: dict[str, Any]
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
-
def __init__(self, yaml_data:
|
|
42
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
43
43
|
super().__init__(yaml_data, code_model)
|
|
44
44
|
self.type = yaml_data["type"] # the type discriminator
|
|
45
|
-
self.api_versions:
|
|
45
|
+
self.api_versions: list[str] = yaml_data.get("apiVersions", []) # api versions this type is in.
|
|
46
46
|
|
|
47
47
|
@classmethod
|
|
48
|
-
def from_yaml(cls, yaml_data:
|
|
48
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "BaseType":
|
|
49
49
|
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
50
50
|
|
|
51
51
|
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
52
52
|
return FileImport(self.code_model)
|
|
53
53
|
|
|
54
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
55
|
-
return self.imports(**kwargs)
|
|
56
|
-
|
|
57
54
|
def imports_for_sample(self) -> FileImport:
|
|
58
55
|
return FileImport(self.code_model)
|
|
59
56
|
|
|
@@ -62,7 +59,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
62
59
|
return repr(value)
|
|
63
60
|
|
|
64
61
|
@property
|
|
65
|
-
def xml_metadata(self) ->
|
|
62
|
+
def xml_metadata(self) -> dict[str, Any]:
|
|
66
63
|
"""XML metadata for the type, if the type has it."""
|
|
67
64
|
return self.yaml_data.get("xmlMetadata", {})
|
|
68
65
|
|
|
@@ -132,7 +129,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
132
129
|
"""
|
|
133
130
|
|
|
134
131
|
@property
|
|
135
|
-
def validation(self) -> Optional[
|
|
132
|
+
def validation(self) -> Optional[dict[str, Any]]:
|
|
136
133
|
"""Whether there's any validation constraints on this type.
|
|
137
134
|
|
|
138
135
|
Even though we generate validation maps if there are validation constraints,
|
|
@@ -162,7 +159,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
162
159
|
"""Template of what this schema would look like as JSON input"""
|
|
163
160
|
|
|
164
161
|
def get_polymorphic_subtypes(
|
|
165
|
-
self, polymorphic_subtypes:
|
|
162
|
+
self, polymorphic_subtypes: list["ModelType"] # pylint: disable=unused-argument
|
|
166
163
|
) -> None:
|
|
167
164
|
return None
|
|
168
165
|
|
|
@@ -172,7 +169,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
172
169
|
"""Template of what an instance check of a variable for this type would look like"""
|
|
173
170
|
|
|
174
171
|
@property
|
|
175
|
-
def serialization_constraints(self) ->
|
|
172
|
+
def serialization_constraints(self) -> list[str]:
|
|
176
173
|
"""Whether there are any serialization constraints when serializing this type."""
|
|
177
174
|
return []
|
|
178
175
|
|