@autorest/python 6.7.6 → 6.7.8
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/dictionary_type.py +2 -2
- package/autorest/codegen/models/enum_type.py +1 -1
- package/autorest/codegen/models/list_type.py +2 -2
- package/autorest/codegen/models/primitive_types.py +7 -7
- package/autorest/codegen/serializers/builder_serializer.py +19 -22
- package/autorest/codegen/serializers/model_serializer.py +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +0 -3
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +0 -3
- package/autorest/codegen/templates/macros.jinja2 +12 -0
- package/autorest/codegen/templates/model_base.py.jinja2 +6 -7
- package/autorest/codegen/templates/model_dpg.py.jinja2 +3 -2
- package/autorest/codegen/templates/model_msrest.py.jinja2 +9 -5
- package/autorest/codegen/templates/operation.py.jinja2 +0 -3
- package/autorest/codegen/templates/paging_operation.py.jinja2 +0 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +2 -0
- package/autorest/m4reformatter/__init__.py +2 -2
- package/package.json +1 -1
|
@@ -31,8 +31,8 @@ class DictionaryType(BaseType):
|
|
|
31
31
|
self.element_type = element_type
|
|
32
32
|
|
|
33
33
|
@property
|
|
34
|
-
def
|
|
35
|
-
return self.element_type.
|
|
34
|
+
def encode(self) -> Optional[str]:
|
|
35
|
+
return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore
|
|
36
36
|
|
|
37
37
|
@property
|
|
38
38
|
def serialization_type(self) -> str:
|
|
@@ -65,7 +65,7 @@ class EnumType(BaseType):
|
|
|
65
65
|
value_type: BaseType,
|
|
66
66
|
) -> None:
|
|
67
67
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
68
|
-
self.name: str = yaml_data["name"]
|
|
68
|
+
self.name: str = yaml_data["name"][0].upper() + yaml_data["name"][1:]
|
|
69
69
|
self.values = values
|
|
70
70
|
self.value_type = value_type
|
|
71
71
|
|
|
@@ -26,8 +26,8 @@ class ListType(BaseType):
|
|
|
26
26
|
self.unique_items: bool = yaml_data.get("uniqueItems", False)
|
|
27
27
|
|
|
28
28
|
@property
|
|
29
|
-
def
|
|
30
|
-
return self.element_type.
|
|
29
|
+
def encode(self) -> Optional[str]:
|
|
30
|
+
return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore
|
|
31
31
|
|
|
32
32
|
@property
|
|
33
33
|
def serialization_type(self) -> str:
|
|
@@ -355,10 +355,10 @@ class StringType(PrimitiveType):
|
|
|
355
355
|
class DatetimeType(PrimitiveType):
|
|
356
356
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
357
357
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
358
|
-
self.
|
|
358
|
+
self.encode = (
|
|
359
359
|
"rfc3339"
|
|
360
|
-
if yaml_data.get("
|
|
361
|
-
or yaml_data.get("
|
|
360
|
+
if yaml_data.get("encode", "date-time") == "date-time"
|
|
361
|
+
or yaml_data.get("encode", "date-time") == "rfc3339"
|
|
362
362
|
else "rfc7231"
|
|
363
363
|
)
|
|
364
364
|
|
|
@@ -368,7 +368,7 @@ class DatetimeType(PrimitiveType):
|
|
|
368
368
|
"rfc3339": "iso-8601",
|
|
369
369
|
"rfc7231": "rfc-1123",
|
|
370
370
|
}
|
|
371
|
-
return formats_to_attribute_type[self.
|
|
371
|
+
return formats_to_attribute_type[self.encode]
|
|
372
372
|
|
|
373
373
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
374
374
|
return "~" + self.type_annotation()
|
|
@@ -455,7 +455,7 @@ class TimeType(PrimitiveType):
|
|
|
455
455
|
|
|
456
456
|
class UnixTimeType(PrimitiveType):
|
|
457
457
|
@property
|
|
458
|
-
def
|
|
458
|
+
def encode(self) -> str:
|
|
459
459
|
return "unix-timestamp"
|
|
460
460
|
|
|
461
461
|
@property
|
|
@@ -592,11 +592,11 @@ class DurationType(PrimitiveType):
|
|
|
592
592
|
class ByteArraySchema(PrimitiveType):
|
|
593
593
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
594
594
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
595
|
-
self.
|
|
595
|
+
self.encode = yaml_data.get("encode", "base64")
|
|
596
596
|
|
|
597
597
|
@property
|
|
598
598
|
def serialization_type(self) -> str:
|
|
599
|
-
if self.
|
|
599
|
+
if self.encode == "base64url":
|
|
600
600
|
return "base64"
|
|
601
601
|
return "bytearray"
|
|
602
602
|
|
|
@@ -32,6 +32,7 @@ from ..models import (
|
|
|
32
32
|
RequestBuilderType,
|
|
33
33
|
CombinedType,
|
|
34
34
|
ParameterListType,
|
|
35
|
+
ByteArraySchema,
|
|
35
36
|
)
|
|
36
37
|
from .parameter_serializer import ParameterSerializer, PopKwargType
|
|
37
38
|
from ..models.parameter_list import ParameterType
|
|
@@ -749,10 +750,17 @@ class _OperationSerializer(
|
|
|
749
750
|
f"'{body_param.type.serialization_type}'{is_xml_cmd}{serialization_ctxt_cmd})"
|
|
750
751
|
)
|
|
751
752
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
753
|
+
if hasattr(body_param.type, "encode") and body_param.type.encode: # type: ignore
|
|
754
|
+
create_body_call = (
|
|
755
|
+
f"_{body_kwarg_name} = json.dumps({body_param.client_name}, "
|
|
756
|
+
"cls=AzureJSONEncoder, exclude_readonly=True, "
|
|
757
|
+
f"format='{body_param.type.encode}') # type: ignore" # type: ignore
|
|
758
|
+
)
|
|
759
|
+
else:
|
|
760
|
+
create_body_call = (
|
|
761
|
+
f"_{body_kwarg_name} = json.dumps({body_param.client_name}, "
|
|
762
|
+
"cls=AzureJSONEncoder, exclude_readonly=True) # type: ignore"
|
|
763
|
+
)
|
|
756
764
|
else:
|
|
757
765
|
create_body_call = f"_{body_kwarg_name} = {body_param.client_name}"
|
|
758
766
|
if body_param.optional:
|
|
@@ -774,7 +782,11 @@ class _OperationSerializer(
|
|
|
774
782
|
if hasattr(body_param, "entries"):
|
|
775
783
|
return _serialize_multipart_body(builder)
|
|
776
784
|
body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name
|
|
777
|
-
|
|
785
|
+
body_param_type = body_param.type
|
|
786
|
+
if isinstance(body_param_type, BinaryType) or (
|
|
787
|
+
isinstance(body_param.type, ByteArraySchema)
|
|
788
|
+
and body_param.default_content_type != "application/json"
|
|
789
|
+
):
|
|
778
790
|
retval.append(f"_{body_kwarg_name} = {body_param.client_name}")
|
|
779
791
|
if (
|
|
780
792
|
not body_param.default_content_type
|
|
@@ -889,7 +901,6 @@ class _OperationSerializer(
|
|
|
889
901
|
self,
|
|
890
902
|
builder: OperationType,
|
|
891
903
|
request_builder: RequestBuilderType,
|
|
892
|
-
template_url: Optional[str] = None,
|
|
893
904
|
is_next_request: bool = False,
|
|
894
905
|
) -> List[str]:
|
|
895
906
|
retval: List[str] = []
|
|
@@ -949,9 +960,6 @@ class _OperationSerializer(
|
|
|
949
960
|
retval.append(
|
|
950
961
|
f" {body_param.client_name}={body_param.name_in_high_level_operation},"
|
|
951
962
|
)
|
|
952
|
-
if not self.code_model.options["version_tolerant"]:
|
|
953
|
-
template_url = template_url or f"self.{builder.name}.metadata['url']"
|
|
954
|
-
retval.append(f" template_url={template_url},")
|
|
955
963
|
retval.append(" headers=_headers,")
|
|
956
964
|
retval.append(" params=_params,")
|
|
957
965
|
retval.append(")")
|
|
@@ -1011,9 +1019,7 @@ class _OperationSerializer(
|
|
|
1011
1019
|
retval.extend(self._create_body_parameter(builder))
|
|
1012
1020
|
retval.append("")
|
|
1013
1021
|
retval.extend(
|
|
1014
|
-
self._create_request_builder_call(
|
|
1015
|
-
builder, request_builder, template_url, is_next_request
|
|
1016
|
-
)
|
|
1022
|
+
self._create_request_builder_call(builder, request_builder, is_next_request)
|
|
1017
1023
|
)
|
|
1018
1024
|
retval.extend(self._postprocess_http_request(builder, template_url))
|
|
1019
1025
|
return retval
|
|
@@ -1275,11 +1281,6 @@ class _OperationSerializer(
|
|
|
1275
1281
|
retval.append("error_map.update(kwargs.pop('error_map', {}) or {})")
|
|
1276
1282
|
return retval
|
|
1277
1283
|
|
|
1278
|
-
@staticmethod
|
|
1279
|
-
def get_metadata_url(builder: OperationType) -> str:
|
|
1280
|
-
url = _escape_str(builder.request_builder.url)
|
|
1281
|
-
return f"{builder.name}.metadata = {{'url': {url}}}"
|
|
1282
|
-
|
|
1283
1284
|
@property
|
|
1284
1285
|
def _call_method(self) -> str:
|
|
1285
1286
|
return "await " if self.async_mode else ""
|
|
@@ -1326,11 +1327,7 @@ class _PagingOperationSerializer(
|
|
|
1326
1327
|
def call_next_link_request_builder(self, builder: PagingOperationType) -> List[str]:
|
|
1327
1328
|
if builder.next_request_builder:
|
|
1328
1329
|
request_builder = builder.next_request_builder
|
|
1329
|
-
template_url =
|
|
1330
|
-
None
|
|
1331
|
-
if self.code_model.options["version_tolerant"]
|
|
1332
|
-
else f"'{request_builder.url}'"
|
|
1333
|
-
)
|
|
1330
|
+
template_url = None
|
|
1334
1331
|
else:
|
|
1335
1332
|
request_builder = builder.request_builder
|
|
1336
1333
|
template_url = "next_link"
|
|
@@ -260,8 +260,8 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
260
260
|
args.append(f"visibility=[{v_list}]")
|
|
261
261
|
if prop.client_default_value is not None:
|
|
262
262
|
args.append(f"default={prop.client_default_value_declaration}")
|
|
263
|
-
if hasattr(prop.type, "
|
|
264
|
-
args.append(f'format="{prop.type.
|
|
263
|
+
if hasattr(prop.type, "encode") and prop.type.encode: # type: ignore
|
|
264
|
+
args.append(f'format="{prop.type.encode}"') # type: ignore
|
|
265
265
|
|
|
266
266
|
field = "rest_discriminator" if prop.is_discriminator else "rest_field"
|
|
267
267
|
type_ignore = (
|
|
@@ -16,6 +16,3 @@
|
|
|
16
16
|
{{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
|
|
17
17
|
{{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
|
|
18
18
|
{% endif %}
|
|
19
|
-
{% if not code_model.options["version_tolerant"] %}
|
|
20
|
-
{{ operation_serializer.get_metadata_url(operation) }}
|
|
21
|
-
{% endif %}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{% macro wrap_model_string(doc_string, wrap_string, suffix_string="") %}
|
|
2
|
+
{% set orignal_result = doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) %}
|
|
3
|
+
{% set list_result = orignal_result.split('\n') %}
|
|
4
|
+
{% for line in list_result %}
|
|
5
|
+
{% set suffix = suffix_string if list_result | length == loop.index %}
|
|
6
|
+
{% if line | length > 120 %}
|
|
7
|
+
{{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
|
|
8
|
+
{% else %}
|
|
9
|
+
{{ line }}{{ suffix }}
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
{% endmacro %}
|
|
@@ -128,9 +128,10 @@ def _is_readonly(p):
|
|
|
128
128
|
class AzureJSONEncoder(JSONEncoder):
|
|
129
129
|
"""A JSON encoder that's capable of serializing datetime objects and bytes."""
|
|
130
130
|
|
|
131
|
-
def __init__(self, *args, exclude_readonly: bool = False, **kwargs):
|
|
131
|
+
def __init__(self, *args, exclude_readonly: bool = False, format: typing.Optional[str] = None, **kwargs):
|
|
132
132
|
super().__init__(*args, **kwargs)
|
|
133
133
|
self.exclude_readonly = exclude_readonly
|
|
134
|
+
self.format = format
|
|
134
135
|
|
|
135
136
|
def default(self, o): # pylint: disable=too-many-return-statements
|
|
136
137
|
if _is_model(o):
|
|
@@ -138,18 +139,16 @@ class AzureJSONEncoder(JSONEncoder):
|
|
|
138
139
|
readonly_props = [p._rest_name for p in o._attr_to_rest_field.values() if _is_readonly(p)]
|
|
139
140
|
return {k: v for k, v in o.items() if k not in readonly_props}
|
|
140
141
|
return dict(o.items())
|
|
141
|
-
if isinstance(o, (bytes, bytearray)):
|
|
142
|
-
return base64.b64encode(o).decode()
|
|
143
|
-
if isinstance(o, _Null):
|
|
144
|
-
return None
|
|
145
142
|
try:
|
|
146
143
|
return super(AzureJSONEncoder, self).default(o)
|
|
147
144
|
except TypeError:
|
|
145
|
+
if isinstance(o, _Null):
|
|
146
|
+
return None
|
|
148
147
|
if isinstance(o, (bytes, bytearray)):
|
|
149
|
-
return _serialize_bytes(o)
|
|
148
|
+
return _serialize_bytes(o, self.format)
|
|
150
149
|
try:
|
|
151
150
|
# First try datetime.datetime
|
|
152
|
-
return _serialize_datetime(o)
|
|
151
|
+
return _serialize_datetime(o, self.format)
|
|
153
152
|
except AttributeError:
|
|
154
153
|
pass
|
|
155
154
|
# Last, try datetime.timedelta
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{# actual template starts here #}
|
|
2
|
+
{% import "macros.jinja2" as macros %}
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
{{ serializer.declare_model(model) }}
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
{% for p in model.properties %}
|
|
21
22
|
{% for line in serializer.variable_documentation_string(p) %}
|
|
22
23
|
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
23
|
-
{{ doc_string
|
|
24
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
24
25
|
{% endfor %}
|
|
25
26
|
{% endfor %}
|
|
26
27
|
{% endfor %}
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
{{ serializer.declare_property(p) }}
|
|
35
36
|
{% set prop_description = p.description(is_operation_file=False).replace('"', '\\"') %}
|
|
36
37
|
{% if prop_description %}
|
|
37
|
-
"""{{ prop_description
|
|
38
|
+
"""{{ macros.wrap_model_string(prop_description, '\n ', '\"\"\"') -}}
|
|
38
39
|
{% endif %}
|
|
39
40
|
{% endfor %}
|
|
40
41
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
{# actual template starts here #}
|
|
2
|
-
|
|
2
|
+
{% import "macros.jinja2" as macros %}
|
|
3
|
+
{% set initialize_properties = serializer.initialize_properties(model) %}
|
|
4
|
+
{% set exist_constant = (model.properties | selectattr('constant') | first) is defined %}
|
|
3
5
|
|
|
4
6
|
{{ serializer.declare_model(model) }}
|
|
5
7
|
"""{{ model.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
|
|
@@ -20,12 +22,13 @@
|
|
|
20
22
|
{% for p in model.properties %}
|
|
21
23
|
{% for line in serializer.variable_documentation_string(p) %}
|
|
22
24
|
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
23
|
-
{{ doc_string
|
|
25
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
24
26
|
{% endfor %}
|
|
25
27
|
{% endfor %}
|
|
26
28
|
{% endfor %}
|
|
27
29
|
{% endif %}
|
|
28
30
|
"""
|
|
31
|
+
{% if initialize_properties or exist_constant %}
|
|
29
32
|
{% if (model.properties | selectattr('validation') ) | first %}
|
|
30
33
|
|
|
31
34
|
_validation = {
|
|
@@ -53,7 +56,7 @@
|
|
|
53
56
|
{{ model.xml_map_content }}
|
|
54
57
|
}
|
|
55
58
|
{% endif %}
|
|
56
|
-
{% if
|
|
59
|
+
{% if exist_constant %}
|
|
57
60
|
|
|
58
61
|
{% for p in model.properties | selectattr('constant')%}
|
|
59
62
|
{{ p.client_name }} = {{ p.type.get_declaration() }}
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
{% if p.is_input %}
|
|
74
77
|
{% for line in serializer.input_documentation_string(p) %}
|
|
75
78
|
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
76
|
-
{{ doc_string
|
|
79
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
77
80
|
{% endfor %}
|
|
78
81
|
{% endfor %}
|
|
79
82
|
{% endif %}
|
|
@@ -81,6 +84,7 @@
|
|
|
81
84
|
{% endif %}
|
|
82
85
|
"""
|
|
83
86
|
{{ serializer.super_call(model) }}
|
|
84
|
-
{% for initialize_property in
|
|
87
|
+
{% for initialize_property in initialize_properties %}
|
|
85
88
|
{{ initialize_property }}
|
|
86
89
|
{% endfor %}
|
|
90
|
+
{% endif %}
|
|
@@ -19,6 +19,3 @@
|
|
|
19
19
|
{{ op_tools.serialize(operation_serializer.make_pipeline_call(operation)) | indent }}
|
|
20
20
|
{{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
|
|
21
21
|
{% endif %}
|
|
22
|
-
{% if not code_model.options["version_tolerant"] %}
|
|
23
|
-
{{ operation_serializer.get_metadata_url(operation) }}
|
|
24
|
-
{% endif %}
|
|
@@ -39,6 +39,8 @@ def raise_if_not_implemented(cls, abstract_methods):
|
|
|
39
39
|
def quote_etag(etag: Optional[str]) -> Optional[str]:
|
|
40
40
|
if not etag or etag == "*":
|
|
41
41
|
return etag
|
|
42
|
+
if etag.startswith("W/"):
|
|
43
|
+
return etag
|
|
42
44
|
if etag.startswith('"') and etag.endswith('"'):
|
|
43
45
|
return etag
|
|
44
46
|
if etag.startswith("'") and etag.endswith("'"):
|
|
@@ -232,11 +232,11 @@ def update_primitive( # pylint: disable=too-many-return-statements
|
|
|
232
232
|
return KNOWN_TYPES["binary"]
|
|
233
233
|
if type_group == "date-time":
|
|
234
234
|
base = _update_type_base("datetime", yaml_data)
|
|
235
|
-
base["
|
|
235
|
+
base["encode"] = yaml_data["format"]
|
|
236
236
|
return base
|
|
237
237
|
if type_group == "byte-array":
|
|
238
238
|
base = _update_type_base("bytes", yaml_data)
|
|
239
|
-
base["
|
|
239
|
+
base["encode"] = yaml_data["format"]
|
|
240
240
|
return base
|
|
241
241
|
return _update_type_base(type_group, yaml_data)
|
|
242
242
|
|