@autorest/python 6.38.1 → 6.39.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/README.md +2 -27
- package/autorest/codegen.py +0 -1
- package/autorest/jsonrpc/server.py +0 -3
- package/generator/build/lib/pygen/__init__.py +14 -23
- package/generator/build/lib/pygen/codegen/__init__.py +4 -4
- package/generator/build/lib/pygen/codegen/models/__init__.py +2 -2
- package/generator/build/lib/pygen/codegen/models/base.py +9 -12
- package/generator/build/lib/pygen/codegen/models/base_builder.py +4 -6
- package/generator/build/lib/pygen/codegen/models/client.py +61 -102
- package/generator/build/lib/pygen/codegen/models/code_model.py +29 -29
- package/generator/build/lib/pygen/codegen/models/combined_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/constant_type.py +4 -11
- package/generator/build/lib/pygen/codegen/models/credential_types.py +9 -11
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/build/lib/pygen/codegen/models/enum_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/imports.py +24 -29
- package/generator/build/lib/pygen/codegen/models/list_type.py +15 -14
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/build/lib/pygen/codegen/models/model_type.py +11 -11
- package/generator/build/lib/pygen/codegen/models/operation.py +26 -56
- package/generator/build/lib/pygen/codegen/models/operation_group.py +11 -22
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/build/lib/pygen/codegen/models/parameter.py +12 -21
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/build/lib/pygen/codegen/models/property.py +10 -10
- package/generator/build/lib/pygen/codegen/models/request_builder.py +7 -8
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/build/lib/pygen/codegen/models/response.py +15 -40
- package/generator/build/lib/pygen/codegen/models/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +26 -42
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +103 -100
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +49 -61
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/build/lib/pygen/codegen/serializers/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/build/lib/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/build/lib/pygen/preprocess/__init__.py +47 -30
- package/generator/build/lib/pygen/preprocess/helpers.py +2 -2
- package/generator/build/lib/pygen/utils.py +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +14 -23
- package/generator/pygen/codegen/__init__.py +4 -4
- package/generator/pygen/codegen/models/__init__.py +2 -2
- package/generator/pygen/codegen/models/base.py +9 -12
- package/generator/pygen/codegen/models/base_builder.py +4 -6
- package/generator/pygen/codegen/models/client.py +61 -102
- package/generator/pygen/codegen/models/code_model.py +29 -29
- package/generator/pygen/codegen/models/combined_type.py +7 -7
- package/generator/pygen/codegen/models/constant_type.py +4 -11
- package/generator/pygen/codegen/models/credential_types.py +9 -11
- package/generator/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/pygen/codegen/models/enum_type.py +7 -7
- package/generator/pygen/codegen/models/imports.py +24 -29
- package/generator/pygen/codegen/models/list_type.py +15 -14
- package/generator/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/pygen/codegen/models/model_type.py +11 -11
- package/generator/pygen/codegen/models/operation.py +26 -56
- package/generator/pygen/codegen/models/operation_group.py +11 -22
- package/generator/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/pygen/codegen/models/parameter.py +12 -21
- package/generator/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/pygen/codegen/models/property.py +10 -10
- package/generator/pygen/codegen/models/request_builder.py +7 -8
- package/generator/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/pygen/codegen/models/response.py +15 -40
- package/generator/pygen/codegen/models/utils.py +2 -2
- package/generator/pygen/codegen/serializers/__init__.py +26 -42
- package/generator/pygen/codegen/serializers/builder_serializer.py +103 -100
- package/generator/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/pygen/codegen/serializers/general_serializer.py +49 -61
- package/generator/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/pygen/codegen/serializers/utils.py +2 -2
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
- package/generator/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/pygen/preprocess/__init__.py +47 -30
- package/generator/pygen/preprocess/helpers.py +2 -2
- package/generator/pygen/utils.py +6 -6
- package/generator/pygen.egg-info/SOURCES.txt +0 -2
- package/package.json +2 -2
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/autorest/multiapi/__init__.py +0 -185
- package/autorest/multiapi/models/__init__.py +0 -16
- package/autorest/multiapi/models/client.py +0 -68
- package/autorest/multiapi/models/code_model.py +0 -142
- package/autorest/multiapi/models/config.py +0 -24
- package/autorest/multiapi/models/constant_global_parameter.py +0 -11
- package/autorest/multiapi/models/global_parameter.py +0 -34
- package/autorest/multiapi/models/global_parameters.py +0 -53
- package/autorest/multiapi/models/imports.py +0 -181
- package/autorest/multiapi/models/mixin_operation.py +0 -38
- package/autorest/multiapi/models/operation_group.py +0 -29
- package/autorest/multiapi/models/operation_mixin_group.py +0 -89
- package/autorest/multiapi/serializers/__init__.py +0 -145
- package/autorest/multiapi/serializers/import_serializer.py +0 -181
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +0 -89
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +0 -22
- package/autorest/multiapi/templates/multiapi_models.py.jinja2 +0 -9
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +0 -39
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +0 -163
- package/autorest/multiapi/templates/multiapi_version.py.jinja2 +0 -8
- package/autorest/multiapi/utils.py +0 -51
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +0 -167
- package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
|
|
|
23
23
|
|
|
24
24
|
#### Python code gen
|
|
25
25
|
|
|
26
|
-
```yaml !$(
|
|
26
|
+
```yaml !$(multiclientscript)
|
|
27
27
|
# default values for version tolerant and black
|
|
28
28
|
black: true
|
|
29
29
|
```
|
|
@@ -39,7 +39,7 @@ modelerfour:
|
|
|
39
39
|
flatten-payloads: true
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
```yaml !$(
|
|
42
|
+
```yaml !$(multiclientscript)
|
|
43
43
|
pass-thru:
|
|
44
44
|
- model-deduplicator
|
|
45
45
|
- subset-reducer
|
|
@@ -99,25 +99,6 @@ scope-codegen/emitter:
|
|
|
99
99
|
output-artifact: python-files
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
# Multiapi script pipeline
|
|
103
|
-
|
|
104
|
-
```yaml $(multiapiscript)
|
|
105
|
-
pipeline:
|
|
106
|
-
python/multiapiscript:
|
|
107
|
-
scope: multiapiscript
|
|
108
|
-
output-artifact: python-files
|
|
109
|
-
|
|
110
|
-
python/multiapiscript/emitter:
|
|
111
|
-
input: multiapiscript
|
|
112
|
-
scope: scope-multiapiscript/emitter
|
|
113
|
-
|
|
114
|
-
scope-multiapiscript/emitter:
|
|
115
|
-
input-artifact: python-files
|
|
116
|
-
output-uri-expr: $key
|
|
117
|
-
|
|
118
|
-
output-artifact: python-files
|
|
119
|
-
```
|
|
120
|
-
|
|
121
102
|
# Black script pipeline
|
|
122
103
|
|
|
123
104
|
```yaml $(black)
|
|
@@ -173,12 +154,6 @@ help-content:
|
|
|
173
154
|
- key: basic-setup-py
|
|
174
155
|
description: Whether to generate a build script for setuptools to package your SDK. Defaults to `false`, generally not suggested if you are going to wrap the generated code
|
|
175
156
|
type: bool
|
|
176
|
-
- key: multiapi
|
|
177
|
-
description: Whether to generate a multiapi client.
|
|
178
|
-
type: bool
|
|
179
|
-
- key: default-api
|
|
180
|
-
description: In the case of `--multiapi`, you can override the default service API version with this flag. If not specified, we use the latest GA service version as the default API.
|
|
181
|
-
type: string
|
|
182
157
|
- key: no-namespace-folders
|
|
183
158
|
description: Specify if you don't want pkgutil-style namespace folders. Defaults to `false`.
|
|
184
159
|
type: bool
|
package/autorest/codegen.py
CHANGED
|
@@ -69,7 +69,6 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
|
|
|
69
69
|
"package-version": self._autorestapi.get_value("package-version"),
|
|
70
70
|
"client-side-validation": self._autorestapi.get_boolean_value("client-side-validation"),
|
|
71
71
|
"tracing": self._autorestapi.get_boolean_value("trace"),
|
|
72
|
-
"multiapi": self._autorestapi.get_boolean_value("multiapi", False),
|
|
73
72
|
"polymorphic-examples": self._autorestapi.get_value("polymorphic-examples"),
|
|
74
73
|
"models-mode": self._autorestapi.get_value("models-mode"),
|
|
75
74
|
"builders-visibility": self._autorestapi.get_value("builders-visibility"),
|
|
@@ -26,7 +26,6 @@ def GetPluginNames():
|
|
|
26
26
|
"preprocess",
|
|
27
27
|
"m4reformatter",
|
|
28
28
|
"black",
|
|
29
|
-
"multiapiscript",
|
|
30
29
|
"multiclientscript",
|
|
31
30
|
]
|
|
32
31
|
|
|
@@ -53,8 +52,6 @@ def Process(plugin_name: str, session_id: str) -> bool:
|
|
|
53
52
|
from ..codegen import CodeGeneratorAutorest as PluginToLoad # type: ignore
|
|
54
53
|
elif plugin_name == "black":
|
|
55
54
|
from ..black import BlackScriptPluginAutorest as PluginToLoad # type: ignore
|
|
56
|
-
elif plugin_name == "multiapiscript":
|
|
57
|
-
from ..multiapi import MultiApiScriptPluginAutorest as PluginToLoad # type: ignore
|
|
58
55
|
elif plugin_name == "multiclientscript":
|
|
59
56
|
from ..multiclient import MultiClientPluginAutorest as PluginToLoad # type: ignore
|
|
60
57
|
else:
|
|
@@ -8,7 +8,7 @@ import logging
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
import json
|
|
10
10
|
from abc import ABC, abstractmethod
|
|
11
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, Iterator, Optional, Union
|
|
12
12
|
|
|
13
13
|
import yaml
|
|
14
14
|
from .utils import TYPESPEC_PACKAGE_MODE, VALID_PACKAGE_MODE
|
|
@@ -33,7 +33,6 @@ class OptionsDict(MutableMapping):
|
|
|
33
33
|
"head-as-boolean": True,
|
|
34
34
|
"keep-version-file": False,
|
|
35
35
|
"low-level-client": False,
|
|
36
|
-
"multiapi": False,
|
|
37
36
|
"no-async": False,
|
|
38
37
|
"no-namespace-folders": False,
|
|
39
38
|
"polymorphic-examples": 5,
|
|
@@ -42,11 +41,11 @@ class OptionsDict(MutableMapping):
|
|
|
42
41
|
"generation-subdir": None, # subdirectory to generate the code in
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
def __init__(self, options: Optional[
|
|
44
|
+
def __init__(self, options: Optional[dict[str, Any]] = None) -> None:
|
|
46
45
|
self._data = options.copy() if options else {}
|
|
47
46
|
self._validate_combinations()
|
|
48
47
|
|
|
49
|
-
def __getitem__(self, key: str) -> Any:
|
|
48
|
+
def __getitem__(self, key: str) -> Any: # pylint: disable=too-many-return-statements
|
|
50
49
|
if key == "head-as-boolean" and self.get("azure-arm"):
|
|
51
50
|
# override to always true if azure-arm is set
|
|
52
51
|
return True
|
|
@@ -109,7 +108,12 @@ class OptionsDict(MutableMapping):
|
|
|
109
108
|
if key == "combine-operation-files":
|
|
110
109
|
return self.get("version-tolerant")
|
|
111
110
|
if key == "package-pprint-name":
|
|
112
|
-
|
|
111
|
+
package_names = self.get("package-name", "").split("-")
|
|
112
|
+
return (
|
|
113
|
+
(package_names[-1].capitalize() + " Management")
|
|
114
|
+
if self.get("azure-arm")
|
|
115
|
+
else " ".join([i.capitalize() for i in package_names])
|
|
116
|
+
)
|
|
113
117
|
if key == "builders-visibility":
|
|
114
118
|
# Default to public if low-level client is not set, otherwise embedded
|
|
115
119
|
return "embedded" if not self.get("low-level-client") else "public"
|
|
@@ -143,16 +147,6 @@ class OptionsDict(MutableMapping):
|
|
|
143
147
|
"If you want operation files, pass in flag --show-operations"
|
|
144
148
|
)
|
|
145
149
|
|
|
146
|
-
if self.get("multiapi") and self.get("version-tolerant"):
|
|
147
|
-
raise ValueError(
|
|
148
|
-
"Can not currently generate version tolerant multiapi SDKs. "
|
|
149
|
-
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
# If multiapi, do not generate default pyproject.toml
|
|
153
|
-
if self.get("multiapi"):
|
|
154
|
-
self["keep-setup-py"] = True
|
|
155
|
-
|
|
156
150
|
if self.get("client-side-validation") and self.get("version-tolerant"):
|
|
157
151
|
raise ValueError("Can not generate version tolerant with --client-side-validation. ")
|
|
158
152
|
|
|
@@ -200,7 +194,7 @@ class OptionsDict(MutableMapping):
|
|
|
200
194
|
for key in self.DEFAULTS:
|
|
201
195
|
if key not in all_keys:
|
|
202
196
|
all_keys.add(key)
|
|
203
|
-
all_keys
|
|
197
|
+
all_keys |= self.DEFAULTS.keys()
|
|
204
198
|
return KeysView({key: None for key in all_keys})
|
|
205
199
|
|
|
206
200
|
def values(self) -> ValuesView[Any]:
|
|
@@ -213,7 +207,7 @@ class OptionsDict(MutableMapping):
|
|
|
213
207
|
class ReaderAndWriter:
|
|
214
208
|
def __init__(self, *, output_folder: Union[str, Path], **kwargs: Any) -> None:
|
|
215
209
|
self.output_folder = Path(output_folder)
|
|
216
|
-
self._list_file:
|
|
210
|
+
self._list_file: list[str] = []
|
|
217
211
|
try:
|
|
218
212
|
with open(
|
|
219
213
|
Path(self.output_folder) / Path("..") / Path("python.json"),
|
|
@@ -229,9 +223,6 @@ class ReaderAndWriter:
|
|
|
229
223
|
_LOGGER.warning("Loading python.json file. This behavior will be depreacted")
|
|
230
224
|
self.options.update(python_json)
|
|
231
225
|
|
|
232
|
-
def get_output_folder(self) -> Path:
|
|
233
|
-
return self.output_folder
|
|
234
|
-
|
|
235
226
|
def read_file(self, path: Union[str, Path]) -> str:
|
|
236
227
|
"""Directly reading from disk"""
|
|
237
228
|
# make path relative to output folder
|
|
@@ -257,7 +248,7 @@ class ReaderAndWriter:
|
|
|
257
248
|
except FileNotFoundError:
|
|
258
249
|
pass
|
|
259
250
|
|
|
260
|
-
def list_file(self) ->
|
|
251
|
+
def list_file(self) -> list[str]:
|
|
261
252
|
return [str(f.relative_to(self.output_folder)) for f in self.output_folder.glob("**/*") if f.is_file()]
|
|
262
253
|
|
|
263
254
|
|
|
@@ -281,7 +272,7 @@ class Plugin(ReaderAndWriter, ABC):
|
|
|
281
272
|
class YamlUpdatePlugin(Plugin):
|
|
282
273
|
"""A plugin that update the YAML as input."""
|
|
283
274
|
|
|
284
|
-
def get_yaml(self) ->
|
|
275
|
+
def get_yaml(self) -> dict[str, Any]:
|
|
285
276
|
# tsp file doesn't have to be relative to output folder
|
|
286
277
|
with open(self.options["tsp_file"], "r", encoding="utf-8-sig") as fd:
|
|
287
278
|
return yaml.safe_load(fd.read())
|
|
@@ -302,7 +293,7 @@ class YamlUpdatePlugin(Plugin):
|
|
|
302
293
|
return True
|
|
303
294
|
|
|
304
295
|
@abstractmethod
|
|
305
|
-
def update_yaml(self, yaml_data:
|
|
296
|
+
def update_yaml(self, yaml_data: dict[str, Any]) -> None:
|
|
306
297
|
"""The code-model-v4-no-tags yaml model tree.
|
|
307
298
|
|
|
308
299
|
:rtype: updated yaml
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Any
|
|
8
8
|
import yaml
|
|
9
9
|
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
20
20
|
class CodeGenerator(Plugin):
|
|
21
21
|
|
|
22
22
|
@staticmethod
|
|
23
|
-
def sort_exceptions(yaml_data:
|
|
23
|
+
def sort_exceptions(yaml_data: dict[str, Any]) -> None:
|
|
24
24
|
for client in yaml_data["clients"]:
|
|
25
25
|
for group in client.get("operationGroups", []):
|
|
26
26
|
for operation in group.get("operations", []):
|
|
@@ -37,7 +37,7 @@ class CodeGenerator(Plugin):
|
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
@staticmethod
|
|
40
|
-
def remove_cloud_errors(yaml_data:
|
|
40
|
+
def remove_cloud_errors(yaml_data: dict[str, Any]) -> None:
|
|
41
41
|
for client in yaml_data["clients"]:
|
|
42
42
|
for group in client.get("operationGroups", []):
|
|
43
43
|
for operation in group.get("operations", []):
|
|
@@ -60,7 +60,7 @@ class CodeGenerator(Plugin):
|
|
|
60
60
|
del yaml_data["schemas"]["objects"][i]
|
|
61
61
|
break
|
|
62
62
|
|
|
63
|
-
def get_yaml(self) ->
|
|
63
|
+
def get_yaml(self) -> dict[str, Any]:
|
|
64
64
|
# tsp file doesn't have to be relative to output folder
|
|
65
65
|
with open(self.options["tsp_file"], "r", encoding="utf-8-sig") as fd:
|
|
66
66
|
return yaml.safe_load(fd.read())
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Any,
|
|
7
|
+
from typing import Any, Union, Optional
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .base_builder import BaseBuilder, ParameterListType
|
|
10
10
|
from .code_model import CodeModel
|
|
@@ -155,7 +155,7 @@ TYPE_TO_OBJECT = {
|
|
|
155
155
|
_LOGGER = logging.getLogger(__name__)
|
|
156
156
|
|
|
157
157
|
|
|
158
|
-
def build_type(yaml_data:
|
|
158
|
+
def build_type(yaml_data: dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
159
159
|
yaml_id = id(yaml_data)
|
|
160
160
|
try:
|
|
161
161
|
return code_model.lookup_type(yaml_id)
|
|
@@ -3,7 +3,7 @@
|
|
|
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,
|
|
6
|
+
from typing import Any, TYPE_CHECKING, Optional
|
|
7
7
|
from abc import ABC, abstractmethod
|
|
8
8
|
from .imports import FileImport
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ class BaseModel:
|
|
|
20
20
|
:type yaml_data: dict[str, Any]
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
def __init__(self, yaml_data:
|
|
23
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
24
24
|
self.yaml_data = yaml_data
|
|
25
25
|
self.code_model = code_model
|
|
26
26
|
|
|
@@ -39,21 +39,18 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
39
39
|
:type yaml_data: dict[str, Any]
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
-
def __init__(self, yaml_data:
|
|
42
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
43
43
|
super().__init__(yaml_data, code_model)
|
|
44
44
|
self.type = yaml_data["type"] # the type discriminator
|
|
45
|
-
self.api_versions:
|
|
45
|
+
self.api_versions: list[str] = yaml_data.get("apiVersions", []) # api versions this type is in.
|
|
46
46
|
|
|
47
47
|
@classmethod
|
|
48
|
-
def from_yaml(cls, yaml_data:
|
|
48
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "BaseType":
|
|
49
49
|
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
50
50
|
|
|
51
51
|
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
52
52
|
return FileImport(self.code_model)
|
|
53
53
|
|
|
54
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
55
|
-
return self.imports(**kwargs)
|
|
56
|
-
|
|
57
54
|
def imports_for_sample(self) -> FileImport:
|
|
58
55
|
return FileImport(self.code_model)
|
|
59
56
|
|
|
@@ -62,7 +59,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
62
59
|
return repr(value)
|
|
63
60
|
|
|
64
61
|
@property
|
|
65
|
-
def xml_metadata(self) ->
|
|
62
|
+
def xml_metadata(self) -> dict[str, Any]:
|
|
66
63
|
"""XML metadata for the type, if the type has it."""
|
|
67
64
|
return self.yaml_data.get("xmlMetadata", {})
|
|
68
65
|
|
|
@@ -132,7 +129,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
132
129
|
"""
|
|
133
130
|
|
|
134
131
|
@property
|
|
135
|
-
def validation(self) -> Optional[
|
|
132
|
+
def validation(self) -> Optional[dict[str, Any]]:
|
|
136
133
|
"""Whether there's any validation constraints on this type.
|
|
137
134
|
|
|
138
135
|
Even though we generate validation maps if there are validation constraints,
|
|
@@ -162,7 +159,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
162
159
|
"""Template of what this schema would look like as JSON input"""
|
|
163
160
|
|
|
164
161
|
def get_polymorphic_subtypes(
|
|
165
|
-
self, polymorphic_subtypes:
|
|
162
|
+
self, polymorphic_subtypes: list["ModelType"] # pylint: disable=unused-argument
|
|
166
163
|
) -> None:
|
|
167
164
|
return None
|
|
168
165
|
|
|
@@ -172,7 +169,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
172
169
|
"""Template of what an instance check of a variable for this type would look like"""
|
|
173
170
|
|
|
174
171
|
@property
|
|
175
|
-
def serialization_constraints(self) ->
|
|
172
|
+
def serialization_constraints(self) -> list[str]:
|
|
176
173
|
"""Whether there are any serialization constraints when serializing this type."""
|
|
177
174
|
return []
|
|
178
175
|
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
7
|
from typing import (
|
|
8
|
-
List,
|
|
9
|
-
Dict,
|
|
10
8
|
Any,
|
|
11
9
|
Generic,
|
|
12
10
|
TypeVar,
|
|
@@ -52,7 +50,7 @@ class BaseBuilder(
|
|
|
52
50
|
|
|
53
51
|
def __init__(
|
|
54
52
|
self,
|
|
55
|
-
yaml_data:
|
|
53
|
+
yaml_data: dict[str, Any],
|
|
56
54
|
code_model: "CodeModel",
|
|
57
55
|
client: "Client",
|
|
58
56
|
name: str,
|
|
@@ -70,9 +68,9 @@ class BaseBuilder(
|
|
|
70
68
|
self.want_tracing: bool = yaml_data.get("wantTracing", True)
|
|
71
69
|
self.group_name: str = yaml_data["groupName"] # either operationGroup or client I am on
|
|
72
70
|
self.is_overload: bool = yaml_data["isOverload"]
|
|
73
|
-
self.api_versions:
|
|
71
|
+
self.api_versions: list[str] = yaml_data["apiVersions"]
|
|
74
72
|
self.added_on: Optional[str] = yaml_data.get("addedOn")
|
|
75
|
-
self.external_docs: Optional[
|
|
73
|
+
self.external_docs: Optional[dict[str, Any]] = yaml_data.get("externalDocs")
|
|
76
74
|
self.client_namespace: str = yaml_data.get("clientNamespace", code_model.namespace)
|
|
77
75
|
|
|
78
76
|
if code_model.options["version-tolerant"] and yaml_data.get("abstract"):
|
|
@@ -114,7 +112,7 @@ class BaseBuilder(
|
|
|
114
112
|
)
|
|
115
113
|
return self._description or self.name
|
|
116
114
|
|
|
117
|
-
def method_signature(self, async_mode: bool, **kwargs: Any) ->
|
|
115
|
+
def method_signature(self, async_mode: bool, **kwargs: Any) -> list[str]:
|
|
118
116
|
if self.abstract:
|
|
119
117
|
return ["*args,", "**kwargs"]
|
|
120
118
|
return self.parameters.method_signature(async_mode, **kwargs)
|
|
@@ -3,7 +3,7 @@
|
|
|
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,
|
|
6
|
+
from typing import Any, TYPE_CHECKING, TypeVar, Generic, Union, Optional
|
|
7
7
|
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
|
|
@@ -35,7 +35,7 @@ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
|
35
35
|
|
|
36
36
|
def __init__(
|
|
37
37
|
self,
|
|
38
|
-
yaml_data:
|
|
38
|
+
yaml_data: dict[str, Any],
|
|
39
39
|
code_model: "CodeModel",
|
|
40
40
|
parameters: ParameterListType,
|
|
41
41
|
):
|
|
@@ -54,19 +54,19 @@ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
|
54
54
|
return self.yaml_data["name"]
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
57
|
+
class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
58
58
|
"""Model representing our service client"""
|
|
59
59
|
|
|
60
60
|
def __init__(
|
|
61
61
|
self,
|
|
62
|
-
yaml_data:
|
|
62
|
+
yaml_data: dict[str, Any],
|
|
63
63
|
code_model: "CodeModel",
|
|
64
64
|
parameters: ClientGlobalParameterList,
|
|
65
65
|
*,
|
|
66
66
|
is_subclient: bool = False,
|
|
67
67
|
):
|
|
68
68
|
super().__init__(yaml_data, code_model, parameters)
|
|
69
|
-
self.operation_groups:
|
|
69
|
+
self.operation_groups: list[OperationGroup] = []
|
|
70
70
|
self.config = Config.from_yaml(yaml_data, self.code_model)
|
|
71
71
|
self.is_subclient = is_subclient
|
|
72
72
|
self.request_builders = self._build_request_builders()
|
|
@@ -81,12 +81,18 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
81
81
|
|
|
82
82
|
# update the host parameter value. In later logic, SDK will overwrite it
|
|
83
83
|
# with value from cloud_setting if users don't provide it.
|
|
84
|
-
if self.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
p.
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
if self.code_model.options.get("azure-arm"):
|
|
85
|
+
if self.need_cloud_setting:
|
|
86
|
+
for p in self.parameters.parameters:
|
|
87
|
+
if p.location == ParameterLocation.ENDPOINT_PATH:
|
|
88
|
+
p.client_default_value = None
|
|
89
|
+
p.optional = True
|
|
90
|
+
break
|
|
91
|
+
else:
|
|
92
|
+
for idx, p in enumerate(self.parameters.parameters):
|
|
93
|
+
if p.client_name == "cloud_setting":
|
|
94
|
+
self.parameters.parameters.pop(idx)
|
|
95
|
+
break
|
|
90
96
|
|
|
91
97
|
@property
|
|
92
98
|
def need_cloud_setting(self) -> bool:
|
|
@@ -102,10 +108,10 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
102
108
|
|
|
103
109
|
def _build_request_builders(
|
|
104
110
|
self,
|
|
105
|
-
) ->
|
|
106
|
-
request_builders:
|
|
111
|
+
) -> list[Union[RequestBuilder, OverloadedRequestBuilder]]:
|
|
112
|
+
request_builders: list[Union[RequestBuilder, OverloadedRequestBuilder]] = []
|
|
107
113
|
|
|
108
|
-
def add_og_request_builder(og:
|
|
114
|
+
def add_og_request_builder(og: dict[str, Any]):
|
|
109
115
|
for operation_yaml in og["operations"]:
|
|
110
116
|
request_builder = get_request_builder(
|
|
111
117
|
operation_yaml,
|
|
@@ -203,7 +209,43 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
203
209
|
except StopIteration as exc:
|
|
204
210
|
raise KeyError(f"No operation with id {operation_id} found.") from exc
|
|
205
211
|
|
|
206
|
-
|
|
212
|
+
@property
|
|
213
|
+
def has_mixin(self) -> bool:
|
|
214
|
+
"""Do we want a mixin ABC class for typing purposes?"""
|
|
215
|
+
return any(og for og in self.operation_groups if og.is_mixin)
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def lro_operations(self) -> list["OperationType"]:
|
|
219
|
+
"""all LRO operations in this SDK?"""
|
|
220
|
+
return [operation for operation_group in self.operation_groups for operation in operation_group.lro_operations]
|
|
221
|
+
|
|
222
|
+
@property
|
|
223
|
+
def has_public_lro_operations(self) -> bool:
|
|
224
|
+
"""Are there any public LRO operations in this SDK?"""
|
|
225
|
+
return any(not operation.internal for operation in self.lro_operations)
|
|
226
|
+
|
|
227
|
+
@property
|
|
228
|
+
def has_operations(self) -> bool:
|
|
229
|
+
return any(operation_group.has_operations for operation_group in self.operation_groups)
|
|
230
|
+
|
|
231
|
+
def link_lro_initial_operations(self) -> None:
|
|
232
|
+
"""Link each LRO operation to its initial operation"""
|
|
233
|
+
for operation_group in self.operation_groups:
|
|
234
|
+
for operation in operation_group.operations:
|
|
235
|
+
if isinstance(operation, (LROOperation, LROPagingOperation)):
|
|
236
|
+
operation.initial_operation = self.lookup_operation(id(operation.yaml_data["initialOperation"]))
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def has_abstract_operations(self) -> bool:
|
|
240
|
+
"""Whether there is abstract operation in any operation group."""
|
|
241
|
+
return any(og.has_abstract_operations for og in self.operation_groups)
|
|
242
|
+
|
|
243
|
+
@property
|
|
244
|
+
def has_non_abstract_operations(self) -> bool:
|
|
245
|
+
"""Whether there is non-abstract operation in any operation group."""
|
|
246
|
+
return any(og.has_non_abstract_operations for og in self.operation_groups)
|
|
247
|
+
|
|
248
|
+
def imports(self, async_mode: bool, **kwargs) -> FileImport:
|
|
207
249
|
file_import = FileImport(self.code_model)
|
|
208
250
|
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
209
251
|
if self.code_model.options["azure-arm"]:
|
|
@@ -259,46 +301,6 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
259
301
|
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
260
302
|
file_import.add_submodule_import("azure.core.settings", "settings", ImportType.SDKCORE)
|
|
261
303
|
file_import.add_submodule_import("azure.mgmt.core.tools", "get_arm_endpoints", ImportType.SDKCORE)
|
|
262
|
-
return file_import
|
|
263
|
-
|
|
264
|
-
@property
|
|
265
|
-
def has_mixin(self) -> bool:
|
|
266
|
-
"""Do we want a mixin ABC class for typing purposes?"""
|
|
267
|
-
return any(og for og in self.operation_groups if og.is_mixin)
|
|
268
|
-
|
|
269
|
-
@property
|
|
270
|
-
def lro_operations(self) -> List["OperationType"]:
|
|
271
|
-
"""all LRO operations in this SDK?"""
|
|
272
|
-
return [operation for operation_group in self.operation_groups for operation in operation_group.lro_operations]
|
|
273
|
-
|
|
274
|
-
@property
|
|
275
|
-
def has_public_lro_operations(self) -> bool:
|
|
276
|
-
"""Are there any public LRO operations in this SDK?"""
|
|
277
|
-
return any(not operation.internal for operation in self.lro_operations)
|
|
278
|
-
|
|
279
|
-
@property
|
|
280
|
-
def has_operations(self) -> bool:
|
|
281
|
-
return any(operation_group.has_operations for operation_group in self.operation_groups)
|
|
282
|
-
|
|
283
|
-
def link_lro_initial_operations(self) -> None:
|
|
284
|
-
"""Link each LRO operation to its initial operation"""
|
|
285
|
-
for operation_group in self.operation_groups:
|
|
286
|
-
for operation in operation_group.operations:
|
|
287
|
-
if isinstance(operation, (LROOperation, LROPagingOperation)):
|
|
288
|
-
operation.initial_operation = self.lookup_operation(id(operation.yaml_data["initialOperation"]))
|
|
289
|
-
|
|
290
|
-
@property
|
|
291
|
-
def has_abstract_operations(self) -> bool:
|
|
292
|
-
"""Whether there is abstract operation in any operation group."""
|
|
293
|
-
return any(og.has_abstract_operations for og in self.operation_groups)
|
|
294
|
-
|
|
295
|
-
@property
|
|
296
|
-
def has_non_abstract_operations(self) -> bool:
|
|
297
|
-
"""Whether there is non-abstract operation in any operation group."""
|
|
298
|
-
return any(og.has_non_abstract_operations for og in self.operation_groups)
|
|
299
|
-
|
|
300
|
-
def imports(self, async_mode: bool, **kwargs) -> FileImport:
|
|
301
|
-
file_import = self._imports_shared(async_mode, **kwargs)
|
|
302
304
|
if async_mode:
|
|
303
305
|
file_import.add_submodule_import("typing", "Awaitable", ImportType.STDLIB)
|
|
304
306
|
file_import.add_submodule_import(
|
|
@@ -334,32 +336,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
334
336
|
if self.code_model.model_types and self.code_model.options["models-mode"] == "msrest":
|
|
335
337
|
path_to_models = ".." if async_mode else "."
|
|
336
338
|
file_import.add_submodule_import(path_to_models, "models", ImportType.LOCAL, alias="_models")
|
|
337
|
-
elif self.code_model.options["models-mode"] == "msrest":
|
|
338
|
-
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
339
|
-
# this import will always be commented, so will always add it to the typing section
|
|
340
|
-
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB)
|
|
341
339
|
file_import.add_submodule_import("copy", "deepcopy", ImportType.STDLIB)
|
|
342
340
|
return file_import
|
|
343
341
|
|
|
344
|
-
def imports_for_multiapi(self, async_mode: bool, **kwargs) -> FileImport:
|
|
345
|
-
file_import = self._imports_shared(async_mode, **kwargs)
|
|
346
|
-
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
347
|
-
try:
|
|
348
|
-
mixin_operation = next(og for og in self.operation_groups if og.is_mixin)
|
|
349
|
-
file_import.add_submodule_import("._operations_mixin", mixin_operation.class_name, ImportType.LOCAL)
|
|
350
|
-
except StopIteration:
|
|
351
|
-
pass
|
|
352
|
-
file_import.add_submodule_import("azure.profiles", "KnownProfiles", import_type=ImportType.SDKCORE)
|
|
353
|
-
file_import.add_submodule_import("azure.profiles", "ProfileDefinition", import_type=ImportType.SDKCORE)
|
|
354
|
-
file_import.add_submodule_import(
|
|
355
|
-
"azure.profiles.multiapiclient",
|
|
356
|
-
"MultiApiClientMixin",
|
|
357
|
-
import_type=ImportType.SDKCORE,
|
|
358
|
-
)
|
|
359
|
-
return file_import
|
|
360
|
-
|
|
361
342
|
@property
|
|
362
|
-
def credential_scopes(self) -> Optional[
|
|
343
|
+
def credential_scopes(self) -> Optional[list[str]]:
|
|
363
344
|
"""Credential scopes for this client"""
|
|
364
345
|
|
|
365
346
|
if self.credential:
|
|
@@ -373,7 +354,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
373
354
|
@classmethod
|
|
374
355
|
def from_yaml(
|
|
375
356
|
cls,
|
|
376
|
-
yaml_data:
|
|
357
|
+
yaml_data: dict[str, Any],
|
|
377
358
|
code_model: "CodeModel",
|
|
378
359
|
*,
|
|
379
360
|
is_subclient: bool = False,
|
|
@@ -413,7 +394,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
413
394
|
def name(self) -> str:
|
|
414
395
|
return f"{super().name}Configuration"
|
|
415
396
|
|
|
416
|
-
def
|
|
397
|
+
def imports(self, async_mode: bool, **kwargs) -> FileImport:
|
|
417
398
|
file_import = FileImport(self.code_model)
|
|
418
399
|
file_import.add_submodule_import(
|
|
419
400
|
"pipeline" if self.code_model.is_azure_flavor else "runtime",
|
|
@@ -432,11 +413,6 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
432
413
|
policy = "AsyncARMChallengeAuthenticationPolicy" if async_mode else "ARMChallengeAuthenticationPolicy"
|
|
433
414
|
file_import.add_submodule_import("azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE)
|
|
434
415
|
file_import.add_submodule_import("azure.mgmt.core.policies", policy, ImportType.SDKCORE)
|
|
435
|
-
|
|
436
|
-
return file_import
|
|
437
|
-
|
|
438
|
-
def imports(self, async_mode: bool, **kwargs) -> FileImport:
|
|
439
|
-
file_import = self._imports_shared(async_mode, **kwargs)
|
|
440
416
|
for gp in self.parameters:
|
|
441
417
|
if gp.method_location == ParameterMethodLocation.KWARG and gp not in self.parameters.kwargs_to_pop:
|
|
442
418
|
continue
|
|
@@ -448,25 +424,8 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
448
424
|
)
|
|
449
425
|
return file_import
|
|
450
426
|
|
|
451
|
-
def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
452
|
-
file_import = self._imports_shared(async_mode, **kwargs)
|
|
453
|
-
for gp in self.parameters:
|
|
454
|
-
if (
|
|
455
|
-
gp.method_location == ParameterMethodLocation.KWARG
|
|
456
|
-
and gp not in self.parameters.kwargs_to_pop
|
|
457
|
-
and gp.client_name == "api_version"
|
|
458
|
-
):
|
|
459
|
-
continue
|
|
460
|
-
file_import.merge(
|
|
461
|
-
gp.imports_for_multiapi(
|
|
462
|
-
async_mode=async_mode,
|
|
463
|
-
**kwargs,
|
|
464
|
-
)
|
|
465
|
-
)
|
|
466
|
-
return file_import
|
|
467
|
-
|
|
468
427
|
@classmethod
|
|
469
|
-
def from_yaml(cls, yaml_data:
|
|
428
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "Config":
|
|
470
429
|
return cls(
|
|
471
430
|
yaml_data=yaml_data,
|
|
472
431
|
code_model=code_model,
|