@autorest/python 6.4.10 → 6.4.12
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/client.py +8 -2
- package/autorest/codegen/models/code_model.py +4 -1
- package/autorest/codegen/models/model_type.py +4 -5
- package/autorest/codegen/models/operation.py +0 -2
- package/autorest/codegen/models/paging_operation.py +17 -10
- package/autorest/codegen/models/parameter.py +5 -5
- package/autorest/codegen/models/property.py +1 -1
- package/autorest/codegen/models/request_builder.py +0 -7
- package/autorest/codegen/models/response.py +8 -1
- package/autorest/codegen/serializers/__init__.py +11 -1
- package/autorest/codegen/serializers/builder_serializer.py +11 -9
- package/autorest/codegen/serializers/model_serializer.py +3 -3
- package/autorest/codegen/serializers/parameter_serializer.py +2 -2
- package/autorest/codegen/serializers/sample_serializer.py +22 -12
- package/autorest/codegen/templates/client.py.jinja2 +1 -1
- package/autorest/codegen/templates/sample.py.jinja2 +1 -1
- package/autorest/m4reformatter/__init__.py +9 -9
- package/autorest/preprocess/__init__.py +7 -5
- package/package.json +3 -3
|
@@ -146,8 +146,14 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
146
146
|
retval = add_to_pylint_disable("", "client-accepts-api-version-keyword")
|
|
147
147
|
if len(self.operation_groups) > 6:
|
|
148
148
|
retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
return retval
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def url_pylint_disable(self) -> str:
|
|
153
|
+
# if the url is too long
|
|
154
|
+
retval = ""
|
|
155
|
+
if len(self.url) > 85:
|
|
156
|
+
retval = add_to_pylint_disable(retval, "line-too-long")
|
|
151
157
|
return retval
|
|
152
158
|
|
|
153
159
|
@property
|
|
@@ -184,7 +184,10 @@ class CodeModel: # pylint: disable=too-many-public-methods
|
|
|
184
184
|
"""All of the model types in this class"""
|
|
185
185
|
if not self._model_types:
|
|
186
186
|
self._model_types = [
|
|
187
|
-
t
|
|
187
|
+
t
|
|
188
|
+
for t in self.types_map.values()
|
|
189
|
+
if isinstance(t, ModelType)
|
|
190
|
+
and not (self.options["models_mode"] == "dpg" and t.page_result_model)
|
|
188
191
|
]
|
|
189
192
|
return self._model_types
|
|
190
193
|
|
|
@@ -74,6 +74,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
74
74
|
self._got_polymorphic_subtypes = False
|
|
75
75
|
self.internal: bool = self.yaml_data.get("internal", False)
|
|
76
76
|
self.snake_case_name: str = self.yaml_data["snakeCaseName"]
|
|
77
|
+
self.page_result_model: bool = self.yaml_data.get("pageResultModel", False)
|
|
77
78
|
|
|
78
79
|
@property
|
|
79
80
|
def is_xml(self) -> bool:
|
|
@@ -129,7 +130,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
129
130
|
# don't add additional properties, because there's not really a concept of
|
|
130
131
|
# additional properties in the template
|
|
131
132
|
representation = {
|
|
132
|
-
f'"{prop.
|
|
133
|
+
f'"{prop.wire_name}"': prop.get_json_template_representation(
|
|
133
134
|
optional=optional,
|
|
134
135
|
client_default_value_declaration=client_default_value_declaration,
|
|
135
136
|
description=description,
|
|
@@ -142,16 +143,14 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
142
143
|
}
|
|
143
144
|
if self.discriminator and self.discriminator_value:
|
|
144
145
|
representation[
|
|
145
|
-
f'"{self.discriminator.
|
|
146
|
+
f'"{self.discriminator.wire_name}"'
|
|
146
147
|
] = f'"{self.discriminator_value}"'
|
|
147
148
|
|
|
148
149
|
# once we've finished, we want to reset created_json_template_representation to false
|
|
149
150
|
# so we can call it again
|
|
150
151
|
self._created_json_template_representation = False
|
|
151
152
|
optional_keys = [
|
|
152
|
-
f'"{p.
|
|
153
|
-
for p in self.properties
|
|
154
|
-
if getattr(p, "optional", False)
|
|
153
|
+
f'"{p.wire_name}"' for p in self.properties if getattr(p, "optional", False)
|
|
155
154
|
]
|
|
156
155
|
return OrderedDict(
|
|
157
156
|
sorted(
|
|
@@ -130,8 +130,6 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
130
130
|
if self.response_type_annotation(async_mode=False) == "None":
|
|
131
131
|
# doesn't matter if it's async or not
|
|
132
132
|
retval = add_to_pylint_disable(retval, "inconsistent-return-statements")
|
|
133
|
-
if len(self.name) > 40:
|
|
134
|
-
retval = add_to_pylint_disable(retval, "name-too-long")
|
|
135
133
|
return retval
|
|
136
134
|
|
|
137
135
|
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
@@ -62,17 +62,17 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
62
62
|
self.pager_sync: str = yaml_data["pagerSync"]
|
|
63
63
|
self.pager_async: str = yaml_data["pagerAsync"]
|
|
64
64
|
|
|
65
|
-
def _get_attr_name(self,
|
|
65
|
+
def _get_attr_name(self, wire_name: str) -> str:
|
|
66
66
|
response = self.responses[0]
|
|
67
67
|
try:
|
|
68
68
|
return next(
|
|
69
69
|
p.client_name
|
|
70
70
|
for p in cast(ModelType, response.type).properties
|
|
71
|
-
if p.
|
|
71
|
+
if p.wire_name == wire_name
|
|
72
72
|
)
|
|
73
73
|
except StopIteration as exc:
|
|
74
74
|
raise ValueError(
|
|
75
|
-
f"Can't find a matching property in response for {
|
|
75
|
+
f"Can't find a matching property in response for {wire_name}"
|
|
76
76
|
) from exc
|
|
77
77
|
|
|
78
78
|
def get_pager(self, async_mode: bool) -> str:
|
|
@@ -80,21 +80,21 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
80
80
|
|
|
81
81
|
@property
|
|
82
82
|
def continuation_token_name(self) -> Optional[str]:
|
|
83
|
-
|
|
84
|
-
if not
|
|
83
|
+
wire_name = self.yaml_data["continuationTokenName"]
|
|
84
|
+
if not wire_name:
|
|
85
85
|
# That's an ok scenario, it just means no next page possible
|
|
86
86
|
return None
|
|
87
87
|
if self.code_model.options["models_mode"] == "msrest":
|
|
88
|
-
return self._get_attr_name(
|
|
89
|
-
return
|
|
88
|
+
return self._get_attr_name(wire_name)
|
|
89
|
+
return wire_name
|
|
90
90
|
|
|
91
91
|
@property
|
|
92
92
|
def item_name(self) -> str:
|
|
93
|
-
|
|
93
|
+
wire_name = self.yaml_data["itemName"]
|
|
94
94
|
if self.code_model.options["models_mode"] == "msrest":
|
|
95
95
|
# we don't use the paging model for dpg
|
|
96
|
-
return self._get_attr_name(
|
|
97
|
-
return
|
|
96
|
+
return self._get_attr_name(wire_name)
|
|
97
|
+
return wire_name
|
|
98
98
|
|
|
99
99
|
@property
|
|
100
100
|
def item_type(self) -> ModelType:
|
|
@@ -156,7 +156,14 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
156
156
|
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
157
157
|
)
|
|
158
158
|
if self.code_model.options["models_mode"] == "dpg":
|
|
159
|
+
relative_path = "..." if async_mode else ".."
|
|
159
160
|
file_import.merge(self.item_type.imports(**kwargs))
|
|
161
|
+
if self.default_error_deserialization or any(
|
|
162
|
+
r.type for r in self.responses
|
|
163
|
+
):
|
|
164
|
+
file_import.add_submodule_import(
|
|
165
|
+
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
|
|
166
|
+
)
|
|
160
167
|
return file_import
|
|
161
168
|
|
|
162
169
|
|
|
@@ -64,7 +64,7 @@ class _ParameterBase(
|
|
|
64
64
|
type: BaseType,
|
|
65
65
|
) -> None:
|
|
66
66
|
super().__init__(yaml_data, code_model)
|
|
67
|
-
self.
|
|
67
|
+
self.wire_name: str = yaml_data["wireName"]
|
|
68
68
|
self.client_name: str = self.yaml_data["clientName"]
|
|
69
69
|
self.optional: bool = self.yaml_data["optional"]
|
|
70
70
|
self.location: ParameterLocation = self.yaml_data["location"]
|
|
@@ -342,7 +342,7 @@ class Parameter(_ParameterBase):
|
|
|
342
342
|
|
|
343
343
|
@property
|
|
344
344
|
def in_method_signature(self) -> bool:
|
|
345
|
-
return not (self.
|
|
345
|
+
return not (self.wire_name == "Accept" or self.grouped_by or self.flattened)
|
|
346
346
|
|
|
347
347
|
@property
|
|
348
348
|
def full_client_name(self) -> str:
|
|
@@ -356,7 +356,7 @@ class Parameter(_ParameterBase):
|
|
|
356
356
|
|
|
357
357
|
@property
|
|
358
358
|
def is_content_type(self) -> bool:
|
|
359
|
-
return bool(self.
|
|
359
|
+
return bool(self.wire_name) and self.wire_name.lower() == "content-type"
|
|
360
360
|
|
|
361
361
|
@property
|
|
362
362
|
def method_location( # pylint: disable=too-many-return-statements
|
|
@@ -399,7 +399,7 @@ class ClientParameter(Parameter):
|
|
|
399
399
|
|
|
400
400
|
@property
|
|
401
401
|
def is_host(self) -> bool:
|
|
402
|
-
return self.
|
|
402
|
+
return self.wire_name == "$host"
|
|
403
403
|
|
|
404
404
|
@property
|
|
405
405
|
def method_location(self) -> ParameterMethodLocation:
|
|
@@ -423,7 +423,7 @@ class ConfigParameter(Parameter):
|
|
|
423
423
|
|
|
424
424
|
@property
|
|
425
425
|
def is_host(self) -> bool:
|
|
426
|
-
return self.
|
|
426
|
+
return self.wire_name == "$host"
|
|
427
427
|
|
|
428
428
|
@property
|
|
429
429
|
def method_location(self) -> ParameterMethodLocation:
|
|
@@ -24,7 +24,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
24
24
|
type: BaseType,
|
|
25
25
|
) -> None:
|
|
26
26
|
super().__init__(yaml_data, code_model)
|
|
27
|
-
self.
|
|
27
|
+
self.wire_name: str = self.yaml_data["wireName"]
|
|
28
28
|
self.client_name: str = self.yaml_data["clientName"]
|
|
29
29
|
self.type = type
|
|
30
30
|
self.optional: bool = self.yaml_data["optional"]
|
|
@@ -16,7 +16,6 @@ from typing import (
|
|
|
16
16
|
from abc import abstractmethod
|
|
17
17
|
|
|
18
18
|
from .base_builder import BaseBuilder
|
|
19
|
-
from .utils import add_to_pylint_disable
|
|
20
19
|
from .parameter_list import (
|
|
21
20
|
RequestBuilderParameterList,
|
|
22
21
|
OverloadedRequestBuilderParameterList,
|
|
@@ -57,12 +56,6 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
57
56
|
self.method: str = yaml_data["method"]
|
|
58
57
|
self.want_tracing = False
|
|
59
58
|
|
|
60
|
-
@property
|
|
61
|
-
def pylint_disable(self) -> str:
|
|
62
|
-
if len(self.name) > 40:
|
|
63
|
-
return add_to_pylint_disable("", "name-too-long")
|
|
64
|
-
return ""
|
|
65
|
-
|
|
66
59
|
def response_type_annotation(self, **kwargs) -> str:
|
|
67
60
|
return "HttpRequest"
|
|
68
61
|
|
|
@@ -26,7 +26,7 @@ class ResponseHeader(BaseModel):
|
|
|
26
26
|
type: BaseType,
|
|
27
27
|
) -> None:
|
|
28
28
|
super().__init__(yaml_data, code_model)
|
|
29
|
-
self.
|
|
29
|
+
self.wire_name: str = yaml_data["wireName"]
|
|
30
30
|
self.type = type
|
|
31
31
|
|
|
32
32
|
@property
|
|
@@ -59,6 +59,13 @@ class Response(BaseModel):
|
|
|
59
59
|
self.type = type
|
|
60
60
|
self.nullable = yaml_data.get("nullable")
|
|
61
61
|
|
|
62
|
+
@property
|
|
63
|
+
def result_property(self) -> str:
|
|
64
|
+
field = self.yaml_data.get("resultProperty")
|
|
65
|
+
if field:
|
|
66
|
+
return f'.get("{field}")'
|
|
67
|
+
return ""
|
|
68
|
+
|
|
62
69
|
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
63
70
|
if self.type:
|
|
64
71
|
self.type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
@@ -48,6 +48,16 @@ _PACKAGE_FILES = [
|
|
|
48
48
|
|
|
49
49
|
_REGENERATE_FILES = {"setup.py", "MANIFEST.in"}
|
|
50
50
|
|
|
51
|
+
# extract sub folders. For example, source_file_path is like:
|
|
52
|
+
# "xxx/resource-manager/Microsoft.XX/stable/2023-04-01/examples/Compute/createOrUpdate/AKSCompute.json",
|
|
53
|
+
# and we want to extract the sub folders after "examples/", which is "compute/create_or_update"
|
|
54
|
+
def _sample_output_path(source_file_path: str) -> Path:
|
|
55
|
+
posix_path = Path(source_file_path).as_posix()
|
|
56
|
+
if "examples/" in posix_path:
|
|
57
|
+
after_examples = Path(posix_path.split("examples/", maxsplit=1)[-1]).parent
|
|
58
|
+
return Path("/".join([to_snake_case(i) for i in after_examples.parts]))
|
|
59
|
+
return Path("")
|
|
60
|
+
|
|
51
61
|
|
|
52
62
|
class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
53
63
|
def __init__(
|
|
@@ -568,7 +578,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
568
578
|
file_name = to_snake_case(extract_sample_name(file)) + ".py"
|
|
569
579
|
try:
|
|
570
580
|
self.write_file(
|
|
571
|
-
out_path / file_name,
|
|
581
|
+
out_path / _sample_output_path(file) / file_name,
|
|
572
582
|
SampleSerializer(
|
|
573
583
|
code_model=self.code_model,
|
|
574
584
|
env=env,
|
|
@@ -200,7 +200,7 @@ def _serialize_multipart_body(builder: BuilderType) -> List[str]:
|
|
|
200
200
|
retval.append("# Construct form data")
|
|
201
201
|
retval.append(f"_{body_param.client_name} = {{")
|
|
202
202
|
for param in body_param.entries:
|
|
203
|
-
retval.append(f' "{param.
|
|
203
|
+
retval.append(f' "{param.wire_name}": {param.client_name},')
|
|
204
204
|
retval.append("}")
|
|
205
205
|
return retval
|
|
206
206
|
|
|
@@ -396,7 +396,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
396
396
|
# we just assume one kind of polymorphic body for input
|
|
397
397
|
discriminator_name = cast(
|
|
398
398
|
Property, polymorphic_subtypes[0].discriminator
|
|
399
|
-
).
|
|
399
|
+
).wire_name
|
|
400
400
|
template.append(
|
|
401
401
|
"# The input is polymorphic. The following are possible polymorphic "
|
|
402
402
|
f'inputs based off discriminator "{discriminator_name}":'
|
|
@@ -425,7 +425,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
425
425
|
def _serialize_parameter(self, param: Parameter, kwarg_name: str) -> List[str]:
|
|
426
426
|
set_parameter = "_{}['{}'] = {}".format(
|
|
427
427
|
kwarg_name,
|
|
428
|
-
param.
|
|
428
|
+
param.wire_name,
|
|
429
429
|
self.parameter_serializer.serialize_parameter(param, self.serializer_name),
|
|
430
430
|
)
|
|
431
431
|
if not param.optional:
|
|
@@ -480,7 +480,7 @@ class RequestBuilderSerializer(
|
|
|
480
480
|
if param.location == ParameterLocation.HEADER
|
|
481
481
|
else "params"
|
|
482
482
|
)
|
|
483
|
-
return f"_{kwarg_dict}.pop('{param.
|
|
483
|
+
return f"_{kwarg_dict}.pop('{param.wire_name}', {param_type.get_declaration()})"
|
|
484
484
|
return f"{param_type.get_declaration()}"
|
|
485
485
|
|
|
486
486
|
return [
|
|
@@ -614,7 +614,7 @@ class _OperationSerializer(
|
|
|
614
614
|
# we just assume one kind of polymorphic body for input
|
|
615
615
|
discriminator_name = cast(
|
|
616
616
|
Property, polymorphic_subtypes[0].discriminator
|
|
617
|
-
).
|
|
617
|
+
).wire_name
|
|
618
618
|
retval.append(
|
|
619
619
|
"# The response is polymorphic. The following are possible polymorphic "
|
|
620
620
|
f'responses based off discriminator "{discriminator_name}":'
|
|
@@ -792,7 +792,7 @@ class _OperationSerializer(
|
|
|
792
792
|
and not next(
|
|
793
793
|
p
|
|
794
794
|
for p in builder.parameters
|
|
795
|
-
if p.
|
|
795
|
+
if p.wire_name.lower() == "content-type"
|
|
796
796
|
).optional
|
|
797
797
|
):
|
|
798
798
|
content_types = "'" + "', '".join(body_param.content_types) + "'"
|
|
@@ -1043,8 +1043,8 @@ class _OperationSerializer(
|
|
|
1043
1043
|
) -> List[str]:
|
|
1044
1044
|
retval: List[str] = [
|
|
1045
1045
|
(
|
|
1046
|
-
f"response_headers['{response_header.
|
|
1047
|
-
f"'{response_header.serialization_type}', response.headers.get('{response_header.
|
|
1046
|
+
f"response_headers['{response_header.wire_name}']=self._deserialize("
|
|
1047
|
+
f"'{response_header.serialization_type}', response.headers.get('{response_header.wire_name}'))"
|
|
1048
1048
|
)
|
|
1049
1049
|
for response_header in response.headers
|
|
1050
1050
|
]
|
|
@@ -1075,7 +1075,9 @@ class _OperationSerializer(
|
|
|
1075
1075
|
deserialize_code.append(
|
|
1076
1076
|
f" {response.type.type_annotation(is_operation_file=True)},{pylint_disable}"
|
|
1077
1077
|
)
|
|
1078
|
-
deserialize_code.append(
|
|
1078
|
+
deserialize_code.append(
|
|
1079
|
+
f" response.json(){response.result_property}"
|
|
1080
|
+
)
|
|
1079
1081
|
deserialize_code.append(")")
|
|
1080
1082
|
else:
|
|
1081
1083
|
deserialized_value = (
|
|
@@ -188,7 +188,7 @@ class MsrestModelSerializer(_ModelSerializer):
|
|
|
188
188
|
_ModelSerializer.escape_dot(n) for n in prop.flattened_names
|
|
189
189
|
)
|
|
190
190
|
else:
|
|
191
|
-
attribute_key = _ModelSerializer.escape_dot(prop.
|
|
191
|
+
attribute_key = _ModelSerializer.escape_dot(prop.wire_name)
|
|
192
192
|
if prop.type.xml_serialization_ctxt:
|
|
193
193
|
xml_metadata = f", 'xml': {{{prop.type.xml_serialization_ctxt}}}"
|
|
194
194
|
else:
|
|
@@ -253,8 +253,8 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
253
253
|
@staticmethod
|
|
254
254
|
def declare_property(prop: Property) -> str:
|
|
255
255
|
args = []
|
|
256
|
-
if prop.client_name != prop.
|
|
257
|
-
args.append(f'name="{prop.
|
|
256
|
+
if prop.client_name != prop.wire_name or prop.is_discriminator:
|
|
257
|
+
args.append(f'name="{prop.wire_name}"')
|
|
258
258
|
if prop.readonly:
|
|
259
259
|
args.append("readonly=True")
|
|
260
260
|
if prop.client_default_value is not None:
|
|
@@ -95,7 +95,7 @@ class ParameterSerializer:
|
|
|
95
95
|
retval.extend(
|
|
96
96
|
[
|
|
97
97
|
' "{}": {},'.format(
|
|
98
|
-
path_parameter.
|
|
98
|
+
path_parameter.wire_name,
|
|
99
99
|
self.serialize_parameter(path_parameter, serializer_name),
|
|
100
100
|
)
|
|
101
101
|
for path_parameter in parameters
|
|
@@ -143,7 +143,7 @@ class ParameterSerializer:
|
|
|
143
143
|
else "params"
|
|
144
144
|
)
|
|
145
145
|
default_value = (
|
|
146
|
-
f"_{kwarg_dict}.pop('{kwarg.
|
|
146
|
+
f"_{kwarg_dict}.pop('{kwarg.wire_name}', {default_value})"
|
|
147
147
|
)
|
|
148
148
|
retval.append(
|
|
149
149
|
f"{kwarg.client_name}: {type_annot} = kwargs.pop('{kwarg.client_name}', "
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# license information.
|
|
6
6
|
# --------------------------------------------------------------------------
|
|
7
7
|
import logging
|
|
8
|
-
from typing import Dict, Any, Union
|
|
8
|
+
from typing import Dict, Any, Union, Tuple
|
|
9
9
|
from jinja2 import Environment
|
|
10
10
|
|
|
11
11
|
from autorest.codegen.models.credential_types import AzureKeyCredentialType
|
|
@@ -58,7 +58,7 @@ class SampleSerializer:
|
|
|
58
58
|
if (
|
|
59
59
|
not param.client_default_value
|
|
60
60
|
and not param.optional
|
|
61
|
-
and param.
|
|
61
|
+
and param.wire_name in self.sample["parameters"]
|
|
62
62
|
):
|
|
63
63
|
imports.merge(param.type.imports_for_sample())
|
|
64
64
|
return FileImportSerializer(imports, True)
|
|
@@ -82,7 +82,7 @@ class SampleSerializer:
|
|
|
82
82
|
client_params = {
|
|
83
83
|
p.client_name: special_param.get(
|
|
84
84
|
p.client_name,
|
|
85
|
-
f'"{self.sample["parameters"].get(p.
|
|
85
|
+
f'"{self.sample["parameters"].get(p.wire_name) or p.client_name.upper()}"',
|
|
86
86
|
)
|
|
87
87
|
for p in params_positional
|
|
88
88
|
}
|
|
@@ -107,7 +107,7 @@ class SampleSerializer:
|
|
|
107
107
|
failure_info = "fail to find required param named {}"
|
|
108
108
|
operation_params = {}
|
|
109
109
|
for param in params_positional:
|
|
110
|
-
name = param.
|
|
110
|
+
name = param.wire_name
|
|
111
111
|
param_value = self.sample["parameters"].get(name)
|
|
112
112
|
if not param.optional:
|
|
113
113
|
if not param_value:
|
|
@@ -122,17 +122,25 @@ class SampleSerializer:
|
|
|
122
122
|
return ""
|
|
123
123
|
return f".{self.operation_group.property_name}"
|
|
124
124
|
|
|
125
|
-
def _operation_result(self) -> str:
|
|
125
|
+
def _operation_result(self) -> Tuple[str, str]:
|
|
126
|
+
is_response_none = "None" in self.operation.response_type_annotation(
|
|
127
|
+
async_mode=False
|
|
128
|
+
)
|
|
126
129
|
lro = ".result()"
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
if is_response_none:
|
|
131
|
+
paging, normal_print, return_var = "", "", ""
|
|
132
|
+
else:
|
|
133
|
+
paging = "\n for item in response:\n print(item)"
|
|
134
|
+
normal_print = "\n print(response)"
|
|
135
|
+
return_var = "response = "
|
|
136
|
+
|
|
129
137
|
if self.operation.operation_type == "paging":
|
|
130
|
-
return paging
|
|
138
|
+
return paging, return_var
|
|
131
139
|
if self.operation.operation_type == "lro":
|
|
132
|
-
return lro + normal_print
|
|
140
|
+
return lro + normal_print, return_var
|
|
133
141
|
if self.operation.operation_type == "lropaging":
|
|
134
|
-
return lro + paging
|
|
135
|
-
return normal_print
|
|
142
|
+
return lro + paging, return_var
|
|
143
|
+
return normal_print, return_var
|
|
136
144
|
|
|
137
145
|
def _operation_name(self) -> str:
|
|
138
146
|
return f".{self.operation.name}"
|
|
@@ -144,14 +152,16 @@ class SampleSerializer:
|
|
|
144
152
|
return ""
|
|
145
153
|
|
|
146
154
|
def serialize(self) -> str:
|
|
155
|
+
operation_result, return_var = self._operation_result()
|
|
147
156
|
return self.env.get_template("sample.py.jinja2").render(
|
|
148
157
|
code_model=self.code_model,
|
|
149
158
|
file_name=self.file_name,
|
|
150
|
-
operation_result=
|
|
159
|
+
operation_result=operation_result,
|
|
151
160
|
operation_params=self._operation_params(),
|
|
152
161
|
operation_group_name=self._operation_group_name(),
|
|
153
162
|
operation_name=self._operation_name(),
|
|
154
163
|
imports=self._imports(),
|
|
155
164
|
client_params=self._client_params(),
|
|
156
165
|
origin_file=self._origin_file(),
|
|
166
|
+
return_var=return_var,
|
|
157
167
|
)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
super().__init__()
|
|
8
8
|
{% endif %}
|
|
9
9
|
{% if client.has_parameterized_host %}
|
|
10
|
-
{{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
|
|
10
|
+
{{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}{{ client.url_pylint_disable }}
|
|
11
11
|
{% endif %}
|
|
12
12
|
{{ serializer.initialize_config() }}
|
|
13
13
|
{{ serializer.initialize_pipeline_client(async_mode) }}
|
|
@@ -31,7 +31,7 @@ def main():
|
|
|
31
31
|
{% endfor %}
|
|
32
32
|
)
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
{{ return_var }}client{{ operation_group_name }}{{ operation_name }}(
|
|
35
35
|
{% for key, value in operation_params.items() %}
|
|
36
36
|
{{ key }}={{ value|indent(8) }},
|
|
37
37
|
{% endfor %}
|
|
@@ -117,7 +117,7 @@ def update_property(
|
|
|
117
117
|
client_name = "additional_properties1"
|
|
118
118
|
return {
|
|
119
119
|
"clientName": client_name,
|
|
120
|
-
"
|
|
120
|
+
"wireName": yaml_data["serializedName"],
|
|
121
121
|
"flattenedNames": yaml_data.get("flattenedNames", []),
|
|
122
122
|
"type": update_type(yaml_data["schema"]),
|
|
123
123
|
"optional": not yaml_data.get("required"),
|
|
@@ -158,7 +158,7 @@ def fill_model(
|
|
|
158
158
|
properties.append(
|
|
159
159
|
{
|
|
160
160
|
"clientName": "additional_properties",
|
|
161
|
-
"
|
|
161
|
+
"wireName": "",
|
|
162
162
|
"type": update_type(dict_parents[0]),
|
|
163
163
|
"optional": True,
|
|
164
164
|
"description": "Unmatched properties from the message are deserialized to this collection.",
|
|
@@ -333,7 +333,7 @@ def filter_out_paging_next_operation(
|
|
|
333
333
|
|
|
334
334
|
def update_response_header(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
335
335
|
return {
|
|
336
|
-
"
|
|
336
|
+
"wireName": yaml_data["header"],
|
|
337
337
|
"type": update_type(yaml_data["schema"]),
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -470,7 +470,7 @@ class M4Reformatter(
|
|
|
470
470
|
"optional": not yaml_data.get("required", False),
|
|
471
471
|
"description": yaml_data["language"]["default"]["description"],
|
|
472
472
|
"clientName": client_name,
|
|
473
|
-
"
|
|
473
|
+
"wireName": yaml_data["language"]["default"].get("serializedName"),
|
|
474
474
|
"clientDefaultValue": yaml_data.get("clientDefaultValue"),
|
|
475
475
|
"location": location,
|
|
476
476
|
"groupedBy": grouped_by,
|
|
@@ -499,7 +499,7 @@ class M4Reformatter(
|
|
|
499
499
|
group_name, yaml_data, body_type, content_types=content_types
|
|
500
500
|
)
|
|
501
501
|
for parameter in overload["parameters"]:
|
|
502
|
-
if parameter["
|
|
502
|
+
if parameter["wireName"].lower() == "content-type":
|
|
503
503
|
parameter["clientDefaultValue"] = overload["bodyParameter"][
|
|
504
504
|
"defaultContentType"
|
|
505
505
|
]
|
|
@@ -606,7 +606,7 @@ class M4Reformatter(
|
|
|
606
606
|
operation["itemType"] = next(
|
|
607
607
|
p["type"]
|
|
608
608
|
for p in returned_response_object["type"]["properties"]
|
|
609
|
-
if p["
|
|
609
|
+
if p["wireName"] == operation["itemName"]
|
|
610
610
|
)
|
|
611
611
|
if yaml_data["language"]["default"]["paging"].get("nextLinkOperation"):
|
|
612
612
|
operation["nextOperation"] = self.update_operation(
|
|
@@ -724,7 +724,7 @@ class M4Reformatter(
|
|
|
724
724
|
body_param["clientDefaultValue"] = body_type["value"]
|
|
725
725
|
body_param["flattened"] = flattened
|
|
726
726
|
body_param["isPartialBody"] = is_partial_body
|
|
727
|
-
body_param["
|
|
727
|
+
body_param["wireName"] = body_param["wireName"] or to_lower_camel_case(
|
|
728
728
|
body_param["clientName"]
|
|
729
729
|
)
|
|
730
730
|
return body_param
|
|
@@ -742,7 +742,7 @@ class M4Reformatter(
|
|
|
742
742
|
"optional": not first_value.get("required", False),
|
|
743
743
|
"description": description,
|
|
744
744
|
"clientName": client_name,
|
|
745
|
-
"
|
|
745
|
+
"wireName": client_name,
|
|
746
746
|
"clientDefaultValue": None,
|
|
747
747
|
"location": "Method",
|
|
748
748
|
"type": KNOWN_TYPES["anydict"],
|
|
@@ -1120,7 +1120,7 @@ class M4Reformatter(
|
|
|
1120
1120
|
"description": "Credential needed for the client to connect to Azure.",
|
|
1121
1121
|
"clientName": "credential",
|
|
1122
1122
|
"location": "other",
|
|
1123
|
-
"
|
|
1123
|
+
"wireName": "credential",
|
|
1124
1124
|
"implementation": "Client",
|
|
1125
1125
|
"skipUrlEncoding": True,
|
|
1126
1126
|
"inOverload": False,
|
|
@@ -85,7 +85,7 @@ def add_overload(
|
|
|
85
85
|
|
|
86
86
|
# update content type to be an overloads content type
|
|
87
87
|
content_type_param = next(
|
|
88
|
-
p for p in overload["parameters"] if p["
|
|
88
|
+
p for p in overload["parameters"] if p["wireName"].lower() == "content-type"
|
|
89
89
|
)
|
|
90
90
|
content_type_param["inOverload"] = True
|
|
91
91
|
content_type_param["inDocstring"] = True
|
|
@@ -126,7 +126,7 @@ def add_overloads_for_body_param(yaml_data: Dict[str, Any]) -> None:
|
|
|
126
126
|
add_overload(yaml_data, body_type, for_flatten_params=True)
|
|
127
127
|
)
|
|
128
128
|
content_type_param = next(
|
|
129
|
-
p for p in yaml_data["parameters"] if p["
|
|
129
|
+
p for p in yaml_data["parameters"] if p["wireName"].lower() == "content-type"
|
|
130
130
|
)
|
|
131
131
|
content_type_param["inOverload"] = False
|
|
132
132
|
content_type_param["inOverriden"] = True
|
|
@@ -143,7 +143,7 @@ def _remove_paging_maxpagesize(yaml_data: Dict[str, Any]) -> None:
|
|
|
143
143
|
yaml_data["parameters"] = [
|
|
144
144
|
p
|
|
145
145
|
for p in yaml_data.get("parameters", [])
|
|
146
|
-
if p["
|
|
146
|
+
if p["wireName"].lower() not in ["maxpagesize", "$maxpagesize"]
|
|
147
147
|
]
|
|
148
148
|
|
|
149
149
|
|
|
@@ -212,7 +212,9 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
212
212
|
def update_types(self, yaml_data: List[Dict[str, Any]]) -> None:
|
|
213
213
|
for type in yaml_data:
|
|
214
214
|
for property in type.get("properties", []):
|
|
215
|
-
property["description"] = update_description(
|
|
215
|
+
property["description"] = update_description(
|
|
216
|
+
property.get("description", "")
|
|
217
|
+
)
|
|
216
218
|
property["clientName"] = self.pad_reserved_words(
|
|
217
219
|
property["clientName"].lower(), PadType.PROPERTY
|
|
218
220
|
)
|
|
@@ -264,7 +266,7 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
264
266
|
return self.update_operation
|
|
265
267
|
|
|
266
268
|
def update_parameter(self, yaml_data: Dict[str, Any]) -> None:
|
|
267
|
-
yaml_data["description"] = update_description(yaml_data
|
|
269
|
+
yaml_data["description"] = update_description(yaml_data.get("description", ""))
|
|
268
270
|
if not (
|
|
269
271
|
yaml_data["location"] == "header"
|
|
270
272
|
and yaml_data["clientName"] in ("content_type", "accept")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.12",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@autorest/system-requirements": "~1.0.
|
|
22
|
+
"@autorest/system-requirements": "~1.0.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@microsoft.azure/autorest.testserver": "^3.3.46",
|
|
26
|
-
"typescript": "^
|
|
26
|
+
"typescript": "^5.0.4"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"autorest/**/*.py",
|