@autorest/python 6.2.1 → 6.2.3
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/codegen/models/paging_operation.py +1 -1
- package/autorest/codegen/models/parameter.py +4 -1
- package/autorest/codegen/serializers/builder_serializer.py +3 -1
- package/autorest/codegen/serializers/model_serializer.py +2 -3
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +1 -1
- package/autorest/m4reformatter/__init__.py +50 -41
- package/autorest/preprocess/helpers.py +6 -0
- package/package.json +1 -1
|
@@ -143,7 +143,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
143
143
|
file_import.merge(
|
|
144
144
|
self.get_request_builder_import(self.next_request_builder, async_mode)
|
|
145
145
|
)
|
|
146
|
-
elif
|
|
146
|
+
elif any(p.is_api_version for p in self.client.parameters):
|
|
147
147
|
file_import.add_import("urllib.parse", ImportType.STDLIB)
|
|
148
148
|
file_import.add_submodule_import(
|
|
149
149
|
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
@@ -86,6 +86,7 @@ class _ParameterBase(
|
|
|
86
86
|
self.grouper: bool = self.yaml_data.get("grouper", False)
|
|
87
87
|
self.check_client_input: bool = self.yaml_data.get("checkClientInput", False)
|
|
88
88
|
self.added_on: Optional[str] = self.yaml_data.get("addedOn")
|
|
89
|
+
self.is_api_version: bool = self.yaml_data.get("isApiVersion", False)
|
|
89
90
|
|
|
90
91
|
@property
|
|
91
92
|
def constant(self) -> bool:
|
|
@@ -93,7 +94,9 @@ class _ParameterBase(
|
|
|
93
94
|
Checking to see if it's required, because if not, we don't consider it
|
|
94
95
|
a constant because it can have a value of None.
|
|
95
96
|
"""
|
|
96
|
-
return not self.optional and isinstance(
|
|
97
|
+
return (not self.optional or self.is_api_version) and isinstance(
|
|
98
|
+
self.type, ConstantType
|
|
99
|
+
)
|
|
97
100
|
|
|
98
101
|
@property
|
|
99
102
|
def description(self) -> str:
|
|
@@ -1203,7 +1203,9 @@ class _PagingOperationSerializer(
|
|
|
1203
1203
|
next_link_str = "next_link"
|
|
1204
1204
|
try:
|
|
1205
1205
|
api_version_param = next(
|
|
1206
|
-
p
|
|
1206
|
+
p
|
|
1207
|
+
for p in builder.client.parameters
|
|
1208
|
+
if p.is_api_version and p.location == ParameterLocation.QUERY
|
|
1207
1209
|
)
|
|
1208
1210
|
retval.append("# make call to next link with the client's api-version")
|
|
1209
1211
|
retval.append("_parsed_next_link = urllib.parse.urlparse(next_link)")
|
|
@@ -248,10 +248,9 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
248
248
|
|
|
249
249
|
@staticmethod
|
|
250
250
|
def declare_property(prop: Property) -> List[str]:
|
|
251
|
-
attribute_key = _ModelSerializer.escape_dot(prop.rest_api_name)
|
|
252
251
|
args = []
|
|
253
|
-
if prop.client_name !=
|
|
254
|
-
args.append(f'name="{
|
|
252
|
+
if prop.client_name != prop.rest_api_name or prop.is_discriminator:
|
|
253
|
+
args.append(f'name="{prop.rest_api_name}"')
|
|
255
254
|
if prop.readonly:
|
|
256
255
|
args.append("readonly=True")
|
|
257
256
|
if prop.client_default_value is not None:
|
|
@@ -280,35 +280,6 @@ def update_type(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
280
280
|
return updated_type
|
|
281
281
|
|
|
282
282
|
|
|
283
|
-
def update_parameter_base(
|
|
284
|
-
yaml_data: Dict[str, Any], *, override_client_name: Optional[str] = None
|
|
285
|
-
) -> Dict[str, Any]:
|
|
286
|
-
location = yaml_data["protocol"].get("http", {}).get("in")
|
|
287
|
-
if not location:
|
|
288
|
-
location = "other"
|
|
289
|
-
if location == "uri":
|
|
290
|
-
location = "endpointPath"
|
|
291
|
-
grouped_by = (
|
|
292
|
-
yaml_data["groupedBy"]["language"]["default"]["name"]
|
|
293
|
-
if yaml_data.get("groupedBy")
|
|
294
|
-
else None
|
|
295
|
-
)
|
|
296
|
-
client_name: str = override_client_name or yaml_data["language"]["default"]["name"]
|
|
297
|
-
if grouped_by and client_name[0] != "_":
|
|
298
|
-
# this is an m4 bug, doesn't hide constant grouped params, patching m4 for now
|
|
299
|
-
client_name = "_" + client_name
|
|
300
|
-
return {
|
|
301
|
-
"optional": not yaml_data.get("required", False),
|
|
302
|
-
"description": yaml_data["language"]["default"]["description"],
|
|
303
|
-
"clientName": client_name,
|
|
304
|
-
"restApiName": yaml_data["language"]["default"].get("serializedName"),
|
|
305
|
-
"clientDefaultValue": yaml_data.get("clientDefaultValue"),
|
|
306
|
-
"location": location,
|
|
307
|
-
"groupedBy": grouped_by,
|
|
308
|
-
"checkClientInput": yaml_data.get("checkClientInput", False),
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
283
|
def update_parameter_delimiter(style: Optional[str]) -> Optional[str]:
|
|
313
284
|
if not style:
|
|
314
285
|
return None
|
|
@@ -458,6 +429,45 @@ class M4Reformatter(
|
|
|
458
429
|
or self.version_tolerant
|
|
459
430
|
)
|
|
460
431
|
|
|
432
|
+
def update_parameter_base(
|
|
433
|
+
self, yaml_data: Dict[str, Any], *, override_client_name: Optional[str] = None
|
|
434
|
+
) -> Dict[str, Any]:
|
|
435
|
+
location = yaml_data["protocol"].get("http", {}).get("in")
|
|
436
|
+
if not location:
|
|
437
|
+
location = "other"
|
|
438
|
+
if location == "uri":
|
|
439
|
+
location = "endpointPath"
|
|
440
|
+
grouped_by = (
|
|
441
|
+
yaml_data["groupedBy"]["language"]["default"]["name"]
|
|
442
|
+
if yaml_data.get("groupedBy")
|
|
443
|
+
else None
|
|
444
|
+
)
|
|
445
|
+
client_name: str = (
|
|
446
|
+
override_client_name or yaml_data["language"]["default"]["name"]
|
|
447
|
+
)
|
|
448
|
+
if grouped_by and client_name[0] != "_":
|
|
449
|
+
# this is an m4 bug, doesn't hide constant grouped params, patching m4 for now
|
|
450
|
+
client_name = "_" + client_name
|
|
451
|
+
if yaml_data.get("origin") == "modelerfour:synthesized/api-version":
|
|
452
|
+
yaml_data["inDocstring"] = False
|
|
453
|
+
if self.legacy:
|
|
454
|
+
yaml_data["implementation"] = "Method"
|
|
455
|
+
yaml_data["checkClientInput"] = self.check_client_input
|
|
456
|
+
yaml_data["isApiVersion"] = True
|
|
457
|
+
return {
|
|
458
|
+
"optional": not yaml_data.get("required", False),
|
|
459
|
+
"description": yaml_data["language"]["default"]["description"],
|
|
460
|
+
"clientName": client_name,
|
|
461
|
+
"restApiName": yaml_data["language"]["default"].get("serializedName"),
|
|
462
|
+
"clientDefaultValue": yaml_data.get("clientDefaultValue"),
|
|
463
|
+
"location": location,
|
|
464
|
+
"groupedBy": grouped_by,
|
|
465
|
+
"checkClientInput": yaml_data.get("checkClientInput", False),
|
|
466
|
+
"inDocstring": yaml_data.get("inDocstring", True),
|
|
467
|
+
"isApiVersion": yaml_data.get("isApiVersion", False),
|
|
468
|
+
"implementation": yaml_data.get("implementation"),
|
|
469
|
+
}
|
|
470
|
+
|
|
461
471
|
def update_overloads(
|
|
462
472
|
self,
|
|
463
473
|
group_name: str,
|
|
@@ -646,7 +656,7 @@ class M4Reformatter(
|
|
|
646
656
|
) -> Dict[str, Any]:
|
|
647
657
|
flattened = body_param.get("flattened")
|
|
648
658
|
is_partial_body = body_param.get("isPartialBody")
|
|
649
|
-
param_base = update_parameter_base(body_param)
|
|
659
|
+
param_base = self.update_parameter_base(body_param)
|
|
650
660
|
body_param = copy.deepcopy(param_base)
|
|
651
661
|
body_param["type"] = body_type
|
|
652
662
|
body_param["contentTypes"] = content_types or [
|
|
@@ -811,11 +821,6 @@ class M4Reformatter(
|
|
|
811
821
|
):
|
|
812
822
|
continue
|
|
813
823
|
seen_client_names.add(client_name)
|
|
814
|
-
if param.get("origin") == "modelerfour:synthesized/api-version":
|
|
815
|
-
param["inDocstring"] = False
|
|
816
|
-
if self.legacy:
|
|
817
|
-
param["implementation"] = "Method"
|
|
818
|
-
param["checkClientInput"] = self.check_client_input
|
|
819
824
|
if has_flattened_body and param.get("targetProperty"):
|
|
820
825
|
retval.append(self.update_flattened_parameter(param, body_parameter))
|
|
821
826
|
continue
|
|
@@ -910,7 +915,7 @@ class M4Reformatter(
|
|
|
910
915
|
in_overload: bool = False,
|
|
911
916
|
in_overriden: bool = False,
|
|
912
917
|
) -> Dict[str, Any]:
|
|
913
|
-
param_base = update_parameter_base(
|
|
918
|
+
param_base = self.update_parameter_base(
|
|
914
919
|
yaml_data, override_client_name=override_client_name
|
|
915
920
|
)
|
|
916
921
|
type = get_type(yaml_data["schema"])
|
|
@@ -948,13 +953,17 @@ class M4Reformatter(
|
|
|
948
953
|
|
|
949
954
|
client_name = "base_url" if self.legacy else "endpoint"
|
|
950
955
|
global_parameter["language"]["default"]["description"] = "Service URL."
|
|
951
|
-
elif
|
|
956
|
+
elif (
|
|
957
|
+
global_parameter.get("origin") == "modelerfour:synthesized/api-version"
|
|
958
|
+
):
|
|
952
959
|
self.check_client_input = True
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
global_parameter, override_client_name=client_name
|
|
956
|
-
)
|
|
960
|
+
param = self.update_parameter(
|
|
961
|
+
global_parameter, override_client_name=client_name
|
|
957
962
|
)
|
|
963
|
+
if global_parameter.get("origin") == "modelerfour:synthesized/api-version":
|
|
964
|
+
param["implementation"] = "Client"
|
|
965
|
+
param["checkClientInput"] = False
|
|
966
|
+
global_params.append(param)
|
|
958
967
|
return global_params
|
|
959
968
|
|
|
960
969
|
def get_token_credential(self, credential_scopes: List[str]) -> Dict[str, Any]:
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Any, Dict
|
|
7
|
+
import re
|
|
7
8
|
from .python_mappings import PadType, RESERVED_WORDS, REDEFINED_BUILTINS
|
|
8
9
|
|
|
9
10
|
|
|
@@ -12,6 +13,7 @@ def pad_reserved_words(name: str, pad_type: PadType):
|
|
|
12
13
|
if not name:
|
|
13
14
|
# we'll pass in empty operation groups sometime etc.
|
|
14
15
|
return name
|
|
16
|
+
name = pad_special_chars(name)
|
|
15
17
|
name_prefix = "_" if name[0] == "_" else ""
|
|
16
18
|
name = name[1:] if name[0] == "_" else name
|
|
17
19
|
if name.lower() in RESERVED_WORDS[pad_type]:
|
|
@@ -22,3 +24,7 @@ def pad_reserved_words(name: str, pad_type: PadType):
|
|
|
22
24
|
def add_redefined_builtin_info(name: str, yaml_data: Dict[str, Any]) -> None:
|
|
23
25
|
if name in REDEFINED_BUILTINS:
|
|
24
26
|
yaml_data["pylintDisable"] = "redefined-builtin"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def pad_special_chars(name: str) -> str:
|
|
30
|
+
return re.sub(r"[^A-z0-9_]", "_", name)
|