@autorest/python 5.17.0 → 6.0.0-rc.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/ChangeLog.md +63 -1
- package/README.md +9 -0
- package/autorest/codegen/__init__.py +24 -30
- package/autorest/codegen/models/base_builder.py +17 -6
- package/autorest/codegen/models/base_type.py +6 -0
- package/autorest/codegen/models/client.py +9 -6
- package/autorest/codegen/models/code_model.py +20 -14
- package/autorest/codegen/models/dictionary_type.py +16 -1
- package/autorest/codegen/models/imports.py +57 -2
- package/autorest/codegen/models/list_type.py +16 -1
- package/autorest/codegen/models/lro_operation.py +4 -6
- package/autorest/codegen/models/lro_paging_operation.py +3 -9
- package/autorest/codegen/models/model_type.py +34 -16
- package/autorest/codegen/models/operation.py +47 -79
- package/autorest/codegen/models/operation_group.py +10 -9
- package/autorest/codegen/models/paging_operation.py +4 -6
- package/autorest/codegen/models/parameter.py +3 -7
- package/autorest/codegen/models/parameter_list.py +26 -35
- package/autorest/codegen/models/property.py +14 -0
- package/autorest/codegen/models/request_builder.py +32 -43
- package/autorest/codegen/serializers/__init__.py +12 -50
- package/autorest/codegen/serializers/builder_serializer.py +136 -49
- package/autorest/codegen/serializers/client_serializer.py +23 -32
- package/autorest/codegen/serializers/general_serializer.py +12 -12
- package/autorest/codegen/serializers/import_serializer.py +11 -22
- package/autorest/codegen/serializers/metadata_serializer.py +0 -2
- package/autorest/codegen/serializers/{model_base_serializer.py → model_serializer.py} +58 -44
- package/autorest/codegen/serializers/operation_groups_serializer.py +3 -7
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -23
- package/autorest/codegen/serializers/patch_serializer.py +1 -3
- package/autorest/codegen/serializers/request_builders_serializer.py +2 -5
- package/autorest/codegen/serializers/utils.py +3 -4
- package/autorest/codegen/templates/client.py.jinja2 +6 -3
- package/autorest/codegen/templates/config.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +4 -4
- package/autorest/codegen/templates/model.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +5 -12
- package/autorest/codegen/templates/operation_group.py.jinja2 +16 -3
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -8
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -1
- package/autorest/codegen/templates/patch.py.jinja2 +1 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +0 -7
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -4
- package/autorest/codegen/templates/rest_init.py.jinja2 +3 -8
- package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
- package/autorest/codegen/templates/setup.py.jinja2 +4 -0
- package/autorest/codegen/templates/vendor.py.jinja2 +10 -0
- package/autorest/m4reformatter/__init__.py +82 -58
- package/autorest/multiapi/models/client.py +12 -2
- package/autorest/multiapi/serializers/__init__.py +17 -8
- package/autorest/multiapi/serializers/import_serializer.py +4 -8
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/preprocess/__init__.py +1 -0
- package/package.json +2 -2
- package/autorest/codegen/serializers/model_generic_serializer.py +0 -32
- package/autorest/codegen/serializers/model_python3_serializer.py +0 -72
package/ChangeLog.md
CHANGED
|
@@ -1,4 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Release History
|
|
2
|
+
|
|
3
|
+
### 2022-06-17 - 6.0.0-rc.1
|
|
4
|
+
|
|
5
|
+
| Library | Min Version |
|
|
6
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
7
|
+
| `@autorest/core` | `3.8.1` |
|
|
8
|
+
| `@autorest/modelerfour` | `4.23.5` |
|
|
9
|
+
| `azure-core` dep of generated code | `1.24.0` |
|
|
10
|
+
| `msrest` dep of generated code (If generating legacy code | `0.7.1` |
|
|
11
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
12
|
+
|
|
13
|
+
**Breaking Changes**
|
|
14
|
+
|
|
15
|
+
- Default to generating DPG SDKs with `--version-tolerant` now defaulting to `true`. For a list of flag default changes, please
|
|
16
|
+
see [here](https://github.com/Azure/autorest.python/issues/1186) #1304
|
|
17
|
+
- Only generate Python3 SDKs #1297
|
|
18
|
+
- Don't reformat initial query parameters into the next link #1297
|
|
19
|
+
- Don't generate operations with more than two body types. SDK authors need to implement this operation themselves #1300
|
|
20
|
+
|
|
21
|
+
**New Features**
|
|
22
|
+
|
|
23
|
+
- Automatically format generated code with `black`. To not format, pass in `--black=false` #1304
|
|
24
|
+
|
|
25
|
+
**Other**
|
|
26
|
+
|
|
27
|
+
- Remove testing support for `--low-level-client` SDKs #1303
|
|
28
|
+
|
|
29
|
+
### 2022-06-13 - 5.19.0
|
|
30
|
+
|
|
31
|
+
| Library | Min Version |
|
|
32
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
33
|
+
| `@autorest/core` | `3.8.1` |
|
|
34
|
+
| `@autorest/modelerfour` | `4.23.5` |
|
|
35
|
+
| `azure-core` dep of generated code | `1.24.0` |
|
|
36
|
+
| `msrest` dep of generated code | `0.7.0` |
|
|
37
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
38
|
+
|
|
39
|
+
**New Features**
|
|
40
|
+
|
|
41
|
+
- Add _serialization.py for `--client-side-validation=false` generation, and migrate serilization from msrest to _serialization.py #1236
|
|
42
|
+
|
|
43
|
+
### 2022-06-09 - 5.18.0
|
|
44
|
+
|
|
45
|
+
| Library | Min Version |
|
|
46
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
47
|
+
| `@autorest/core` | `3.8.1` |
|
|
48
|
+
| `@autorest/modelerfour` | `4.23.5` |
|
|
49
|
+
| `azure-core` dep of generated code | `1.24.0` |
|
|
50
|
+
| `msrest` dep of generated code | `0.7.0` |
|
|
51
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
52
|
+
|
|
53
|
+
**Breaking Changes in Version Tolerant**
|
|
54
|
+
|
|
55
|
+
- No longer allow users to specify `api_version` on the method level #1281
|
|
56
|
+
- Make `content_type` param required with no default if streaming with no `application/octet-stream` #1288
|
|
57
|
+
|
|
58
|
+
**Bug Fixes**
|
|
59
|
+
|
|
60
|
+
- Fix duplicate params in signature with `--payload-flattening-threshold` #1289
|
|
61
|
+
- Fix overloaded request builder signatures #1289
|
|
62
|
+
- Improve docstring templates, specifically for polymorphic bodies #1279
|
|
63
|
+
|
|
2
64
|
|
|
3
65
|
### 2022-06-02 - 5.17.0
|
|
4
66
|
|
package/README.md
CHANGED
|
@@ -23,6 +23,15 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
|
|
|
23
23
|
|
|
24
24
|
#### Python code gen
|
|
25
25
|
|
|
26
|
+
```yaml !$(multiapiscript)
|
|
27
|
+
# default values for version tolerant and black
|
|
28
|
+
black: true
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```yaml !$(low-level-client)
|
|
32
|
+
version-tolerant: true
|
|
33
|
+
```
|
|
34
|
+
|
|
26
35
|
```yaml !$(low-level-client) && !$(version-tolerant)
|
|
27
36
|
modelerfour:
|
|
28
37
|
group-parameters: true
|
|
@@ -57,13 +57,6 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
57
57
|
"to 'public' or 'hidden'."
|
|
58
58
|
)
|
|
59
59
|
|
|
60
|
-
if not options["show_operations"] and options["add_python3_operation_files"]:
|
|
61
|
-
raise ValueError(
|
|
62
|
-
"Can not add typed sync operation files if you are not showing operations. "
|
|
63
|
-
"If you want typed synced operation files, you have to add flag "
|
|
64
|
-
"--show-operations"
|
|
65
|
-
)
|
|
66
|
-
|
|
67
60
|
if options["basic_setup_py"] and not options["package_version"]:
|
|
68
61
|
raise ValueError("--basic-setup-py must be used with --package-version")
|
|
69
62
|
|
|
@@ -85,18 +78,17 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
85
78
|
"--package-mode can only be 'mgmtplane' or 'dataplane' or directory which contains template files"
|
|
86
79
|
)
|
|
87
80
|
|
|
88
|
-
if options["reformat_next_link"] and options["version_tolerant"]:
|
|
89
|
-
raise ValueError(
|
|
90
|
-
"--reformat-next-link can not be true for version tolerant generations. "
|
|
91
|
-
"Please remove --reformat-next-link from your call for version tolerant generations."
|
|
92
|
-
)
|
|
93
|
-
|
|
94
81
|
if options["multiapi"] and options["version_tolerant"]:
|
|
95
82
|
raise ValueError(
|
|
96
83
|
"Can not currently generate version tolerant multiapi SDKs. "
|
|
97
84
|
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
98
85
|
)
|
|
99
86
|
|
|
87
|
+
if options["client_side_validation"] and options["version_tolerant"]:
|
|
88
|
+
raise ValueError(
|
|
89
|
+
"Can not generate version tolerant with --client-side-validation. "
|
|
90
|
+
)
|
|
91
|
+
|
|
100
92
|
|
|
101
93
|
_LOGGER = logging.getLogger(__name__)
|
|
102
94
|
|
|
@@ -130,8 +122,8 @@ class CodeGenerator(Plugin):
|
|
|
130
122
|
def _build_package_dependency() -> Dict[str, str]:
|
|
131
123
|
return {
|
|
132
124
|
"dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.0",
|
|
133
|
-
"dependency_azure_core": "azure-core<2.0.0,>=1.
|
|
134
|
-
"dependency_msrest": "msrest>=0.
|
|
125
|
+
"dependency_azure_core": "azure-core<2.0.0,>=1.24.0",
|
|
126
|
+
"dependency_msrest": "msrest>=0.7.1",
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
def _create_code_model(
|
|
@@ -184,7 +176,7 @@ class CodeGenerator(Plugin):
|
|
|
184
176
|
bool, self._autorestapi.get_boolean_value("low-level-client", False)
|
|
185
177
|
)
|
|
186
178
|
version_tolerant = cast(
|
|
187
|
-
bool, self._autorestapi.get_boolean_value("version-tolerant"
|
|
179
|
+
bool, self._autorestapi.get_boolean_value("version-tolerant")
|
|
188
180
|
)
|
|
189
181
|
show_operations = self._autorestapi.get_boolean_value(
|
|
190
182
|
"show-operations", not low_level_client
|
|
@@ -192,12 +184,22 @@ class CodeGenerator(Plugin):
|
|
|
192
184
|
models_mode_default = (
|
|
193
185
|
"none" if low_level_client or version_tolerant else "msrest"
|
|
194
186
|
)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"
|
|
199
|
-
)
|
|
200
|
-
)
|
|
187
|
+
if self._autorestapi.get_boolean_value("python3-only") is False:
|
|
188
|
+
_LOGGER.warning(
|
|
189
|
+
"You have passed in --python3-only=False. We have force overriden "
|
|
190
|
+
"this to True."
|
|
191
|
+
)
|
|
192
|
+
if self._autorestapi.get_boolean_value("add-python3-operation-files"):
|
|
193
|
+
_LOGGER.warning(
|
|
194
|
+
"You have passed in --add-python3-operation-files. "
|
|
195
|
+
"This flag no longer has an effect bc all SDKs are now Python3 only."
|
|
196
|
+
)
|
|
197
|
+
if self._autorestapi.get_boolean_value("reformat-next-link"):
|
|
198
|
+
_LOGGER.warning(
|
|
199
|
+
"You have passed in --reformat-next-link. We have force overriden "
|
|
200
|
+
"this to False because we no longer reformat initial query parameters into next "
|
|
201
|
+
"calls unless explicitly defined in the service definition."
|
|
202
|
+
)
|
|
201
203
|
|
|
202
204
|
options: Dict[str, Any] = {
|
|
203
205
|
"azure_arm": azure_arm,
|
|
@@ -236,16 +238,11 @@ class CodeGenerator(Plugin):
|
|
|
236
238
|
"only-path-and-body-params-positional",
|
|
237
239
|
low_level_client or version_tolerant,
|
|
238
240
|
),
|
|
239
|
-
"add_python3_operation_files": self._autorestapi.get_boolean_value(
|
|
240
|
-
"add-python3-operation-files",
|
|
241
|
-
python3_only and not (low_level_client or version_tolerant),
|
|
242
|
-
),
|
|
243
241
|
"version_tolerant": version_tolerant,
|
|
244
242
|
"low_level_client": low_level_client,
|
|
245
243
|
"combine_operation_files": self._autorestapi.get_boolean_value(
|
|
246
244
|
"combine-operation-files", version_tolerant
|
|
247
245
|
),
|
|
248
|
-
"python3_only": python3_only,
|
|
249
246
|
"package_mode": self._autorestapi.get_value("package-mode"),
|
|
250
247
|
"package_pprint_name": self._autorestapi.get_value("package-pprint-name"),
|
|
251
248
|
"package_configuration": self._autorestapi.get_value(
|
|
@@ -255,9 +252,6 @@ class CodeGenerator(Plugin):
|
|
|
255
252
|
"default-optional-constants-to-none",
|
|
256
253
|
low_level_client or version_tolerant,
|
|
257
254
|
),
|
|
258
|
-
"reformat_next_link": self._autorestapi.get_boolean_value(
|
|
259
|
-
"reformat-next-link", not version_tolerant
|
|
260
|
-
),
|
|
261
255
|
}
|
|
262
256
|
|
|
263
257
|
if options["builders_visibility"] is None:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
import logging
|
|
6
7
|
from abc import abstractmethod
|
|
7
8
|
from typing import Any, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING, Generic
|
|
8
9
|
from .base_model import BaseModel
|
|
@@ -27,6 +28,8 @@ if TYPE_CHECKING:
|
|
|
27
28
|
from .operation import Operation
|
|
28
29
|
from .request_builder import RequestBuilder
|
|
29
30
|
|
|
31
|
+
_LOGGER = logging.getLogger(__name__)
|
|
32
|
+
|
|
30
33
|
|
|
31
34
|
class BaseBuilder(Generic[ParameterListType], BaseModel):
|
|
32
35
|
"""Base class for Operations and Request Builders"""
|
|
@@ -39,7 +42,6 @@ class BaseBuilder(Generic[ParameterListType], BaseModel):
|
|
|
39
42
|
parameters: ParameterListType,
|
|
40
43
|
*,
|
|
41
44
|
overloads=None,
|
|
42
|
-
abstract: bool = False,
|
|
43
45
|
want_tracing: bool = True,
|
|
44
46
|
) -> None:
|
|
45
47
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
@@ -50,14 +52,23 @@ class BaseBuilder(Generic[ParameterListType], BaseModel):
|
|
|
50
52
|
overloads or []
|
|
51
53
|
)
|
|
52
54
|
self._summary: str = yaml_data.get("summary", "")
|
|
53
|
-
# for operations where we don't know what to do, we mark them as abstract so users implement
|
|
54
|
-
# in patch.py
|
|
55
|
-
self.abstract = abstract
|
|
56
55
|
self.want_tracing = want_tracing
|
|
57
56
|
self.group_name: str = yaml_data["groupName"]
|
|
58
57
|
self.is_overload: bool = yaml_data["isOverload"]
|
|
59
58
|
self.api_versions: List[str] = yaml_data["apiVersions"]
|
|
60
59
|
|
|
60
|
+
if code_model.options["version_tolerant"] and yaml_data.get("abstract"):
|
|
61
|
+
_LOGGER.warning(
|
|
62
|
+
'Not going to generate operation "%s" because we are unable to generate this '
|
|
63
|
+
"type of operation right now. "
|
|
64
|
+
'Please write your own custom operation in the "_patch.py" file '
|
|
65
|
+
"following https://aka.ms/azsdk/python/dpcodegen/python/customize",
|
|
66
|
+
name,
|
|
67
|
+
)
|
|
68
|
+
self.abstract = True
|
|
69
|
+
else:
|
|
70
|
+
self.abstract = False
|
|
71
|
+
|
|
61
72
|
@property
|
|
62
73
|
def summary(self) -> Optional[str]:
|
|
63
74
|
if self.abstract:
|
|
@@ -89,7 +100,7 @@ class BaseBuilder(Generic[ParameterListType], BaseModel):
|
|
|
89
100
|
)
|
|
90
101
|
return self._description or self.name
|
|
91
102
|
|
|
92
|
-
def method_signature(self,
|
|
103
|
+
def method_signature(self, async_mode: bool) -> List[str]:
|
|
93
104
|
if self.abstract:
|
|
94
105
|
return ["*args,", "**kwargs"]
|
|
95
|
-
return self.parameters.method_signature(
|
|
106
|
+
return self.parameters.method_signature(async_mode)
|
|
@@ -11,6 +11,7 @@ from .imports import FileImport
|
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from .code_model import CodeModel
|
|
14
|
+
from .model_type import ModelType
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class BaseType(BaseModel, ABC):
|
|
@@ -143,6 +144,11 @@ class BaseType(BaseModel, ABC):
|
|
|
143
144
|
"""Template of what this schema would look like as JSON input"""
|
|
144
145
|
...
|
|
145
146
|
|
|
147
|
+
def get_polymorphic_subtypes( # pylint: disable=no-self-use
|
|
148
|
+
self, polymorphic_subtypes: List["ModelType"] # pylint: disable=unused-argument
|
|
149
|
+
) -> None:
|
|
150
|
+
return None
|
|
151
|
+
|
|
146
152
|
@property
|
|
147
153
|
@abstractmethod
|
|
148
154
|
def instance_check_template(self) -> str:
|
|
@@ -7,7 +7,7 @@ from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union
|
|
|
7
7
|
|
|
8
8
|
from .base_model import BaseModel
|
|
9
9
|
from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
|
|
10
|
-
from .imports import FileImport, ImportType, TypingSection
|
|
10
|
+
from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
11
11
|
from .utils import add_to_pylint_disable
|
|
12
12
|
|
|
13
13
|
ParameterListType = TypeVar(
|
|
@@ -89,10 +89,6 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
89
89
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
90
90
|
file_import = FileImport()
|
|
91
91
|
|
|
92
|
-
file_import.add_submodule_import("msrest", "Serializer", ImportType.THIRDPARTY)
|
|
93
|
-
file_import.add_submodule_import(
|
|
94
|
-
"msrest", "Deserializer", ImportType.THIRDPARTY
|
|
95
|
-
)
|
|
96
92
|
file_import.add_submodule_import(
|
|
97
93
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
98
94
|
)
|
|
@@ -113,6 +109,13 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
113
109
|
ImportType.LOCAL,
|
|
114
110
|
)
|
|
115
111
|
|
|
112
|
+
file_import.add_msrest_import(
|
|
113
|
+
self.code_model,
|
|
114
|
+
".." if async_mode else ".",
|
|
115
|
+
MsrestImportType.SerializerDeserializer,
|
|
116
|
+
TypingSection.REGULAR,
|
|
117
|
+
)
|
|
118
|
+
|
|
116
119
|
return file_import
|
|
117
120
|
|
|
118
121
|
def imports(self, async_mode: bool) -> FileImport:
|
|
@@ -156,7 +159,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
156
159
|
# Also in this case, we're in version tolerant, so python3 only is true
|
|
157
160
|
file_import.add_submodule_import(
|
|
158
161
|
f"{path_to_models}models",
|
|
159
|
-
|
|
162
|
+
self.code_model.models_filename,
|
|
160
163
|
ImportType.LOCAL,
|
|
161
164
|
alias="models",
|
|
162
165
|
)
|
|
@@ -200,8 +200,15 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
200
200
|
name = f"_{name}"
|
|
201
201
|
return name
|
|
202
202
|
|
|
203
|
+
@property
|
|
204
|
+
def has_abstract_operations(self) -> bool:
|
|
205
|
+
"""Whether there is abstract operation in any operation group."""
|
|
206
|
+
return any(og.has_abstract_operations for og in self.operation_groups)
|
|
207
|
+
|
|
203
208
|
def need_vendored_code(self, async_mode: bool) -> bool:
|
|
204
209
|
"""Whether we need to vendor code in the _vendor.py file for this SDK"""
|
|
210
|
+
if self.has_abstract_operations:
|
|
211
|
+
return True
|
|
205
212
|
if async_mode:
|
|
206
213
|
return self.need_mixin_abc
|
|
207
214
|
return (
|
|
@@ -228,11 +235,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
228
235
|
@property
|
|
229
236
|
def need_mixin_abc(self) -> bool:
|
|
230
237
|
"""Do we want a mixin ABC class for typing purposes?"""
|
|
231
|
-
return any(
|
|
232
|
-
o
|
|
233
|
-
for o in self.operation_groups
|
|
234
|
-
if o.is_mixin and self.options["python3_only"]
|
|
235
|
-
)
|
|
238
|
+
return any(o for o in self.operation_groups if o.is_mixin)
|
|
236
239
|
|
|
237
240
|
@property
|
|
238
241
|
def has_lro_operations(self) -> bool:
|
|
@@ -245,22 +248,25 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
245
248
|
]
|
|
246
249
|
)
|
|
247
250
|
|
|
248
|
-
|
|
251
|
+
@property
|
|
252
|
+
def models_filename(self) -> str:
|
|
249
253
|
"""Get the names of the model file(s)"""
|
|
250
|
-
if
|
|
251
|
-
self.options["version_tolerant"] or self.options["low_level_client"]
|
|
252
|
-
) and self.options["python3_only"]:
|
|
253
|
-
return "_models"
|
|
254
|
-
if is_python3_file:
|
|
254
|
+
if self.is_legacy:
|
|
255
255
|
return "_models_py3"
|
|
256
256
|
return "_models"
|
|
257
257
|
|
|
258
258
|
@property
|
|
259
259
|
def enums_filename(self) -> str:
|
|
260
260
|
"""The name of the enums file"""
|
|
261
|
-
if self.
|
|
262
|
-
return "_enums"
|
|
263
|
-
return
|
|
261
|
+
if self.is_legacy:
|
|
262
|
+
return f"_{self.module_name}_enums"
|
|
263
|
+
return "_enums"
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def is_legacy(self) -> bool:
|
|
267
|
+
return not (
|
|
268
|
+
self.options["version_tolerant"] or self.options["low_level_client"]
|
|
269
|
+
)
|
|
264
270
|
|
|
265
271
|
@property
|
|
266
272
|
def rest_layer_name(self) -> str:
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Any, Dict, Optional, TYPE_CHECKING
|
|
6
|
+
from typing import Any, Dict, Optional, TYPE_CHECKING, List
|
|
7
7
|
from .base_type import BaseType
|
|
8
8
|
from .imports import FileImport, ImportType, TypingSection
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
11
|
from .code_model import CodeModel
|
|
12
|
+
from .model_type import ModelType
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class DictionaryType(BaseType):
|
|
@@ -79,6 +80,20 @@ class DictionaryType(BaseType):
|
|
|
79
80
|
)
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
84
|
+
from .model_type import ModelType
|
|
85
|
+
|
|
86
|
+
if isinstance(self.element_type, ModelType):
|
|
87
|
+
is_polymorphic_subtype = (
|
|
88
|
+
self.element_type.discriminator_value
|
|
89
|
+
and not self.element_type.discriminated_subtypes
|
|
90
|
+
)
|
|
91
|
+
if (
|
|
92
|
+
self.element_type.name not in (m.name for m in polymorphic_subtypes)
|
|
93
|
+
and is_polymorphic_subtype
|
|
94
|
+
):
|
|
95
|
+
polymorphic_subtypes.append(self.element_type)
|
|
96
|
+
|
|
82
97
|
@classmethod
|
|
83
98
|
def from_yaml(
|
|
84
99
|
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from enum import Enum
|
|
7
|
-
from typing import Dict, List, Optional, Tuple, Union, Set, Mapping
|
|
6
|
+
from enum import Enum, auto
|
|
7
|
+
from typing import Dict, List, Optional, Tuple, Union, Set, Mapping, TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from .code_model import CodeModel
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
class ImportType(str, Enum):
|
|
@@ -20,6 +23,16 @@ class TypingSection(str, Enum):
|
|
|
20
23
|
TYPING = "typing" # never a typing import
|
|
21
24
|
|
|
22
25
|
|
|
26
|
+
class MsrestImportType(Enum):
|
|
27
|
+
Module = auto() # import _serialization.py or msrest.serialization as Module
|
|
28
|
+
Serializer = (
|
|
29
|
+
auto()
|
|
30
|
+
) # from _serialization.py or msrest.serialization import Serializer
|
|
31
|
+
SerializerDeserializer = (
|
|
32
|
+
auto()
|
|
33
|
+
) # from _serialization.py or msrest.serialization import Serializer and Deserializer
|
|
34
|
+
|
|
35
|
+
|
|
23
36
|
class ImportModel:
|
|
24
37
|
def __init__(
|
|
25
38
|
self,
|
|
@@ -190,3 +203,45 @@ class FileImport:
|
|
|
190
203
|
i.import_type, dict()
|
|
191
204
|
).setdefault(i.module_name, set()).add(name_import)
|
|
192
205
|
return retval
|
|
206
|
+
|
|
207
|
+
def add_msrest_import(
|
|
208
|
+
self,
|
|
209
|
+
code_model: "CodeModel",
|
|
210
|
+
relative_path: str,
|
|
211
|
+
msrest_import_type: MsrestImportType,
|
|
212
|
+
typing_section: TypingSection,
|
|
213
|
+
):
|
|
214
|
+
if code_model.options["client_side_validation"]:
|
|
215
|
+
if msrest_import_type == MsrestImportType.Module:
|
|
216
|
+
self.add_import(
|
|
217
|
+
"msrest.serialization", ImportType.AZURECORE, typing_section
|
|
218
|
+
)
|
|
219
|
+
else:
|
|
220
|
+
self.add_submodule_import(
|
|
221
|
+
"msrest", "Serializer", ImportType.THIRDPARTY, typing_section
|
|
222
|
+
)
|
|
223
|
+
if msrest_import_type == MsrestImportType.SerializerDeserializer:
|
|
224
|
+
self.add_submodule_import(
|
|
225
|
+
"msrest", "Deserializer", ImportType.THIRDPARTY, typing_section
|
|
226
|
+
)
|
|
227
|
+
else:
|
|
228
|
+
if code_model.options["multiapi"]:
|
|
229
|
+
relative_path += "."
|
|
230
|
+
if msrest_import_type == MsrestImportType.Module:
|
|
231
|
+
self.add_submodule_import(
|
|
232
|
+
relative_path, "_serialization", ImportType.LOCAL, typing_section
|
|
233
|
+
)
|
|
234
|
+
else:
|
|
235
|
+
self.add_submodule_import(
|
|
236
|
+
f"{relative_path}_serialization",
|
|
237
|
+
"Serializer",
|
|
238
|
+
ImportType.LOCAL,
|
|
239
|
+
typing_section,
|
|
240
|
+
)
|
|
241
|
+
if msrest_import_type == MsrestImportType.SerializerDeserializer:
|
|
242
|
+
self.add_submodule_import(
|
|
243
|
+
f"{relative_path}_serialization",
|
|
244
|
+
"Deserializer",
|
|
245
|
+
ImportType.LOCAL,
|
|
246
|
+
typing_section,
|
|
247
|
+
)
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Any, Dict, Optional, Union, TYPE_CHECKING
|
|
6
|
+
from typing import Any, Dict, Optional, Union, TYPE_CHECKING, List
|
|
7
7
|
from .base_type import BaseType
|
|
8
8
|
from .imports import FileImport, ImportType, TypingSection
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
11
|
from .code_model import CodeModel
|
|
12
|
+
from .model_type import ModelType
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class ListType(BaseType):
|
|
@@ -104,6 +105,20 @@ class ListType(BaseType):
|
|
|
104
105
|
)
|
|
105
106
|
]
|
|
106
107
|
|
|
108
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
109
|
+
from .model_type import ModelType
|
|
110
|
+
|
|
111
|
+
if isinstance(self.element_type, ModelType):
|
|
112
|
+
is_polymorphic_subtype = (
|
|
113
|
+
self.element_type.discriminator_value
|
|
114
|
+
and not self.element_type.discriminated_subtypes
|
|
115
|
+
)
|
|
116
|
+
if (
|
|
117
|
+
self.element_type.name not in (m.name for m in polymorphic_subtypes)
|
|
118
|
+
and is_polymorphic_subtype
|
|
119
|
+
):
|
|
120
|
+
polymorphic_subtypes.append(self.element_type)
|
|
121
|
+
|
|
107
122
|
@property
|
|
108
123
|
def instance_check_template(self) -> str:
|
|
109
124
|
return "isinstance({}, list)"
|
|
@@ -33,7 +33,6 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
33
33
|
overloads: Optional[List[Operation]] = None,
|
|
34
34
|
public: bool = True,
|
|
35
35
|
want_tracing: bool = True,
|
|
36
|
-
abstract: bool = False,
|
|
37
36
|
) -> None:
|
|
38
37
|
super().__init__(
|
|
39
38
|
code_model=code_model,
|
|
@@ -46,7 +45,6 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
46
45
|
overloads=overloads,
|
|
47
46
|
public=public,
|
|
48
47
|
want_tracing=want_tracing,
|
|
49
|
-
abstract=abstract,
|
|
50
48
|
)
|
|
51
49
|
self.name = "begin_" + self.name
|
|
52
50
|
self.lro_options: Dict[str, Any] = self.yaml_data.get("lroOptions", {})
|
|
@@ -120,10 +118,10 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
120
118
|
def get_no_polling_method(self, async_mode: bool) -> str:
|
|
121
119
|
return self.responses[0].get_no_polling_method(async_mode)
|
|
122
120
|
|
|
123
|
-
def imports(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
122
|
+
file_import = super().imports(async_mode, **kwargs)
|
|
123
|
+
if self.abstract:
|
|
124
|
+
return file_import
|
|
127
125
|
if async_mode:
|
|
128
126
|
file_import.add_submodule_import(
|
|
129
127
|
f"azure.core.tracing.decorator_async",
|
|
@@ -25,15 +25,9 @@ class LROPagingOperation(
|
|
|
25
25
|
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
26
26
|
return f"ClsType[{Response.type_annotation(self.responses[0], async_mode=async_mode)}]" # pylint: disable=no-member
|
|
27
27
|
|
|
28
|
-
def imports(
|
|
29
|
-
self, async_mode
|
|
30
|
-
|
|
31
|
-
lro_imports = LROOperationBase.imports(
|
|
32
|
-
self, async_mode, is_python3_file, **kwargs
|
|
33
|
-
)
|
|
34
|
-
paging_imports = PagingOperationBase.imports(
|
|
35
|
-
self, async_mode, is_python3_file, **kwargs
|
|
36
|
-
)
|
|
28
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
29
|
+
lro_imports = LROOperationBase.imports(self, async_mode, **kwargs)
|
|
30
|
+
paging_imports = PagingOperationBase.imports(self, async_mode, **kwargs)
|
|
37
31
|
|
|
38
32
|
file_import = lro_imports
|
|
39
33
|
file_import.merge(paging_imports)
|