@autorest/python 6.7.7 → 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/list_type.py +2 -2
- package/autorest/codegen/models/primitive_types.py +7 -7
- package/autorest/codegen/serializers/builder_serializer.py +17 -5
- package/autorest/codegen/serializers/model_serializer.py +2 -2
- package/autorest/codegen/templates/model_base.py.jinja2 +6 -7
- 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:
|
|
@@ -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
|
|
@@ -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 = (
|
|
@@ -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
|
|
@@ -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
|
|