@autorest/python 6.6.0 → 6.7.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/autorest/codegen/models/client.py +2 -7
- package/autorest/codegen/models/code_model.py +1 -7
- package/autorest/codegen/models/lro_operation.py +12 -0
- package/autorest/codegen/models/model_type.py +4 -1
- package/autorest/codegen/models/operation.py +23 -9
- package/autorest/codegen/models/property.py +1 -0
- package/autorest/codegen/models/request_builder.py +0 -4
- package/autorest/codegen/serializers/builder_serializer.py +1 -1
- package/autorest/codegen/serializers/general_serializer.py +0 -4
- package/autorest/codegen/serializers/model_serializer.py +11 -0
- package/autorest/codegen/templates/model_base.py.jinja2 +5 -5
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +9 -4
- package/autorest/codegen/templates/vendor.py.jinja2 +0 -15
- package/package.json +2 -2
|
@@ -236,11 +236,6 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
236
236
|
"""Do we want a mixin ABC class for typing purposes?"""
|
|
237
237
|
return any(o for o in self.operation_groups if o.is_mixin)
|
|
238
238
|
|
|
239
|
-
@property
|
|
240
|
-
def need_format_url(self) -> bool:
|
|
241
|
-
"""Whether we need to format urls. If so, we need to vendor core."""
|
|
242
|
-
return any(rq for rq in self.request_builders if rq.parameters.path)
|
|
243
|
-
|
|
244
239
|
@property
|
|
245
240
|
def has_lro_operations(self) -> bool:
|
|
246
241
|
"""Are there any LRO operations in this SDK?"""
|
|
@@ -269,8 +264,8 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
269
264
|
@property
|
|
270
265
|
def need_request_converter(self) -> bool:
|
|
271
266
|
"""
|
|
272
|
-
Whether we need to convert our created azure.core.rest.
|
|
273
|
-
azure.core.pipeline.transport.
|
|
267
|
+
Whether we need to convert our created azure.core.rest.HttpRequest to
|
|
268
|
+
azure.core.pipeline.transport.HttpRequest
|
|
274
269
|
"""
|
|
275
270
|
return (
|
|
276
271
|
self.code_model.options["show_operations"]
|
|
@@ -129,18 +129,12 @@ class CodeModel: # pylint: disable=too-many-public-methods
|
|
|
129
129
|
return True
|
|
130
130
|
if async_mode:
|
|
131
131
|
return self.need_mixin_abc
|
|
132
|
-
return
|
|
133
|
-
self.need_request_converter or self.need_format_url or self.need_mixin_abc
|
|
134
|
-
)
|
|
132
|
+
return self.need_request_converter or self.need_mixin_abc
|
|
135
133
|
|
|
136
134
|
@property
|
|
137
135
|
def need_request_converter(self) -> bool:
|
|
138
136
|
return any(c for c in self.clients if c.need_request_converter)
|
|
139
137
|
|
|
140
|
-
@property
|
|
141
|
-
def need_format_url(self) -> bool:
|
|
142
|
-
return any(c for c in self.clients if c.need_format_url)
|
|
143
|
-
|
|
144
138
|
@property
|
|
145
139
|
def need_mixin_abc(self) -> bool:
|
|
146
140
|
return any(c for c in self.clients if c.has_mixin)
|
|
@@ -128,6 +128,18 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
128
128
|
"distributed_trace_async",
|
|
129
129
|
ImportType.AZURECORE,
|
|
130
130
|
)
|
|
131
|
+
if (
|
|
132
|
+
self.code_model.options["models_mode"] == "dpg"
|
|
133
|
+
and self.lro_response
|
|
134
|
+
and self.lro_response.type
|
|
135
|
+
and self.lro_response.type.type == "model"
|
|
136
|
+
):
|
|
137
|
+
# used in the case if initial operation returns none
|
|
138
|
+
# but final call returns a model
|
|
139
|
+
relative_path = "..." if async_mode else ".."
|
|
140
|
+
file_import.add_submodule_import(
|
|
141
|
+
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
|
|
142
|
+
)
|
|
131
143
|
file_import.add_submodule_import(
|
|
132
144
|
"typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
133
145
|
)
|
|
@@ -207,7 +207,10 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
207
207
|
|
|
208
208
|
@property
|
|
209
209
|
def has_readonly_or_constant_property(self) -> bool:
|
|
210
|
-
return any(
|
|
210
|
+
return any(
|
|
211
|
+
x.readonly or x.constant or x.visibility == ["read"]
|
|
212
|
+
for x in self.properties
|
|
213
|
+
)
|
|
211
214
|
|
|
212
215
|
@property
|
|
213
216
|
def discriminator(self) -> Optional[Property]:
|
|
@@ -399,16 +399,30 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
399
399
|
file_import.add_submodule_import(
|
|
400
400
|
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
401
401
|
)
|
|
402
|
-
if
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
402
|
+
if self.code_model.need_request_converter:
|
|
403
|
+
if async_mode:
|
|
404
|
+
file_import.add_submodule_import(
|
|
405
|
+
"azure.core.pipeline.transport",
|
|
406
|
+
"AsyncHttpResponse",
|
|
407
|
+
ImportType.AZURECORE,
|
|
408
|
+
)
|
|
409
|
+
else:
|
|
410
|
+
file_import.add_submodule_import(
|
|
411
|
+
"azure.core.pipeline.transport",
|
|
412
|
+
"HttpResponse",
|
|
413
|
+
ImportType.AZURECORE,
|
|
414
|
+
)
|
|
408
415
|
else:
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
if async_mode:
|
|
417
|
+
file_import.add_submodule_import(
|
|
418
|
+
"azure.core.rest",
|
|
419
|
+
"AsyncHttpResponse",
|
|
420
|
+
ImportType.AZURECORE,
|
|
421
|
+
)
|
|
422
|
+
else:
|
|
423
|
+
file_import.add_submodule_import(
|
|
424
|
+
"azure.core.rest", "HttpResponse", ImportType.AZURECORE
|
|
425
|
+
)
|
|
412
426
|
if (
|
|
413
427
|
self.code_model.options["builders_visibility"] == "embedded"
|
|
414
428
|
and not async_mode
|
|
@@ -29,6 +29,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
29
29
|
self.type = type
|
|
30
30
|
self.optional: bool = self.yaml_data["optional"]
|
|
31
31
|
self.readonly: bool = self.yaml_data.get("readonly", False)
|
|
32
|
+
self.visibility: List[str] = self.yaml_data.get("visibility", [])
|
|
32
33
|
self.is_polymorphic: bool = self.yaml_data.get("isPolymorphic", False)
|
|
33
34
|
self.is_discriminator: bool = yaml_data.get("isDiscriminator", False)
|
|
34
35
|
self.client_default_value = yaml_data.get("clientDefaultValue", None)
|
|
@@ -92,10 +92,6 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
92
92
|
ImportType.AZURECORE,
|
|
93
93
|
)
|
|
94
94
|
|
|
95
|
-
if self.parameters.path:
|
|
96
|
-
file_import.add_submodule_import(
|
|
97
|
-
f"{relative_path}_vendor", "_format_url_section", ImportType.LOCAL
|
|
98
|
-
)
|
|
99
95
|
if self.parameters.headers or self.parameters.query:
|
|
100
96
|
file_import.add_submodule_import(
|
|
101
97
|
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
@@ -1543,7 +1543,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1543
1543
|
retval.append("if cont_token is None:")
|
|
1544
1544
|
retval.append(
|
|
1545
1545
|
f" raw_result = {self._call_method}self.{builder.initial_operation.name}("
|
|
1546
|
-
f"{'' if
|
|
1546
|
+
f"{'' if any(rsp.type for rsp in builder.initial_operation.responses) else ' # type: ignore'}"
|
|
1547
1547
|
)
|
|
1548
1548
|
retval.extend(
|
|
1549
1549
|
[
|
|
@@ -109,10 +109,6 @@ class GeneralSerializer:
|
|
|
109
109
|
ImportType.AZURECORE,
|
|
110
110
|
)
|
|
111
111
|
|
|
112
|
-
if self.code_model.need_format_url and not self.async_mode:
|
|
113
|
-
file_import.add_submodule_import("typing", "List", ImportType.STDLIB)
|
|
114
|
-
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
115
|
-
|
|
116
112
|
if self.code_model.need_mixin_abc:
|
|
117
113
|
file_import.add_submodule_import(
|
|
118
114
|
"abc",
|
|
@@ -257,6 +257,9 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
257
257
|
args.append(f'name="{prop.wire_name}"')
|
|
258
258
|
if prop.readonly:
|
|
259
259
|
args.append("readonly=True")
|
|
260
|
+
if prop.visibility:
|
|
261
|
+
v_list = ", ".join(f'"{x}"' for x in prop.visibility)
|
|
262
|
+
args.append(f"visibility=[{v_list}]")
|
|
260
263
|
if prop.client_default_value is not None:
|
|
261
264
|
args.append(f"default={prop.client_default_value_declaration}")
|
|
262
265
|
|
|
@@ -280,3 +283,11 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
280
283
|
f"{cast(ConstantType, prop.type).get_declaration()}"
|
|
281
284
|
)
|
|
282
285
|
return init_args
|
|
286
|
+
|
|
287
|
+
@staticmethod
|
|
288
|
+
def _init_line_parameters(model: ModelType):
|
|
289
|
+
return [
|
|
290
|
+
p
|
|
291
|
+
for p in model.properties
|
|
292
|
+
if not p.is_discriminator and not p.constant and p.visibility != ["read"]
|
|
293
|
+
]
|
|
@@ -136,7 +136,7 @@ def _serialize_datetime(o):
|
|
|
136
136
|
|
|
137
137
|
def _is_readonly(p):
|
|
138
138
|
try:
|
|
139
|
-
return p.
|
|
139
|
+
return p._visibility == ["read"] # pylint: disable=protected-access
|
|
140
140
|
except AttributeError:
|
|
141
141
|
return False
|
|
142
142
|
|
|
@@ -634,14 +634,14 @@ class _RestField:
|
|
|
634
634
|
name: typing.Optional[str] = None,
|
|
635
635
|
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
|
|
636
636
|
is_discriminator: bool = False,
|
|
637
|
-
|
|
637
|
+
visibility: typing.Optional[typing.List[str]] = None,
|
|
638
638
|
default: typing.Any = _UNSET,
|
|
639
639
|
):
|
|
640
640
|
self._type = type
|
|
641
641
|
self._rest_name_input = name
|
|
642
642
|
self._module: typing.Optional[str] = None
|
|
643
643
|
self._is_discriminator = is_discriminator
|
|
644
|
-
self.
|
|
644
|
+
self._visibility = visibility
|
|
645
645
|
self._is_model = False
|
|
646
646
|
self._default = default
|
|
647
647
|
|
|
@@ -681,10 +681,10 @@ def rest_field(
|
|
|
681
681
|
*,
|
|
682
682
|
name: typing.Optional[str] = None,
|
|
683
683
|
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
|
|
684
|
-
|
|
684
|
+
visibility: typing.Optional[typing.List[str]] = None,
|
|
685
685
|
default: typing.Any = _UNSET,
|
|
686
686
|
) -> typing.Any:
|
|
687
|
-
return _RestField(name=name, type=type,
|
|
687
|
+
return _RestField(name=name, type=type, visibility=visibility, default=default)
|
|
688
688
|
|
|
689
689
|
|
|
690
690
|
def rest_discriminator(
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
{{ request_builder_serializer.construct_url(request_builder) }}
|
|
16
16
|
{% if request_builder.parameters.path %}
|
|
17
17
|
{{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
|
|
18
|
-
_url: str =
|
|
18
|
+
_url: str = _url.format(**path_format_arguments) # type: ignore
|
|
19
19
|
{% endif %}
|
|
20
20
|
|
|
21
21
|
{% if request_builder.parameters.query %}
|
|
@@ -664,8 +664,9 @@ class Serializer(object):
|
|
|
664
664
|
_serialized.update(_new_attr) # type: ignore
|
|
665
665
|
_new_attr = _new_attr[k] # type: ignore
|
|
666
666
|
_serialized = _serialized[k]
|
|
667
|
-
except ValueError:
|
|
668
|
-
|
|
667
|
+
except ValueError as err:
|
|
668
|
+
if isinstance(err, SerializationError):
|
|
669
|
+
raise
|
|
669
670
|
|
|
670
671
|
except (AttributeError, KeyError, TypeError) as err:
|
|
671
672
|
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
|
|
@@ -905,7 +906,9 @@ class Serializer(object):
|
|
|
905
906
|
for d in data:
|
|
906
907
|
try:
|
|
907
908
|
serialized.append(self.serialize_data(d, iter_type, **kwargs))
|
|
908
|
-
except ValueError:
|
|
909
|
+
except ValueError as err:
|
|
910
|
+
if isinstance(err, SerializationError):
|
|
911
|
+
raise
|
|
909
912
|
serialized.append(None)
|
|
910
913
|
|
|
911
914
|
if div:
|
|
@@ -952,7 +955,9 @@ class Serializer(object):
|
|
|
952
955
|
for key, value in attr.items():
|
|
953
956
|
try:
|
|
954
957
|
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
|
|
955
|
-
except ValueError:
|
|
958
|
+
except ValueError as err:
|
|
959
|
+
if isinstance(err, SerializationError):
|
|
960
|
+
raise
|
|
956
961
|
serialized[self.serialize_unicode(key)] = None
|
|
957
962
|
|
|
958
963
|
if "xml" in serialization_ctxt:
|
|
@@ -11,21 +11,6 @@ def _convert_request(request, files=None):
|
|
|
11
11
|
request.set_formdata_body(files)
|
|
12
12
|
return request
|
|
13
13
|
{% endif %}
|
|
14
|
-
{% if code_model.need_format_url and not async_mode %}
|
|
15
|
-
|
|
16
|
-
def _format_url_section(template, **kwargs):
|
|
17
|
-
components = template.split("/")
|
|
18
|
-
while components:
|
|
19
|
-
try:
|
|
20
|
-
return template.format(**kwargs)
|
|
21
|
-
except KeyError as key:
|
|
22
|
-
# Need the cast, as for some reasons "split" is typed as list[str | Any]
|
|
23
|
-
formatted_components = cast(List[str], template.split("/"))
|
|
24
|
-
components = [
|
|
25
|
-
c for c in formatted_components if "{{{}}}".format(key.args[0]) not in c
|
|
26
|
-
]
|
|
27
|
-
template = "/".join(components)
|
|
28
|
-
{% endif %}
|
|
29
14
|
{% if code_model.need_mixin_abc %}
|
|
30
15
|
{% for client in clients | selectattr("has_mixin") %}
|
|
31
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@microsoft.azure/autorest.testserver": "^3.3.46",
|
|
26
|
-
"typescript": "
|
|
26
|
+
"typescript": "~5.1.3"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"autorest/**/*.py",
|