@autorest/python 5.15.0 → 5.18.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/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
import logging
|
|
7
|
-
import datetime
|
|
8
|
-
from enum import Enum
|
|
9
|
-
from typing import cast, Any, Dict, List, Optional, Union
|
|
10
|
-
|
|
11
|
-
from .base_schema import BaseSchema
|
|
12
|
-
from .imports import FileImport, ImportType, TypingSection
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_LOGGER = logging.getLogger(__name__)
|
|
16
|
-
|
|
17
|
-
class RawString(object):
|
|
18
|
-
def __init__(self, string: str) -> None:
|
|
19
|
-
self.string = string
|
|
20
|
-
|
|
21
|
-
def __repr__(self) -> str:
|
|
22
|
-
return "r'{}'".format(self.string.replace('\'', '\\\''))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class PrimitiveSchema(BaseSchema):
|
|
27
|
-
_TYPE_MAPPINGS = {
|
|
28
|
-
"boolean": "bool",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
def _to_python_type(self) -> str:
|
|
32
|
-
return self._TYPE_MAPPINGS.get(self.yaml_data["type"], "str")
|
|
33
|
-
|
|
34
|
-
@property
|
|
35
|
-
def serialization_type(self) -> str:
|
|
36
|
-
return self._to_python_type()
|
|
37
|
-
|
|
38
|
-
@property
|
|
39
|
-
def docstring_type(self) -> str:
|
|
40
|
-
return self._to_python_type()
|
|
41
|
-
|
|
42
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
43
|
-
return self.docstring_type
|
|
44
|
-
|
|
45
|
-
@property
|
|
46
|
-
def docstring_text(self) -> str:
|
|
47
|
-
return self.docstring_type
|
|
48
|
-
|
|
49
|
-
def _add_optional_and_default_value_template_representation(
|
|
50
|
-
self,
|
|
51
|
-
*,
|
|
52
|
-
optional: bool = True,
|
|
53
|
-
default_value_declaration: Optional[str] = None,
|
|
54
|
-
description: Optional[str] = None,
|
|
55
|
-
):
|
|
56
|
-
comment = ""
|
|
57
|
-
if optional:
|
|
58
|
-
comment += " Optional."
|
|
59
|
-
if default_value_declaration:
|
|
60
|
-
comment += f" Default value is {default_value_declaration}."
|
|
61
|
-
else:
|
|
62
|
-
default_value_declaration = self.default_template_representation_declaration
|
|
63
|
-
if description:
|
|
64
|
-
comment += f" {description}"
|
|
65
|
-
if comment:
|
|
66
|
-
comment = f"#{comment}"
|
|
67
|
-
return f"{default_value_declaration}{comment}"
|
|
68
|
-
|
|
69
|
-
def get_json_template_representation(self, **kwargs: Any) -> Any:
|
|
70
|
-
if self.default_value:
|
|
71
|
-
kwargs["default_value_declaration"] = kwargs.get(
|
|
72
|
-
"default_value_declaration",
|
|
73
|
-
self.get_declaration(self.default_value)
|
|
74
|
-
)
|
|
75
|
-
return self._add_optional_and_default_value_template_representation(
|
|
76
|
-
**kwargs
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
@property
|
|
80
|
-
def default_template_representation_declaration(self) -> str:
|
|
81
|
-
return self.get_declaration(self.docstring_type)
|
|
82
|
-
|
|
83
|
-
def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
|
|
84
|
-
"""Template of what the files input should look like
|
|
85
|
-
"""
|
|
86
|
-
return self._add_optional_and_default_value_template_representation(
|
|
87
|
-
**kwargs
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
class IOSchema(PrimitiveSchema):
|
|
91
|
-
|
|
92
|
-
def __init__(self, namespace, yaml_data) -> None:
|
|
93
|
-
super(IOSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
94
|
-
self.type = "IO"
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def serialization_type(self) -> str:
|
|
98
|
-
return self.type
|
|
99
|
-
|
|
100
|
-
@property
|
|
101
|
-
def docstring_type(self) -> str:
|
|
102
|
-
return self.type
|
|
103
|
-
|
|
104
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
105
|
-
return self.docstring_type
|
|
106
|
-
|
|
107
|
-
@property
|
|
108
|
-
def docstring_text(self) -> str:
|
|
109
|
-
return "IO"
|
|
110
|
-
|
|
111
|
-
@property
|
|
112
|
-
def default_template_representation_declaration(self) -> str:
|
|
113
|
-
return self.get_declaration(b"bytes")
|
|
114
|
-
|
|
115
|
-
def imports(self) -> FileImport:
|
|
116
|
-
file_import = FileImport()
|
|
117
|
-
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
118
|
-
return file_import
|
|
119
|
-
|
|
120
|
-
class AnySchema(PrimitiveSchema):
|
|
121
|
-
@property
|
|
122
|
-
def serialization_type(self) -> str:
|
|
123
|
-
return "object"
|
|
124
|
-
|
|
125
|
-
@property
|
|
126
|
-
def docstring_type(self) -> str:
|
|
127
|
-
return "any"
|
|
128
|
-
|
|
129
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
130
|
-
return "Any"
|
|
131
|
-
|
|
132
|
-
@property
|
|
133
|
-
def default_template_representation_declaration(self) -> str:
|
|
134
|
-
return self.get_declaration({})
|
|
135
|
-
|
|
136
|
-
def imports(self) -> FileImport:
|
|
137
|
-
file_import = FileImport()
|
|
138
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
139
|
-
return file_import
|
|
140
|
-
|
|
141
|
-
class JSONSchema(AnySchema):
|
|
142
|
-
|
|
143
|
-
@property
|
|
144
|
-
def docstring_type(self) -> str:
|
|
145
|
-
return "JSONType"
|
|
146
|
-
|
|
147
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
148
|
-
return "JSONType"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
class NumberSchema(PrimitiveSchema):
|
|
152
|
-
def __init__(self, namespace: str, yaml_data: Dict[str, Any]) -> None:
|
|
153
|
-
super(NumberSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
154
|
-
self.precision = cast(int, yaml_data["precision"])
|
|
155
|
-
self.multiple = cast(int, yaml_data.get("multipleOf"))
|
|
156
|
-
self.maximum = cast(int, yaml_data.get("maximum"))
|
|
157
|
-
self.minimum = cast(int, yaml_data.get("minimum"))
|
|
158
|
-
self.exclusive_maximum = cast(int, yaml_data.get("exclusiveMaximum"))
|
|
159
|
-
self.exclusive_minimum = cast(int, yaml_data.get("exclusiveMinimum"))
|
|
160
|
-
|
|
161
|
-
@property
|
|
162
|
-
def serialization_constraints(self) -> List[str]:
|
|
163
|
-
validation_constraints = [
|
|
164
|
-
f"maximum_ex={self.maximum}" if self.maximum is not None and self.exclusive_maximum else None,
|
|
165
|
-
f"maximum={self.maximum}" if self.maximum is not None and not self.exclusive_maximum else None,
|
|
166
|
-
f"minimum_ex={self.minimum}" if self.minimum is not None and self.exclusive_minimum else None,
|
|
167
|
-
f"minimum={self.minimum}" if self.minimum is not None and not self.exclusive_minimum else None,
|
|
168
|
-
f"multiple={self.multiple}" if self.multiple else None,
|
|
169
|
-
]
|
|
170
|
-
return [x for x in validation_constraints if x is not None]
|
|
171
|
-
|
|
172
|
-
@property
|
|
173
|
-
def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]:
|
|
174
|
-
validation_map: Dict[str, Union[bool, int, str]] = {}
|
|
175
|
-
if self.maximum is not None:
|
|
176
|
-
if self.exclusive_maximum:
|
|
177
|
-
validation_map["maximum_ex"] = self.maximum
|
|
178
|
-
else:
|
|
179
|
-
validation_map["maximum"] = self.maximum
|
|
180
|
-
if self.minimum is not None:
|
|
181
|
-
if self.exclusive_minimum:
|
|
182
|
-
validation_map["minimum_ex"] = self.minimum
|
|
183
|
-
else:
|
|
184
|
-
validation_map["minimum"] = self.minimum
|
|
185
|
-
if self.multiple:
|
|
186
|
-
validation_map["multiple"] = self.multiple
|
|
187
|
-
return validation_map or None
|
|
188
|
-
|
|
189
|
-
@property
|
|
190
|
-
def serialization_type(self) -> str:
|
|
191
|
-
if self.yaml_data["type"] == "integer":
|
|
192
|
-
if self.precision == 64:
|
|
193
|
-
return "long"
|
|
194
|
-
return "int"
|
|
195
|
-
return "float"
|
|
196
|
-
|
|
197
|
-
@property
|
|
198
|
-
def docstring_type(self) -> str:
|
|
199
|
-
if self.yaml_data["type"] == "integer":
|
|
200
|
-
if self.precision == 64:
|
|
201
|
-
return "long"
|
|
202
|
-
return "int"
|
|
203
|
-
return "float"
|
|
204
|
-
|
|
205
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
206
|
-
python_type = self.docstring_type
|
|
207
|
-
if python_type == "long":
|
|
208
|
-
return "int"
|
|
209
|
-
return python_type
|
|
210
|
-
|
|
211
|
-
@property
|
|
212
|
-
def default_template_representation_declaration(self) -> str:
|
|
213
|
-
default_value = 0 if self.docstring_type == "int" else 0.0
|
|
214
|
-
return self.get_declaration(default_value)
|
|
215
|
-
|
|
216
|
-
class StringSchema(PrimitiveSchema):
|
|
217
|
-
|
|
218
|
-
def __init__(self, namespace: str, yaml_data: Dict[str, Any]) -> None:
|
|
219
|
-
super(StringSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
220
|
-
self.max_length = cast(int, yaml_data.get("maxLength"))
|
|
221
|
-
self.min_length = cast(
|
|
222
|
-
int, (yaml_data.get("minLength", 0) if yaml_data.get("maxLength") else yaml_data.get("minLength"))
|
|
223
|
-
)
|
|
224
|
-
self.pattern = cast(str, yaml_data.get("pattern"))
|
|
225
|
-
|
|
226
|
-
@property
|
|
227
|
-
def serialization_constraints(self) -> List[str]:
|
|
228
|
-
validation_constraints = [
|
|
229
|
-
f"max_length={self.max_length}" if self.max_length is not None else None,
|
|
230
|
-
f"min_length={self.min_length}" if self.min_length is not None else None,
|
|
231
|
-
f"pattern={RawString(self.pattern)}" if self.pattern else None,
|
|
232
|
-
]
|
|
233
|
-
return [x for x in validation_constraints if x is not None]
|
|
234
|
-
|
|
235
|
-
@property
|
|
236
|
-
def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]:
|
|
237
|
-
validation_map: Dict[str, Union[bool, int, str]] = {}
|
|
238
|
-
if self.max_length is not None:
|
|
239
|
-
validation_map["max_length"] = self.max_length
|
|
240
|
-
if self.min_length is not None:
|
|
241
|
-
validation_map["min_length"] = self.min_length
|
|
242
|
-
if self.pattern:
|
|
243
|
-
# https://github.com/Azure/autorest.python/issues/407
|
|
244
|
-
validation_map["pattern"] = RawString(self.pattern) # type: ignore
|
|
245
|
-
return validation_map or None
|
|
246
|
-
|
|
247
|
-
def get_declaration(self, value) -> str:
|
|
248
|
-
return f'"{value}"'
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
class DatetimeSchema(PrimitiveSchema):
|
|
252
|
-
def __init__(self, namespace: str, yaml_data: Dict[str, Any]) -> None:
|
|
253
|
-
super(DatetimeSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
254
|
-
self.format = self.Formats(yaml_data["format"])
|
|
255
|
-
|
|
256
|
-
class Formats(str, Enum):
|
|
257
|
-
datetime = "date-time"
|
|
258
|
-
rfc1123 = "date-time-rfc1123"
|
|
259
|
-
|
|
260
|
-
@property
|
|
261
|
-
def serialization_type(self) -> str:
|
|
262
|
-
formats_to_attribute_type = {self.Formats.datetime: "iso-8601", self.Formats.rfc1123: "rfc-1123"}
|
|
263
|
-
return formats_to_attribute_type[self.format]
|
|
264
|
-
|
|
265
|
-
@property
|
|
266
|
-
def docstring_type(self) -> str:
|
|
267
|
-
return "~" + self.type_annotation()
|
|
268
|
-
|
|
269
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
270
|
-
return "datetime.datetime"
|
|
271
|
-
|
|
272
|
-
@property
|
|
273
|
-
def docstring_text(self) -> str:
|
|
274
|
-
return "datetime"
|
|
275
|
-
|
|
276
|
-
def get_declaration(self, value: datetime.datetime) -> str:
|
|
277
|
-
"""Could be discussed, since technically I should return a datetime object,
|
|
278
|
-
but msrest will do fine.
|
|
279
|
-
"""
|
|
280
|
-
return f'"{value}"'
|
|
281
|
-
|
|
282
|
-
def imports(self) -> FileImport:
|
|
283
|
-
file_import = FileImport()
|
|
284
|
-
file_import.add_import("datetime", ImportType.STDLIB)
|
|
285
|
-
return file_import
|
|
286
|
-
|
|
287
|
-
@property
|
|
288
|
-
def default_template_representation_declaration(self):
|
|
289
|
-
return self.get_declaration(datetime.datetime(2020, 2, 20))
|
|
290
|
-
|
|
291
|
-
class TimeSchema(PrimitiveSchema):
|
|
292
|
-
@property
|
|
293
|
-
def serialization_type(self) -> str:
|
|
294
|
-
return "time"
|
|
295
|
-
|
|
296
|
-
@property
|
|
297
|
-
def docstring_type(self) -> str:
|
|
298
|
-
return "~" + self.type_annotation()
|
|
299
|
-
|
|
300
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
301
|
-
return "datetime.time"
|
|
302
|
-
|
|
303
|
-
@property
|
|
304
|
-
def docstring_text(self) -> str:
|
|
305
|
-
return "time"
|
|
306
|
-
|
|
307
|
-
def get_declaration(self, value: datetime.time) -> str:
|
|
308
|
-
"""Could be discussed, since technically I should return a time object,
|
|
309
|
-
but msrest will do fine.
|
|
310
|
-
"""
|
|
311
|
-
return f'"{value}"'
|
|
312
|
-
|
|
313
|
-
def imports(self) -> FileImport:
|
|
314
|
-
file_import = FileImport()
|
|
315
|
-
file_import.add_import("datetime", ImportType.STDLIB)
|
|
316
|
-
return file_import
|
|
317
|
-
|
|
318
|
-
@property
|
|
319
|
-
def default_template_representation_declaration(self) -> str:
|
|
320
|
-
return self.get_declaration(datetime.time(12, 30, 0))
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
class UnixTimeSchema(PrimitiveSchema):
|
|
324
|
-
@property
|
|
325
|
-
def serialization_type(self) -> str:
|
|
326
|
-
return "unix-time"
|
|
327
|
-
|
|
328
|
-
@property
|
|
329
|
-
def docstring_type(self) -> str:
|
|
330
|
-
return "~" + self.type_annotation()
|
|
331
|
-
|
|
332
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
333
|
-
return "datetime.datetime"
|
|
334
|
-
|
|
335
|
-
@property
|
|
336
|
-
def docstring_text(self) -> str:
|
|
337
|
-
return "datetime"
|
|
338
|
-
|
|
339
|
-
def get_declaration(self, value: datetime.datetime) -> str:
|
|
340
|
-
"""Could be discussed, since technically I should return a datetime object,
|
|
341
|
-
but msrest will do fine.
|
|
342
|
-
"""
|
|
343
|
-
return f'"{value}"'
|
|
344
|
-
|
|
345
|
-
def imports(self) -> FileImport:
|
|
346
|
-
file_import = FileImport()
|
|
347
|
-
file_import.add_import("datetime", ImportType.STDLIB)
|
|
348
|
-
return file_import
|
|
349
|
-
|
|
350
|
-
@property
|
|
351
|
-
def default_template_representation_declaration(self) -> str:
|
|
352
|
-
return self.get_declaration(datetime.datetime(2020, 2, 20))
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
class DateSchema(PrimitiveSchema):
|
|
356
|
-
@property
|
|
357
|
-
def serialization_type(self) -> str:
|
|
358
|
-
return "date"
|
|
359
|
-
|
|
360
|
-
@property
|
|
361
|
-
def docstring_type(self) -> str:
|
|
362
|
-
return "~" + self.type_annotation()
|
|
363
|
-
|
|
364
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
365
|
-
return "datetime.date"
|
|
366
|
-
|
|
367
|
-
@property
|
|
368
|
-
def docstring_text(self) -> str:
|
|
369
|
-
return "date"
|
|
370
|
-
|
|
371
|
-
def get_declaration(self, value: datetime.date) -> str:
|
|
372
|
-
"""Could be discussed, since technically I should return a datetime object,
|
|
373
|
-
but msrest will do fine.
|
|
374
|
-
"""
|
|
375
|
-
return f'"{value}"'
|
|
376
|
-
|
|
377
|
-
def imports(self) -> FileImport:
|
|
378
|
-
file_import = FileImport()
|
|
379
|
-
file_import.add_import("datetime", ImportType.STDLIB)
|
|
380
|
-
return file_import
|
|
381
|
-
|
|
382
|
-
@property
|
|
383
|
-
def default_template_representation_declaration(self) -> str:
|
|
384
|
-
return self.get_declaration(datetime.date(2020, 2, 20))
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
class DurationSchema(PrimitiveSchema):
|
|
388
|
-
@property
|
|
389
|
-
def serialization_type(self) -> str:
|
|
390
|
-
return "duration"
|
|
391
|
-
|
|
392
|
-
@property
|
|
393
|
-
def docstring_type(self) -> str:
|
|
394
|
-
return "~" + self.type_annotation()
|
|
395
|
-
|
|
396
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
|
|
397
|
-
return "datetime.timedelta"
|
|
398
|
-
|
|
399
|
-
@property
|
|
400
|
-
def docstring_text(self) -> str:
|
|
401
|
-
return "timedelta"
|
|
402
|
-
|
|
403
|
-
def get_declaration(self, value: datetime.timedelta) -> str:
|
|
404
|
-
"""Could be discussed, since technically I should return a datetime object,
|
|
405
|
-
but msrest will do fine.
|
|
406
|
-
"""
|
|
407
|
-
return f'"{value}"'
|
|
408
|
-
|
|
409
|
-
def imports(self) -> FileImport:
|
|
410
|
-
file_import = FileImport()
|
|
411
|
-
file_import.add_import("datetime", ImportType.STDLIB)
|
|
412
|
-
return file_import
|
|
413
|
-
|
|
414
|
-
@property
|
|
415
|
-
def default_template_representation_declaration(self) -> str:
|
|
416
|
-
return self.get_declaration(datetime.timedelta(1))
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
class ByteArraySchema(PrimitiveSchema):
|
|
420
|
-
def __init__(self, namespace: str, yaml_data: Dict[str, Any]) -> None:
|
|
421
|
-
super(ByteArraySchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
422
|
-
self.format = self.Formats(yaml_data["format"])
|
|
423
|
-
|
|
424
|
-
class Formats(str, Enum):
|
|
425
|
-
base64url = "base64url"
|
|
426
|
-
byte = "byte"
|
|
427
|
-
|
|
428
|
-
@property
|
|
429
|
-
def serialization_type(self) -> str:
|
|
430
|
-
if self.format == ByteArraySchema.Formats.base64url:
|
|
431
|
-
return "base64"
|
|
432
|
-
return "bytearray"
|
|
433
|
-
|
|
434
|
-
@property
|
|
435
|
-
def docstring_type(self) -> str:
|
|
436
|
-
if self.format == ByteArraySchema.Formats.base64url:
|
|
437
|
-
return "bytes"
|
|
438
|
-
return "bytearray"
|
|
439
|
-
|
|
440
|
-
def get_declaration(self, value: str) -> str:
|
|
441
|
-
if self.format == ByteArraySchema.Formats.base64url:
|
|
442
|
-
return f'bytes("{value}", encoding="utf-8")'
|
|
443
|
-
return f'bytearray("{value}", encoding="utf-8")'
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
def get_primitive_schema(namespace: str, yaml_data: Dict[str, Any]) -> "PrimitiveSchema":
|
|
447
|
-
mapping = {
|
|
448
|
-
"integer": NumberSchema,
|
|
449
|
-
"number": NumberSchema,
|
|
450
|
-
"string": StringSchema,
|
|
451
|
-
"char": StringSchema,
|
|
452
|
-
"date-time": DatetimeSchema,
|
|
453
|
-
"time": TimeSchema,
|
|
454
|
-
"unixtime": UnixTimeSchema,
|
|
455
|
-
"date": DateSchema,
|
|
456
|
-
"duration": DurationSchema,
|
|
457
|
-
"byte-array": ByteArraySchema,
|
|
458
|
-
"any": AnySchema,
|
|
459
|
-
"any-object": AnySchema,
|
|
460
|
-
"binary": IOSchema
|
|
461
|
-
}
|
|
462
|
-
schema_type = yaml_data["type"]
|
|
463
|
-
primitive_schema = cast(
|
|
464
|
-
PrimitiveSchema, mapping.get(schema_type, PrimitiveSchema).from_yaml(namespace=namespace, yaml_data=yaml_data)
|
|
465
|
-
)
|
|
466
|
-
return primitive_schema
|