@autorest/python 6.4.3 → 6.4.5
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/_utils.py +0 -1
- package/autorest/codegen/__init__.py +0 -1
- package/autorest/codegen/models/model_type.py +0 -1
- package/autorest/codegen/models/paging_operation.py +15 -2
- package/autorest/codegen/models/parameter_list.py +17 -15
- package/autorest/codegen/models/request_builder.py +9 -9
- package/autorest/codegen/serializers/builder_serializer.py +22 -21
- package/autorest/codegen/serializers/general_serializer.py +0 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +3 -3
- package/autorest/jsonrpc/server.py +0 -1
- package/autorest/m4reformatter/__init__.py +13 -0
- package/autorest/preprocess/__init__.py +5 -12
- package/package.json +1 -1
package/autorest/_utils.py
CHANGED
|
@@ -17,7 +17,6 @@ from ._utils import DEFAULT_HEADER_TEXT
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
20
|
-
|
|
21
20
|
if options["builders_visibility"] not in ["public", "hidden", "embedded"]:
|
|
22
21
|
raise ValueError(
|
|
23
22
|
"The value of --builders-visibility must be either 'public', 'hidden', "
|
|
@@ -163,7 +163,6 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
166
|
-
|
|
167
166
|
is_polymorphic_subtype = (
|
|
168
167
|
self.discriminator_value and not self.discriminated_subtypes
|
|
169
168
|
)
|
|
@@ -84,17 +84,28 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
84
84
|
if not rest_api_name:
|
|
85
85
|
# That's an ok scenario, it just means no next page possible
|
|
86
86
|
return None
|
|
87
|
-
if self.code_model.options["models_mode"]:
|
|
87
|
+
if self.code_model.options["models_mode"] == "msrest":
|
|
88
88
|
return self._get_attr_name(rest_api_name)
|
|
89
89
|
return rest_api_name
|
|
90
90
|
|
|
91
91
|
@property
|
|
92
92
|
def item_name(self) -> str:
|
|
93
93
|
rest_api_name = self.yaml_data["itemName"]
|
|
94
|
-
if self.code_model.options["models_mode"]:
|
|
94
|
+
if self.code_model.options["models_mode"] == "msrest":
|
|
95
|
+
# we don't use the paging model for dpg
|
|
95
96
|
return self._get_attr_name(rest_api_name)
|
|
96
97
|
return rest_api_name
|
|
97
98
|
|
|
99
|
+
@property
|
|
100
|
+
def item_type(self) -> ModelType:
|
|
101
|
+
try:
|
|
102
|
+
item_type_yaml = self.yaml_data["itemType"]
|
|
103
|
+
except KeyError as e:
|
|
104
|
+
raise ValueError(
|
|
105
|
+
"Only call this for DPG paging model deserialization"
|
|
106
|
+
) from e
|
|
107
|
+
return cast(ModelType, self.code_model.types_map[id(item_type_yaml)])
|
|
108
|
+
|
|
98
109
|
@property
|
|
99
110
|
def operation_type(self) -> str:
|
|
100
111
|
return "paging"
|
|
@@ -144,6 +155,8 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
144
155
|
file_import.add_submodule_import(
|
|
145
156
|
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
146
157
|
)
|
|
158
|
+
if self.code_model.options["models_mode"] == "dpg":
|
|
159
|
+
file_import.merge(self.item_type.imports(**kwargs))
|
|
147
160
|
return file_import
|
|
148
161
|
|
|
149
162
|
|
|
@@ -118,9 +118,9 @@ class _ParameterListBase(
|
|
|
118
118
|
|
|
119
119
|
@staticmethod
|
|
120
120
|
@abstractmethod
|
|
121
|
-
def body_parameter_creator() ->
|
|
122
|
-
[Dict[str, Any], "CodeModel"], BodyParameterType
|
|
123
|
-
|
|
121
|
+
def body_parameter_creator() -> (
|
|
122
|
+
Callable[[Dict[str, Any], "CodeModel"], BodyParameterType]
|
|
123
|
+
):
|
|
124
124
|
"""Callable for creating body parameters"""
|
|
125
125
|
|
|
126
126
|
@property
|
|
@@ -317,9 +317,11 @@ class _ParameterList(
|
|
|
317
317
|
return Parameter.from_yaml
|
|
318
318
|
|
|
319
319
|
@staticmethod
|
|
320
|
-
def body_parameter_creator() ->
|
|
321
|
-
[
|
|
322
|
-
|
|
320
|
+
def body_parameter_creator() -> (
|
|
321
|
+
Callable[
|
|
322
|
+
[Dict[str, Any], "CodeModel"], Union[MultipartBodyParameter, BodyParameter]
|
|
323
|
+
]
|
|
324
|
+
):
|
|
323
325
|
return get_body_parameter
|
|
324
326
|
|
|
325
327
|
@property
|
|
@@ -345,15 +347,15 @@ class _RequestBuilderParameterList(
|
|
|
345
347
|
"""_RequestBuilderParameterList is base parameter list for RequestBuilder classes"""
|
|
346
348
|
|
|
347
349
|
@staticmethod
|
|
348
|
-
def parameter_creator() ->
|
|
349
|
-
[Dict[str, Any], "CodeModel"], RequestBuilderParameter
|
|
350
|
-
|
|
350
|
+
def parameter_creator() -> (
|
|
351
|
+
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameter]
|
|
352
|
+
):
|
|
351
353
|
return RequestBuilderParameter.from_yaml
|
|
352
354
|
|
|
353
355
|
@staticmethod
|
|
354
|
-
def body_parameter_creator() ->
|
|
355
|
-
[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameterType
|
|
356
|
-
|
|
356
|
+
def body_parameter_creator() -> (
|
|
357
|
+
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameterType]
|
|
358
|
+
):
|
|
357
359
|
return get_request_body_parameter
|
|
358
360
|
|
|
359
361
|
@property
|
|
@@ -422,9 +424,9 @@ class _ClientGlobalParameterList( # pylint: disable=abstract-method
|
|
|
422
424
|
"""Base parameter list for client and config classes"""
|
|
423
425
|
|
|
424
426
|
@staticmethod
|
|
425
|
-
def body_parameter_creator() ->
|
|
426
|
-
[Dict[str, Any], "CodeModel"], BodyParameter
|
|
427
|
-
|
|
427
|
+
def body_parameter_creator() -> (
|
|
428
|
+
Callable[[Dict[str, Any], "CodeModel"], BodyParameter]
|
|
429
|
+
):
|
|
428
430
|
return BodyParameter.from_yaml
|
|
429
431
|
|
|
430
432
|
@property
|
|
@@ -121,9 +121,9 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
121
121
|
|
|
122
122
|
@staticmethod
|
|
123
123
|
@abstractmethod
|
|
124
|
-
def parameter_list_type() ->
|
|
125
|
-
[Dict[str, Any], "CodeModel"], ParameterListType
|
|
126
|
-
|
|
124
|
+
def parameter_list_type() -> (
|
|
125
|
+
Callable[[Dict[str, Any], "CodeModel"], ParameterListType]
|
|
126
|
+
):
|
|
127
127
|
...
|
|
128
128
|
|
|
129
129
|
@classmethod
|
|
@@ -178,9 +178,9 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
178
178
|
|
|
179
179
|
class RequestBuilder(RequestBuilderBase[RequestBuilderParameterList]):
|
|
180
180
|
@staticmethod
|
|
181
|
-
def parameter_list_type() ->
|
|
182
|
-
[Dict[str, Any], "CodeModel"], RequestBuilderParameterList
|
|
183
|
-
|
|
181
|
+
def parameter_list_type() -> (
|
|
182
|
+
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameterList]
|
|
183
|
+
):
|
|
184
184
|
return RequestBuilderParameterList.from_yaml
|
|
185
185
|
|
|
186
186
|
|
|
@@ -188,9 +188,9 @@ class OverloadedRequestBuilder(
|
|
|
188
188
|
RequestBuilderBase[OverloadedRequestBuilderParameterList]
|
|
189
189
|
):
|
|
190
190
|
@staticmethod
|
|
191
|
-
def parameter_list_type() ->
|
|
192
|
-
[Dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList
|
|
193
|
-
|
|
191
|
+
def parameter_list_type() -> (
|
|
192
|
+
Callable[[Dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList]
|
|
193
|
+
):
|
|
194
194
|
return OverloadedRequestBuilderParameterList.from_yaml
|
|
195
195
|
|
|
196
196
|
|
|
@@ -1066,13 +1066,14 @@ class _OperationSerializer(
|
|
|
1066
1066
|
deserialize_code.append(f" deserialized = {deserialized_value}")
|
|
1067
1067
|
deserialize_code.append("else:")
|
|
1068
1068
|
deserialize_code.append(" deserialized = None")
|
|
1069
|
-
if
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1069
|
+
if len(deserialize_code) > 0:
|
|
1070
|
+
if builder.expose_stream_keyword:
|
|
1071
|
+
retval.append("if _stream:")
|
|
1072
|
+
retval.append(" deserialized = response.iter_bytes()")
|
|
1073
|
+
retval.append("else:")
|
|
1074
|
+
retval.extend([f" {dc}" for dc in deserialize_code])
|
|
1075
|
+
else:
|
|
1076
|
+
retval.extend(deserialize_code)
|
|
1076
1077
|
return retval
|
|
1077
1078
|
|
|
1078
1079
|
def handle_error_response(self, builder: OperationType) -> List[str]:
|
|
@@ -1384,32 +1385,32 @@ class _PagingOperationSerializer(
|
|
|
1384
1385
|
deserialized = f"self._deserialize(\n {deserialize_type}, pipeline_response{pylint_disable}\n)"
|
|
1385
1386
|
retval.append(f" deserialized = {deserialized}")
|
|
1386
1387
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if isinstance(response.type, ModelType) and not response.type.is_public
|
|
1390
|
-
else ""
|
|
1391
|
-
)
|
|
1392
|
-
deserialized = f"_deserialize({response.serialization_type}{pylint_disable}, pipeline_response)"
|
|
1393
|
-
retval.append(
|
|
1394
|
-
f" deserialized: {response.serialization_type} = ({pylint_disable}"
|
|
1395
|
-
)
|
|
1396
|
-
retval.append(f" {deserialized})")
|
|
1388
|
+
# we don't want to generate paging models for DPG
|
|
1389
|
+
retval.append(f" deserialized = {deserialized}")
|
|
1397
1390
|
else:
|
|
1398
1391
|
retval.append(f" deserialized = {deserialized}")
|
|
1399
1392
|
item_name = builder.item_name
|
|
1400
|
-
|
|
1393
|
+
access = (
|
|
1401
1394
|
f".{item_name}"
|
|
1402
|
-
if self.code_model.options["models_mode"]
|
|
1395
|
+
if self.code_model.options["models_mode"] == "msrest"
|
|
1403
1396
|
else f'["{item_name}"]'
|
|
1404
1397
|
)
|
|
1405
|
-
|
|
1398
|
+
list_of_elem_deserialized = ""
|
|
1399
|
+
if self.code_model.options["models_mode"] == "dpg":
|
|
1400
|
+
item_type = builder.item_type.type_annotation(is_operation_file=True)
|
|
1401
|
+
list_of_elem_deserialized = (
|
|
1402
|
+
f"_deserialize({item_type}, deserialized{access})"
|
|
1403
|
+
)
|
|
1404
|
+
else:
|
|
1405
|
+
list_of_elem_deserialized = f"deserialized{access}"
|
|
1406
|
+
retval.append(f" list_of_elem = {list_of_elem_deserialized}")
|
|
1406
1407
|
retval.append(" if cls:")
|
|
1407
1408
|
retval.append(" list_of_elem = cls(list_of_elem) # type: ignore")
|
|
1408
1409
|
|
|
1409
1410
|
continuation_token_name = builder.continuation_token_name
|
|
1410
1411
|
if not continuation_token_name:
|
|
1411
1412
|
cont_token_property = "None"
|
|
1412
|
-
elif self.code_model.options["models_mode"]:
|
|
1413
|
+
elif self.code_model.options["models_mode"] == "msrest":
|
|
1413
1414
|
cont_token_property = f"deserialized.{continuation_token_name} or None"
|
|
1414
1415
|
else:
|
|
1415
1416
|
cont_token_property = (
|
|
@@ -631,7 +631,7 @@ class Serializer(object):
|
|
|
631
631
|
if xml_desc.get("attr", False):
|
|
632
632
|
if xml_ns:
|
|
633
633
|
ET.register_namespace(xml_prefix, xml_ns)
|
|
634
|
-
xml_name = "{}{}".format(xml_ns, xml_name)
|
|
634
|
+
xml_name = "{% raw %}{{{}}}{}{% endraw %}".format(xml_ns, xml_name)
|
|
635
635
|
serialized.set(xml_name, new_attr) # type: ignore
|
|
636
636
|
continue
|
|
637
637
|
if xml_desc.get("text", False):
|
|
@@ -1273,7 +1273,7 @@ def _extract_name_from_internal_type(internal_type):
|
|
|
1273
1273
|
xml_name = internal_type_xml_map.get("name", internal_type.__name__)
|
|
1274
1274
|
xml_ns = internal_type_xml_map.get("ns", None)
|
|
1275
1275
|
if xml_ns:
|
|
1276
|
-
xml_name = "{}{}".format(xml_ns, xml_name)
|
|
1276
|
+
xml_name = "{% raw %}{{{}}}{}{% endraw %}".format(xml_ns, xml_name)
|
|
1277
1277
|
return xml_name
|
|
1278
1278
|
|
|
1279
1279
|
|
|
@@ -1297,7 +1297,7 @@ def xml_key_extractor(attr, attr_desc, data):
|
|
|
1297
1297
|
# Integrate namespace if necessary
|
|
1298
1298
|
xml_ns = xml_desc.get("ns", internal_type_xml_map.get("ns", None))
|
|
1299
1299
|
if xml_ns:
|
|
1300
|
-
xml_name = "{}{}".format(xml_ns, xml_name)
|
|
1300
|
+
xml_name = "{% raw %}{{{}}}{}{% endraw %}".format(xml_ns, xml_name)
|
|
1301
1301
|
|
|
1302
1302
|
# If it's an attribute, that's simple
|
|
1303
1303
|
if xml_desc.get("attr", False):
|
|
@@ -37,7 +37,6 @@ def Process(plugin_name: str, session_id: str) -> bool:
|
|
|
37
37
|
from .stdstream import StdStreamAutorestAPI
|
|
38
38
|
|
|
39
39
|
with contextlib.closing(StdStreamAutorestAPI(session_id)) as stdstream_connection:
|
|
40
|
-
|
|
41
40
|
_LOGGER.debug(
|
|
42
41
|
"Autorest called process with plugin_name '%s' and session_id: '%s'",
|
|
43
42
|
plugin_name,
|
|
@@ -595,6 +595,19 @@ class M4Reformatter(
|
|
|
595
595
|
operation["continuationTokenName"] = yaml_data["extensions"][
|
|
596
596
|
"x-ms-pageable"
|
|
597
597
|
].get("nextLinkName")
|
|
598
|
+
returned_response_object = (
|
|
599
|
+
operation["nextOperation"]["responses"][0]
|
|
600
|
+
if operation.get("nextOperation")
|
|
601
|
+
else operation["responses"][0]
|
|
602
|
+
)
|
|
603
|
+
if self.version_tolerant:
|
|
604
|
+
# if we're in version tolerant, hide the paging model
|
|
605
|
+
returned_response_object["type"]["isPublic"] = False
|
|
606
|
+
operation["itemType"] = next(
|
|
607
|
+
p["type"]
|
|
608
|
+
for p in returned_response_object["type"]["properties"]
|
|
609
|
+
if p["restApiName"] == operation["itemName"]
|
|
610
|
+
)
|
|
598
611
|
if yaml_data["language"]["default"]["paging"].get("nextLinkOperation"):
|
|
599
612
|
operation["nextOperation"] = self.update_operation(
|
|
600
613
|
group_name=group_name,
|
|
@@ -356,26 +356,17 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
356
356
|
code_model: Dict[str, Any],
|
|
357
357
|
yaml_data: Dict[str, Any],
|
|
358
358
|
is_overload: bool = False,
|
|
359
|
+
item_type: Optional[Dict[str, Any]] = None,
|
|
359
360
|
) -> None:
|
|
360
361
|
self.update_operation(code_model, yaml_data, is_overload=is_overload)
|
|
361
362
|
if not yaml_data.get("pagerSync"):
|
|
362
363
|
yaml_data["pagerSync"] = "azure.core.paging.ItemPaged"
|
|
363
364
|
if not yaml_data.get("pagerAsync"):
|
|
364
365
|
yaml_data["pagerAsync"] = "azure.core.async_paging.AsyncItemPaged"
|
|
365
|
-
returned_response_object = (
|
|
366
|
-
yaml_data["nextOperation"]["responses"][0]
|
|
367
|
-
if yaml_data.get("nextOperation")
|
|
368
|
-
else yaml_data["responses"][0]
|
|
369
|
-
)
|
|
370
366
|
if self.version_tolerant:
|
|
371
367
|
# if we're in version tolerant, hide the paging model
|
|
372
|
-
returned_response_object["type"]["isPublic"] = False
|
|
373
368
|
_remove_paging_maxpagesize(yaml_data)
|
|
374
|
-
item_type =
|
|
375
|
-
p["type"]["elementType"]
|
|
376
|
-
for p in returned_response_object["type"]["properties"]
|
|
377
|
-
if p["restApiName"] == (yaml_data.get("itemName") or "value")
|
|
378
|
-
)
|
|
369
|
+
item_type = item_type or yaml_data["itemType"]["elementType"]
|
|
379
370
|
if yaml_data.get("nextOperation"):
|
|
380
371
|
if self.version_tolerant:
|
|
381
372
|
_remove_paging_maxpagesize(yaml_data["nextOperation"])
|
|
@@ -392,7 +383,9 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
392
383
|
update_paging_response(response)
|
|
393
384
|
response["itemType"] = item_type
|
|
394
385
|
for overload in yaml_data.get("overloads", []):
|
|
395
|
-
self.update_paging_operation(
|
|
386
|
+
self.update_paging_operation(
|
|
387
|
+
code_model, overload, is_overload=True, item_type=item_type
|
|
388
|
+
)
|
|
396
389
|
|
|
397
390
|
def update_operation_groups(
|
|
398
391
|
self, code_model: Dict[str, Any], client: Dict[str, Any]
|