@autorest/python 6.1.11 → 6.2.1
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/_utils.py +2 -1
- package/autorest/codegen/__init__.py +23 -81
- package/autorest/codegen/models/__init__.py +5 -3
- package/autorest/codegen/models/{base_type.py → base.py} +24 -3
- package/autorest/codegen/models/base_builder.py +9 -5
- package/autorest/codegen/models/client.py +183 -13
- package/autorest/codegen/models/code_model.py +154 -141
- package/autorest/codegen/models/combined_type.py +5 -2
- package/autorest/codegen/models/constant_type.py +38 -4
- package/autorest/codegen/models/credential_types.py +1 -1
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/enum_type.py +5 -3
- package/autorest/codegen/models/imports.py +78 -29
- package/autorest/codegen/models/list_type.py +1 -1
- package/autorest/codegen/models/lro_operation.py +5 -1
- package/autorest/codegen/models/model_type.py +1 -2
- package/autorest/codegen/models/operation.py +34 -10
- package/autorest/codegen/models/operation_group.py +16 -5
- package/autorest/codegen/models/paging_operation.py +5 -4
- package/autorest/codegen/models/parameter.py +19 -6
- package/autorest/codegen/models/primitive_types.py +1 -2
- package/autorest/codegen/models/property.py +4 -4
- package/autorest/codegen/models/request_builder.py +17 -6
- package/autorest/codegen/models/request_builder_parameter.py +5 -2
- package/autorest/codegen/models/response.py +6 -3
- package/autorest/codegen/serializers/__init__.py +207 -135
- package/autorest/codegen/serializers/builder_serializer.py +2 -4
- package/autorest/codegen/serializers/client_serializer.py +41 -45
- package/autorest/codegen/serializers/general_serializer.py +80 -37
- package/autorest/codegen/serializers/import_serializer.py +30 -36
- package/autorest/codegen/serializers/metadata_serializer.py +36 -14
- package/autorest/codegen/serializers/model_serializer.py +34 -19
- package/autorest/codegen/serializers/operation_groups_serializer.py +22 -6
- package/autorest/codegen/serializers/operations_init_serializer.py +10 -4
- package/autorest/codegen/serializers/sample_serializer.py +144 -0
- package/autorest/codegen/templates/client.py.jinja2 +7 -15
- package/autorest/codegen/templates/client_container.py.jinja2 +12 -0
- package/autorest/codegen/templates/config.py.jinja2 +13 -26
- package/autorest/codegen/templates/config_container.py.jinja2 +16 -0
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +9 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +13 -14
- package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +5 -5
- package/autorest/codegen/templates/operation_tools.jinja2 +2 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
- package/autorest/codegen/templates/{CHANGELOG.md.jinja2 → packaging_templates/CHANGELOG.md.jinja2} +0 -0
- package/autorest/codegen/templates/{LICENSE.jinja2 → packaging_templates/LICENSE.jinja2} +0 -0
- package/autorest/codegen/templates/{MANIFEST.in.jinja2 → packaging_templates/MANIFEST.in.jinja2} +0 -0
- package/autorest/codegen/templates/{README.md.jinja2 → packaging_templates/README.md.jinja2} +0 -0
- package/autorest/codegen/templates/{dev_requirements.txt.jinja2 → packaging_templates/dev_requirements.txt.jinja2} +0 -0
- package/autorest/codegen/templates/{setup.py.jinja2 → packaging_templates/setup.py.jinja2} +12 -9
- package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
- package/autorest/codegen/templates/sample.py.jinja2 +44 -0
- package/autorest/codegen/templates/vendor.py.jinja2 +4 -2
- package/autorest/m4reformatter/__init__.py +18 -4
- package/autorest/multiapi/models/imports.py +89 -18
- package/autorest/multiapi/serializers/import_serializer.py +88 -7
- package/autorest/multiapi/utils.py +6 -0
- package/autorest/preprocess/__init__.py +20 -8
- package/package.json +1 -1
- package/run_cadl.py +0 -1
- package/autorest/cadlflags/__init__.py +0 -130
- package/autorest/codegen/models/base_model.py +0 -28
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from enum import Enum, auto
|
|
7
|
-
from typing import Dict, List, Optional, Tuple, Union, Set,
|
|
7
|
+
from typing import Dict, List, Optional, Tuple, Union, Set, TYPE_CHECKING
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
10
10
|
from .code_model import CodeModel
|
|
@@ -15,6 +15,7 @@ class ImportType(str, Enum):
|
|
|
15
15
|
THIRDPARTY = "thirdparty"
|
|
16
16
|
AZURECORE = "azurecore"
|
|
17
17
|
LOCAL = "local"
|
|
18
|
+
BYVERSION = "by_version"
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
class TypingSection(str, Enum):
|
|
@@ -42,12 +43,19 @@ class ImportModel:
|
|
|
42
43
|
*,
|
|
43
44
|
submodule_name: Optional[str] = None,
|
|
44
45
|
alias: Optional[str] = None,
|
|
46
|
+
version_modules: Optional[
|
|
47
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]]
|
|
48
|
+
] = None,
|
|
45
49
|
):
|
|
46
50
|
self.typing_section = typing_section
|
|
47
51
|
self.import_type = import_type
|
|
48
52
|
self.module_name = module_name
|
|
49
53
|
self.submodule_name = submodule_name
|
|
50
54
|
self.alias = alias
|
|
55
|
+
# version_modules: this field is for imports submodule from specified module by python version.
|
|
56
|
+
# It's a list of "python version, module_name, comments".
|
|
57
|
+
# The python version is in form of (major, minor), for instance (3, 9) stands for py3.9.
|
|
58
|
+
self.version_modules = version_modules
|
|
51
59
|
|
|
52
60
|
def __eq__(self, other):
|
|
53
61
|
try:
|
|
@@ -74,14 +82,9 @@ class TypeDefinition:
|
|
|
74
82
|
self,
|
|
75
83
|
sync_definition: str,
|
|
76
84
|
async_definition: str,
|
|
77
|
-
version_imports: Mapping[Optional[Tuple[int, int]], ImportModel] = None,
|
|
78
85
|
):
|
|
79
|
-
# version_imports: a map of "python version -> ImportModel".
|
|
80
|
-
# The python version is in form of (major, minor), for instance (3, 9) stands for py3.9.
|
|
81
|
-
# If the python version is None, it's a default ImportModel.
|
|
82
86
|
self.sync_definition = sync_definition
|
|
83
87
|
self.async_definition = async_definition
|
|
84
|
-
self.version_imports = version_imports
|
|
85
88
|
|
|
86
89
|
|
|
87
90
|
class FileImport:
|
|
@@ -114,6 +117,9 @@ class FileImport:
|
|
|
114
117
|
import_type: ImportType,
|
|
115
118
|
typing_section: TypingSection = TypingSection.REGULAR,
|
|
116
119
|
alias: Optional[str] = None,
|
|
120
|
+
version_modules: Optional[
|
|
121
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]]
|
|
122
|
+
] = None,
|
|
117
123
|
) -> None:
|
|
118
124
|
"""Add an import to this import block."""
|
|
119
125
|
self._append_import(
|
|
@@ -123,6 +129,7 @@ class FileImport:
|
|
|
123
129
|
module_name=module_name,
|
|
124
130
|
submodule_name=submodule_name,
|
|
125
131
|
alias=alias,
|
|
132
|
+
version_modules=version_modules,
|
|
126
133
|
)
|
|
127
134
|
)
|
|
128
135
|
|
|
@@ -148,10 +155,9 @@ class FileImport:
|
|
|
148
155
|
type_name: str,
|
|
149
156
|
type_value: str,
|
|
150
157
|
async_type_value: Optional[str] = None,
|
|
151
|
-
version_imports: Mapping[Optional[Tuple[int, int]], ImportModel] = None,
|
|
152
158
|
):
|
|
153
159
|
self.type_definitions[type_name] = TypeDefinition(
|
|
154
|
-
type_value, async_type_value or type_value
|
|
160
|
+
type_value, async_type_value or type_value
|
|
155
161
|
)
|
|
156
162
|
|
|
157
163
|
def merge(self, file_import: "FileImport") -> None:
|
|
@@ -162,24 +168,18 @@ class FileImport:
|
|
|
162
168
|
|
|
163
169
|
def define_mutable_mapping_type(self) -> None:
|
|
164
170
|
"""Helper function for defining the mutable mapping type"""
|
|
171
|
+
self.add_import("sys", ImportType.STDLIB)
|
|
172
|
+
self.add_submodule_import(
|
|
173
|
+
"typing",
|
|
174
|
+
"MutableMapping",
|
|
175
|
+
ImportType.BYVERSION,
|
|
176
|
+
TypingSection.REGULAR,
|
|
177
|
+
None,
|
|
178
|
+
(((3, 9), "collections.abc", None),),
|
|
179
|
+
)
|
|
165
180
|
self.define_mypy_type(
|
|
166
181
|
"JSON",
|
|
167
182
|
"MutableMapping[str, Any] # pylint: disable=unsubscriptable-object",
|
|
168
|
-
None,
|
|
169
|
-
{
|
|
170
|
-
(3, 9): ImportModel(
|
|
171
|
-
TypingSection.CONDITIONAL,
|
|
172
|
-
ImportType.STDLIB,
|
|
173
|
-
"collections.abc",
|
|
174
|
-
submodule_name="MutableMapping",
|
|
175
|
-
),
|
|
176
|
-
None: ImportModel(
|
|
177
|
-
TypingSection.CONDITIONAL,
|
|
178
|
-
ImportType.STDLIB,
|
|
179
|
-
"typing",
|
|
180
|
-
submodule_name="MutableMapping",
|
|
181
|
-
),
|
|
182
|
-
},
|
|
183
183
|
)
|
|
184
184
|
self.add_submodule_import("typing", "Any", ImportType.STDLIB)
|
|
185
185
|
|
|
@@ -187,18 +187,67 @@ class FileImport:
|
|
|
187
187
|
self,
|
|
188
188
|
) -> Dict[
|
|
189
189
|
TypingSection,
|
|
190
|
-
Dict[
|
|
190
|
+
Dict[
|
|
191
|
+
ImportType,
|
|
192
|
+
Dict[
|
|
193
|
+
str,
|
|
194
|
+
Set[
|
|
195
|
+
Optional[
|
|
196
|
+
Union[
|
|
197
|
+
str,
|
|
198
|
+
Tuple[str, str],
|
|
199
|
+
Tuple[
|
|
200
|
+
str,
|
|
201
|
+
Optional[str],
|
|
202
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
203
|
+
],
|
|
204
|
+
]
|
|
205
|
+
]
|
|
206
|
+
],
|
|
207
|
+
],
|
|
208
|
+
],
|
|
191
209
|
]:
|
|
192
210
|
retval: Dict[
|
|
193
211
|
TypingSection,
|
|
194
|
-
Dict[
|
|
212
|
+
Dict[
|
|
213
|
+
ImportType,
|
|
214
|
+
Dict[
|
|
215
|
+
str,
|
|
216
|
+
Set[
|
|
217
|
+
Optional[
|
|
218
|
+
Union[
|
|
219
|
+
str,
|
|
220
|
+
Tuple[str, str],
|
|
221
|
+
Tuple[
|
|
222
|
+
str,
|
|
223
|
+
Optional[str],
|
|
224
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
225
|
+
],
|
|
226
|
+
]
|
|
227
|
+
]
|
|
228
|
+
],
|
|
229
|
+
],
|
|
230
|
+
],
|
|
195
231
|
] = dict()
|
|
196
232
|
for i in self.imports:
|
|
197
|
-
name_import: Optional[
|
|
233
|
+
name_import: Optional[
|
|
234
|
+
Union[
|
|
235
|
+
str,
|
|
236
|
+
Tuple[str, str],
|
|
237
|
+
Tuple[
|
|
238
|
+
str,
|
|
239
|
+
Optional[str],
|
|
240
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
241
|
+
],
|
|
242
|
+
]
|
|
243
|
+
] = None
|
|
198
244
|
if i.submodule_name:
|
|
199
|
-
|
|
200
|
-
(i.submodule_name, i.alias
|
|
201
|
-
|
|
245
|
+
if i.version_modules:
|
|
246
|
+
name_import = (i.submodule_name, i.alias, i.version_modules)
|
|
247
|
+
elif i.alias:
|
|
248
|
+
name_import = (i.submodule_name, i.alias)
|
|
249
|
+
else:
|
|
250
|
+
name_import = i.submodule_name
|
|
202
251
|
retval.setdefault(i.typing_section, dict()).setdefault(
|
|
203
252
|
i.import_type, dict()
|
|
204
253
|
).setdefault(i.module_name, set()).add(name_import)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Any, Dict, Optional, Union, TYPE_CHECKING, List
|
|
7
|
-
from .
|
|
7
|
+
from .base import BaseType
|
|
8
8
|
from .imports import FileImport, ImportType, TypingSection
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
@@ -13,6 +13,7 @@ from .parameter_list import ParameterList
|
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
15
|
from .code_model import CodeModel
|
|
16
|
+
from .client import Client
|
|
16
17
|
|
|
17
18
|
LROResponseType = TypeVar(
|
|
18
19
|
"LROResponseType", bound=Union[LROResponse, LROPagingResponse]
|
|
@@ -24,6 +25,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
24
25
|
self,
|
|
25
26
|
yaml_data: Dict[str, Any],
|
|
26
27
|
code_model: "CodeModel",
|
|
28
|
+
client: "Client",
|
|
27
29
|
name: str,
|
|
28
30
|
request_builder: RequestBuilder,
|
|
29
31
|
parameters: ParameterList,
|
|
@@ -36,6 +38,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
36
38
|
) -> None:
|
|
37
39
|
super().__init__(
|
|
38
40
|
code_model=code_model,
|
|
41
|
+
client=client,
|
|
39
42
|
yaml_data=yaml_data,
|
|
40
43
|
name=name,
|
|
41
44
|
request_builder=request_builder,
|
|
@@ -90,7 +93,8 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
90
93
|
return Operation(
|
|
91
94
|
yaml_data=self.yaml_data,
|
|
92
95
|
code_model=self.code_model,
|
|
93
|
-
|
|
96
|
+
client=self.client,
|
|
97
|
+
request_builder=self.client.lookup_request_builder(id(self.yaml_data)),
|
|
94
98
|
name=self.name[5:] + "_initial",
|
|
95
99
|
overloads=self.overloads,
|
|
96
100
|
parameters=self.parameters,
|
|
@@ -7,7 +7,7 @@ from collections import OrderedDict
|
|
|
7
7
|
from typing import Any, Dict, List, Optional, TYPE_CHECKING, cast
|
|
8
8
|
|
|
9
9
|
from autorest.codegen.models.utils import add_to_pylint_disable
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseType
|
|
11
11
|
from .constant_type import ConstantType
|
|
12
12
|
from .property import Property
|
|
13
13
|
from .imports import FileImport, ImportType, TypingSection
|
|
@@ -284,7 +284,6 @@ class ModelType(
|
|
|
284
284
|
file_import.add_submodule_import(
|
|
285
285
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
286
286
|
)
|
|
287
|
-
file_import.add_import("sys", ImportType.STDLIB)
|
|
288
287
|
file_import.define_mutable_mapping_type()
|
|
289
288
|
if self.is_xml:
|
|
290
289
|
file_import.add_submodule_import(
|
|
@@ -19,7 +19,6 @@ from typing import (
|
|
|
19
19
|
from .request_builder_parameter import RequestBuilderParameter
|
|
20
20
|
|
|
21
21
|
from .utils import OrderedSet, add_to_pylint_disable
|
|
22
|
-
|
|
23
22
|
from .base_builder import BaseBuilder
|
|
24
23
|
from .imports import FileImport, ImportType, TypingSection
|
|
25
24
|
from .response import (
|
|
@@ -41,6 +40,7 @@ from .request_builder import OverloadedRequestBuilder, RequestBuilder
|
|
|
41
40
|
|
|
42
41
|
if TYPE_CHECKING:
|
|
43
42
|
from .code_model import CodeModel
|
|
43
|
+
from .client import Client
|
|
44
44
|
|
|
45
45
|
ResponseType = TypeVar(
|
|
46
46
|
"ResponseType",
|
|
@@ -55,6 +55,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
55
55
|
self,
|
|
56
56
|
yaml_data: Dict[str, Any],
|
|
57
57
|
code_model: "CodeModel",
|
|
58
|
+
client: "Client",
|
|
58
59
|
name: str,
|
|
59
60
|
request_builder: Union[RequestBuilder, OverloadedRequestBuilder],
|
|
60
61
|
parameters: ParameterList,
|
|
@@ -67,6 +68,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
67
68
|
) -> None:
|
|
68
69
|
super().__init__(
|
|
69
70
|
code_model=code_model,
|
|
71
|
+
client=client,
|
|
70
72
|
yaml_data=yaml_data,
|
|
71
73
|
name=name,
|
|
72
74
|
parameters=parameters,
|
|
@@ -202,13 +204,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
202
204
|
)
|
|
203
205
|
)
|
|
204
206
|
|
|
205
|
-
def _imports_shared(
|
|
207
|
+
def _imports_shared(
|
|
208
|
+
self, async_mode: bool, **kwargs: Any # pylint: disable=unused-argument
|
|
209
|
+
) -> FileImport:
|
|
206
210
|
file_import = FileImport()
|
|
207
211
|
file_import.add_submodule_import(
|
|
208
212
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
209
213
|
)
|
|
210
|
-
for param in self.parameters.method:
|
|
211
|
-
file_import.merge(param.imports(async_mode, **kwargs))
|
|
212
214
|
|
|
213
215
|
response_types = [
|
|
214
216
|
r.type_annotation(async_mode=async_mode) for r in self.responses if r.type
|
|
@@ -229,6 +231,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
229
231
|
if self.abstract:
|
|
230
232
|
return FileImport()
|
|
231
233
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
234
|
+
for param in self.parameters.method:
|
|
235
|
+
file_import.merge(
|
|
236
|
+
param.imports_for_multiapi(
|
|
237
|
+
async_mode,
|
|
238
|
+
**kwargs,
|
|
239
|
+
)
|
|
240
|
+
)
|
|
232
241
|
for response in self.responses:
|
|
233
242
|
file_import.merge(
|
|
234
243
|
response.imports_for_multiapi(async_mode=async_mode, **kwargs)
|
|
@@ -300,6 +309,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
300
309
|
return FileImport()
|
|
301
310
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
302
311
|
|
|
312
|
+
for param in self.parameters.method:
|
|
313
|
+
file_import.merge(
|
|
314
|
+
param.imports(
|
|
315
|
+
async_mode,
|
|
316
|
+
**kwargs,
|
|
317
|
+
)
|
|
318
|
+
)
|
|
303
319
|
for response in self.responses:
|
|
304
320
|
file_import.merge(response.imports(async_mode=async_mode, **kwargs))
|
|
305
321
|
if self.code_model.options["models_mode"]:
|
|
@@ -409,7 +425,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
409
425
|
basename = self.group_name
|
|
410
426
|
if basename == "":
|
|
411
427
|
# in a mixin
|
|
412
|
-
basename = self.code_model.
|
|
428
|
+
basename = self.code_model.clients[0].legacy_filename
|
|
413
429
|
|
|
414
430
|
if (
|
|
415
431
|
basename == "operations"
|
|
@@ -423,9 +439,14 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
423
439
|
return any(r.is_stream_response for r in self.responses)
|
|
424
440
|
|
|
425
441
|
@classmethod
|
|
426
|
-
def from_yaml(
|
|
442
|
+
def from_yaml(
|
|
443
|
+
cls,
|
|
444
|
+
yaml_data: Dict[str, Any],
|
|
445
|
+
code_model: "CodeModel",
|
|
446
|
+
client: "Client",
|
|
447
|
+
):
|
|
427
448
|
name = yaml_data["name"]
|
|
428
|
-
request_builder =
|
|
449
|
+
request_builder = client.lookup_request_builder(id(yaml_data))
|
|
429
450
|
responses = [
|
|
430
451
|
cast(ResponseType, get_response(r, code_model))
|
|
431
452
|
for r in yaml_data["responses"]
|
|
@@ -435,13 +456,14 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
435
456
|
]
|
|
436
457
|
parameter_list = ParameterList.from_yaml(yaml_data, code_model)
|
|
437
458
|
overloads = [
|
|
438
|
-
cls.from_yaml(overload, code_model)
|
|
459
|
+
cls.from_yaml(overload, code_model, client)
|
|
439
460
|
for overload in yaml_data.get("overloads", [])
|
|
440
461
|
]
|
|
441
462
|
|
|
442
463
|
return cls(
|
|
443
464
|
yaml_data=yaml_data,
|
|
444
465
|
code_model=code_model,
|
|
466
|
+
client=client,
|
|
445
467
|
request_builder=request_builder,
|
|
446
468
|
name=name,
|
|
447
469
|
parameters=parameter_list,
|
|
@@ -486,7 +508,9 @@ class Operation(OperationBase[Response]):
|
|
|
486
508
|
return file_import
|
|
487
509
|
|
|
488
510
|
|
|
489
|
-
def get_operation(
|
|
511
|
+
def get_operation(
|
|
512
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
513
|
+
) -> OperationBase:
|
|
490
514
|
if yaml_data["discriminator"] == "lropaging":
|
|
491
515
|
from .lro_paging_operation import LROPagingOperation as OperationCls
|
|
492
516
|
elif yaml_data["discriminator"] == "lro":
|
|
@@ -495,4 +519,4 @@ def get_operation(yaml_data: Dict[str, Any], code_model: "CodeModel") -> Operati
|
|
|
495
519
|
from .paging_operation import PagingOperation as OperationCls # type: ignore
|
|
496
520
|
else:
|
|
497
521
|
from . import Operation as OperationCls # type: ignore
|
|
498
|
-
return OperationCls.from_yaml(yaml_data, code_model)
|
|
522
|
+
return OperationCls.from_yaml(yaml_data, code_model, client)
|
|
@@ -7,13 +7,14 @@ from typing import Dict, List, Any, TYPE_CHECKING
|
|
|
7
7
|
|
|
8
8
|
from autorest.codegen.models.utils import OrderedSet
|
|
9
9
|
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseModel
|
|
11
11
|
from .operation import OperationBase, get_operation
|
|
12
12
|
from .imports import FileImport, ImportType, TypingSection
|
|
13
13
|
from .utils import add_to_pylint_disable
|
|
14
14
|
|
|
15
15
|
if TYPE_CHECKING:
|
|
16
16
|
from .code_model import CodeModel
|
|
17
|
+
from .client import Client
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class OperationGroup(BaseModel):
|
|
@@ -23,10 +24,12 @@ class OperationGroup(BaseModel):
|
|
|
23
24
|
self,
|
|
24
25
|
yaml_data: Dict[str, Any],
|
|
25
26
|
code_model: "CodeModel",
|
|
27
|
+
client: "Client",
|
|
26
28
|
operations: List[OperationBase],
|
|
27
29
|
api_versions: List[str],
|
|
28
30
|
) -> None:
|
|
29
31
|
super().__init__(yaml_data, code_model)
|
|
32
|
+
self.client = client
|
|
30
33
|
self.class_name: str = yaml_data["className"]
|
|
31
34
|
self.property_name: str = yaml_data["propertyName"]
|
|
32
35
|
self.operations = operations
|
|
@@ -40,7 +43,7 @@ class OperationGroup(BaseModel):
|
|
|
40
43
|
def base_class(self) -> str:
|
|
41
44
|
base_classes: List[str] = []
|
|
42
45
|
if self.is_mixin and self.code_model.need_mixin_abc:
|
|
43
|
-
base_classes.append("MixinABC")
|
|
46
|
+
base_classes.append(f"{self.client.name}MixinABC")
|
|
44
47
|
return ", ".join(base_classes)
|
|
45
48
|
|
|
46
49
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
@@ -87,7 +90,9 @@ class OperationGroup(BaseModel):
|
|
|
87
90
|
relative_path, "models", ImportType.LOCAL, alias="_models"
|
|
88
91
|
)
|
|
89
92
|
if self.code_model.need_mixin_abc:
|
|
90
|
-
file_import.add_submodule_import(
|
|
93
|
+
file_import.add_submodule_import(
|
|
94
|
+
".._vendor", f"{self.client.name}MixinABC", ImportType.LOCAL
|
|
95
|
+
)
|
|
91
96
|
if self.has_abstract_operations:
|
|
92
97
|
file_import.add_submodule_import(
|
|
93
98
|
".._vendor", "raise_if_not_implemented", ImportType.LOCAL
|
|
@@ -115,9 +120,14 @@ class OperationGroup(BaseModel):
|
|
|
115
120
|
|
|
116
121
|
@classmethod
|
|
117
122
|
def from_yaml(
|
|
118
|
-
cls,
|
|
123
|
+
cls,
|
|
124
|
+
yaml_data: Dict[str, Any],
|
|
125
|
+
code_model: "CodeModel",
|
|
126
|
+
client: "Client",
|
|
119
127
|
) -> "OperationGroup":
|
|
120
|
-
operations = [
|
|
128
|
+
operations = [
|
|
129
|
+
get_operation(o, code_model, client) for o in yaml_data["operations"]
|
|
130
|
+
]
|
|
121
131
|
api_versions: OrderedSet[str] = {}
|
|
122
132
|
for operation in operations:
|
|
123
133
|
for api_version in operation.api_versions:
|
|
@@ -125,6 +135,7 @@ class OperationGroup(BaseModel):
|
|
|
125
135
|
return cls(
|
|
126
136
|
yaml_data=yaml_data,
|
|
127
137
|
code_model=code_model,
|
|
138
|
+
client=client,
|
|
128
139
|
operations=operations,
|
|
129
140
|
api_versions=list(api_versions.keys()),
|
|
130
141
|
)
|
|
@@ -18,6 +18,7 @@ from .model_type import ModelType
|
|
|
18
18
|
|
|
19
19
|
if TYPE_CHECKING:
|
|
20
20
|
from .code_model import CodeModel
|
|
21
|
+
from .client import Client
|
|
21
22
|
|
|
22
23
|
PagingResponseType = TypeVar(
|
|
23
24
|
"PagingResponseType", bound=Union[PagingResponse, LROPagingResponse]
|
|
@@ -29,6 +30,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
29
30
|
self,
|
|
30
31
|
yaml_data: Dict[str, Any],
|
|
31
32
|
code_model: "CodeModel",
|
|
33
|
+
client: "Client",
|
|
32
34
|
name: str,
|
|
33
35
|
request_builder: RequestBuilder,
|
|
34
36
|
parameters: ParameterList,
|
|
@@ -42,6 +44,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
42
44
|
) -> None:
|
|
43
45
|
super().__init__(
|
|
44
46
|
code_model=code_model,
|
|
47
|
+
client=client,
|
|
45
48
|
yaml_data=yaml_data,
|
|
46
49
|
name=name,
|
|
47
50
|
request_builder=request_builder,
|
|
@@ -55,7 +58,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
55
58
|
self.next_request_builder: Optional[
|
|
56
59
|
Union[RequestBuilder, OverloadedRequestBuilder]
|
|
57
60
|
] = (
|
|
58
|
-
get_request_builder(self.yaml_data["nextOperation"], code_model)
|
|
61
|
+
get_request_builder(self.yaml_data["nextOperation"], code_model, client)
|
|
59
62
|
if self.yaml_data.get("nextOperation")
|
|
60
63
|
else None
|
|
61
64
|
)
|
|
@@ -140,9 +143,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
140
143
|
file_import.merge(
|
|
141
144
|
self.get_request_builder_import(self.next_request_builder, async_mode)
|
|
142
145
|
)
|
|
143
|
-
elif "api-version" in [
|
|
144
|
-
p.rest_api_name for p in self.code_model.client.parameters
|
|
145
|
-
]:
|
|
146
|
+
elif "api-version" in [p.rest_api_name for p in self.client.parameters]:
|
|
146
147
|
file_import.add_import("urllib.parse", ImportType.STDLIB)
|
|
147
148
|
file_import.add_submodule_import(
|
|
148
149
|
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
@@ -19,8 +19,8 @@ from typing import (
|
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
from .imports import FileImport, ImportType
|
|
22
|
-
from .
|
|
23
|
-
from .
|
|
22
|
+
from .base import BaseModel
|
|
23
|
+
from .base import BaseType
|
|
24
24
|
from .constant_type import ConstantType
|
|
25
25
|
from .model_type import ModelType
|
|
26
26
|
from .combined_type import CombinedType
|
|
@@ -149,11 +149,8 @@ class _ParameterBase(
|
|
|
149
149
|
def serialization_type(self) -> str:
|
|
150
150
|
return self.type.serialization_type
|
|
151
151
|
|
|
152
|
-
def
|
|
152
|
+
def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
|
|
153
153
|
file_import = FileImport()
|
|
154
|
-
file_import.merge(
|
|
155
|
-
self.type.imports(is_operation_file=True, async_mode=async_mode, **kwargs)
|
|
156
|
-
)
|
|
157
154
|
if self.optional and self.client_default_value is None:
|
|
158
155
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
159
156
|
if self.added_on:
|
|
@@ -164,6 +161,22 @@ class _ParameterBase(
|
|
|
164
161
|
)
|
|
165
162
|
return file_import
|
|
166
163
|
|
|
164
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
165
|
+
file_import = self._imports_shared(async_mode, **kwargs)
|
|
166
|
+
file_import.merge(
|
|
167
|
+
self.type.imports(is_operation_file=True, async_mode=async_mode, **kwargs)
|
|
168
|
+
)
|
|
169
|
+
return file_import
|
|
170
|
+
|
|
171
|
+
def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
172
|
+
file_import = self._imports_shared(async_mode, **kwargs)
|
|
173
|
+
file_import.merge(
|
|
174
|
+
self.type.imports_for_multiapi(
|
|
175
|
+
is_operation_file=True, async_mode=async_mode, **kwargs
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
return file_import
|
|
179
|
+
|
|
167
180
|
@property
|
|
168
181
|
def method_location(self) -> ParameterMethodLocation:
|
|
169
182
|
raise NotImplementedError("Please implement in children")
|
|
@@ -7,7 +7,7 @@ import datetime
|
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING
|
|
9
9
|
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseType
|
|
11
11
|
from .imports import FileImport, ImportType, TypingSection
|
|
12
12
|
from .utils import add_to_description
|
|
13
13
|
|
|
@@ -197,7 +197,6 @@ class AnyObjectType(PrimitiveType):
|
|
|
197
197
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
198
198
|
file_import = FileImport()
|
|
199
199
|
file_import.define_mutable_mapping_type()
|
|
200
|
-
file_import.add_import("sys", ImportType.STDLIB)
|
|
201
200
|
return file_import
|
|
202
201
|
|
|
203
202
|
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Any, Dict, Optional, TYPE_CHECKING, List
|
|
7
7
|
|
|
8
|
-
from .
|
|
8
|
+
from .base import BaseModel
|
|
9
9
|
from .constant_type import ConstantType
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseType
|
|
11
11
|
from .imports import FileImport, ImportType, TypingSection
|
|
12
12
|
from .utils import add_to_description, add_to_pylint_disable
|
|
13
13
|
|
|
@@ -125,10 +125,10 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
125
125
|
retval.update(self.type.validation or {})
|
|
126
126
|
return retval or None
|
|
127
127
|
|
|
128
|
-
def imports(self) -> FileImport:
|
|
128
|
+
def imports(self, **kwargs) -> FileImport:
|
|
129
129
|
from .model_type import ModelType
|
|
130
130
|
|
|
131
|
-
file_import = self.type.imports(is_operation_file=False)
|
|
131
|
+
file_import = self.type.imports(**kwargs, is_operation_file=False)
|
|
132
132
|
if self.optional and self.client_default_value is None:
|
|
133
133
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
134
134
|
if isinstance(self.type, ModelType):
|
|
@@ -24,6 +24,7 @@ from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
|
24
24
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
26
26
|
from .code_model import CodeModel
|
|
27
|
+
from .client import Client
|
|
27
28
|
|
|
28
29
|
ParameterListType = TypeVar(
|
|
29
30
|
"ParameterListType",
|
|
@@ -36,6 +37,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
36
37
|
self,
|
|
37
38
|
yaml_data: Dict[str, Any],
|
|
38
39
|
code_model: "CodeModel",
|
|
40
|
+
client: "Client",
|
|
39
41
|
name: str,
|
|
40
42
|
parameters: ParameterListType,
|
|
41
43
|
*,
|
|
@@ -43,6 +45,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
43
45
|
) -> None:
|
|
44
46
|
super().__init__(
|
|
45
47
|
code_model=code_model,
|
|
48
|
+
client=client,
|
|
46
49
|
yaml_data=yaml_data,
|
|
47
50
|
name=name,
|
|
48
51
|
parameters=parameters,
|
|
@@ -122,7 +125,12 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
122
125
|
...
|
|
123
126
|
|
|
124
127
|
@classmethod
|
|
125
|
-
def from_yaml(
|
|
128
|
+
def from_yaml(
|
|
129
|
+
cls,
|
|
130
|
+
yaml_data: Dict[str, Any],
|
|
131
|
+
code_model: "CodeModel",
|
|
132
|
+
client: "Client",
|
|
133
|
+
):
|
|
126
134
|
# when combine embedded builders into one operation file, we need to avoid duplicated build function name.
|
|
127
135
|
# So add operation group name is effective method
|
|
128
136
|
additional_mark = ""
|
|
@@ -130,7 +138,9 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
130
138
|
code_model.options["combine_operation_files"]
|
|
131
139
|
and code_model.options["builders_visibility"] == "embedded"
|
|
132
140
|
):
|
|
133
|
-
additional_mark =
|
|
141
|
+
additional_mark = (
|
|
142
|
+
yaml_data["groupName"] or client.yaml_data["builderPadName"]
|
|
143
|
+
)
|
|
134
144
|
names = [
|
|
135
145
|
"build",
|
|
136
146
|
additional_mark,
|
|
@@ -139,7 +149,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
139
149
|
]
|
|
140
150
|
name = "_".join([n for n in names if n])
|
|
141
151
|
overloads = [
|
|
142
|
-
RequestBuilder.from_yaml(rb_yaml_data, code_model)
|
|
152
|
+
RequestBuilder.from_yaml(rb_yaml_data, code_model, client)
|
|
143
153
|
for rb_yaml_data in yaml_data.get("overloads", [])
|
|
144
154
|
]
|
|
145
155
|
parameter_list = cls.parameter_list_type()(yaml_data, code_model)
|
|
@@ -147,6 +157,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
147
157
|
return cls(
|
|
148
158
|
yaml_data=yaml_data,
|
|
149
159
|
code_model=code_model,
|
|
160
|
+
client=client,
|
|
150
161
|
name=name,
|
|
151
162
|
parameters=parameter_list,
|
|
152
163
|
overloads=overloads,
|
|
@@ -172,8 +183,8 @@ class OverloadedRequestBuilder(
|
|
|
172
183
|
|
|
173
184
|
|
|
174
185
|
def get_request_builder(
|
|
175
|
-
yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
186
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
176
187
|
) -> Union[RequestBuilder, OverloadedRequestBuilder]:
|
|
177
188
|
if yaml_data.get("overloads"):
|
|
178
|
-
return OverloadedRequestBuilder.from_yaml(yaml_data, code_model)
|
|
179
|
-
return RequestBuilder.from_yaml(yaml_data, code_model)
|
|
189
|
+
return OverloadedRequestBuilder.from_yaml(yaml_data, code_model, client)
|
|
190
|
+
return RequestBuilder.from_yaml(yaml_data, code_model, client)
|
|
@@ -11,7 +11,7 @@ from .parameter import (
|
|
|
11
11
|
BodyParameter,
|
|
12
12
|
_MultipartBodyParameter,
|
|
13
13
|
)
|
|
14
|
-
from .
|
|
14
|
+
from .base import BaseType
|
|
15
15
|
from .primitive_types import BinaryType, StringType
|
|
16
16
|
from .combined_type import CombinedType
|
|
17
17
|
|
|
@@ -93,7 +93,10 @@ class RequestBuilderParameter(Parameter):
|
|
|
93
93
|
"""Basic RequestBuilder Parameter."""
|
|
94
94
|
|
|
95
95
|
def __init__(
|
|
96
|
-
self,
|
|
96
|
+
self,
|
|
97
|
+
yaml_data: Dict[str, Any],
|
|
98
|
+
code_model: "CodeModel",
|
|
99
|
+
type: BaseType,
|
|
97
100
|
) -> None:
|
|
98
101
|
super().__init__(yaml_data, code_model, type)
|
|
99
102
|
# we don't want any default content type behavior in request builder
|