@autorest/python 6.2.0 → 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/codegen/__init__.py +9 -74
- package/autorest/codegen/models/__init__.py +11 -12
- package/autorest/codegen/models/{base_type.py → base.py} +29 -10
- package/autorest/codegen/models/base_builder.py +8 -10
- package/autorest/codegen/models/client.py +111 -40
- package/autorest/codegen/models/code_model.py +131 -90
- package/autorest/codegen/models/combined_type.py +7 -7
- package/autorest/codegen/models/constant_type.py +44 -10
- package/autorest/codegen/models/credential_types.py +17 -19
- package/autorest/codegen/models/dictionary_type.py +7 -9
- package/autorest/codegen/models/enum_type.py +19 -24
- package/autorest/codegen/models/imports.py +82 -33
- package/autorest/codegen/models/list_type.py +11 -15
- package/autorest/codegen/models/lro_operation.py +6 -10
- package/autorest/codegen/models/model_type.py +20 -21
- package/autorest/codegen/models/operation.py +49 -42
- package/autorest/codegen/models/operation_group.py +11 -11
- package/autorest/codegen/models/paging_operation.py +8 -10
- package/autorest/codegen/models/parameter.py +44 -31
- package/autorest/codegen/models/parameter_list.py +16 -22
- package/autorest/codegen/models/primitive_types.py +12 -23
- package/autorest/codegen/models/property.py +11 -11
- package/autorest/codegen/models/request_builder.py +19 -19
- package/autorest/codegen/models/request_builder_parameter.py +14 -16
- package/autorest/codegen/models/response.py +24 -28
- package/autorest/codegen/serializers/__init__.py +202 -187
- package/autorest/codegen/serializers/builder_serializer.py +46 -49
- package/autorest/codegen/serializers/client_serializer.py +9 -7
- package/autorest/codegen/serializers/enum_serializer.py +4 -4
- package/autorest/codegen/serializers/general_serializer.py +26 -36
- package/autorest/codegen/serializers/import_serializer.py +30 -36
- package/autorest/codegen/serializers/metadata_serializer.py +35 -17
- package/autorest/codegen/serializers/model_init_serializer.py +6 -10
- package/autorest/codegen/serializers/model_serializer.py +42 -27
- package/autorest/codegen/serializers/operation_groups_serializer.py +12 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +13 -6
- package/autorest/codegen/serializers/patch_serializer.py +4 -4
- package/autorest/codegen/serializers/request_builders_serializer.py +6 -6
- package/autorest/codegen/serializers/sample_serializer.py +10 -12
- package/autorest/codegen/templates/client_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/config.py.jinja2 +1 -1
- package/autorest/codegen/templates/config_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/enum_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/init.py.jinja2 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
- package/autorest/codegen/templates/model_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -3
- 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 +3 -3
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -3
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +4 -1
- package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
- package/autorest/codegen/templates/rest_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/sample.py.jinja2 +5 -5
- package/autorest/codegen/templates/validation.py.jinja2 +1 -1
- package/autorest/codegen/templates/vendor.py.jinja2 +6 -6
- package/autorest/codegen/templates/version.py.jinja2 +2 -2
- package/autorest/m4reformatter/__init__.py +7 -6
- 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 +23 -26
- 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 -30
|
@@ -4,77 +4,18 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Dict, Any,
|
|
7
|
+
from typing import Dict, Any, cast
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
import yaml
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
from .. import Plugin, PluginAutorest
|
|
13
13
|
from .._utils import parse_args
|
|
14
|
-
from .models.
|
|
15
|
-
from .models.code_model import CodeModel, NamespaceModel
|
|
16
|
-
from .models.request_builder import get_request_builder
|
|
17
|
-
|
|
18
|
-
from .models.operation_group import OperationGroup
|
|
14
|
+
from .models.code_model import CodeModel
|
|
19
15
|
from .serializers import JinjaSerializer, JinjaSerializerAutorest
|
|
20
16
|
from ._utils import DEFAULT_HEADER_TEXT
|
|
21
17
|
|
|
22
18
|
|
|
23
|
-
def _build_convenience_layer(code_model: CodeModel) -> None:
|
|
24
|
-
for namespace_model in code_model.namespace_models:
|
|
25
|
-
if namespace_model.options["show_operations"]:
|
|
26
|
-
for client in namespace_model.clients:
|
|
27
|
-
client.operation_groups = [
|
|
28
|
-
OperationGroup.from_yaml(op_group, namespace_model, client)
|
|
29
|
-
for op_group in client.yaml_data.get("operationGroups", [])
|
|
30
|
-
]
|
|
31
|
-
if namespace_model.options["models_mode"] and namespace_model.model_types:
|
|
32
|
-
namespace_model.sort_model_types()
|
|
33
|
-
|
|
34
|
-
if namespace_model.options["show_operations"]:
|
|
35
|
-
for client in namespace_model.clients:
|
|
36
|
-
client.format_lro_operations()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def _create_code_model(
|
|
40
|
-
yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]
|
|
41
|
-
) -> CodeModel:
|
|
42
|
-
# Create a code model
|
|
43
|
-
code_model = CodeModel(yaml_data, options=options)
|
|
44
|
-
for namespace_model in code_model.namespace_models:
|
|
45
|
-
namespace_model.clients = [
|
|
46
|
-
Client.from_yaml(client_yaml_data, namespace_model)
|
|
47
|
-
for client_yaml_data in namespace_model.yaml_data["clients"]
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
for client in namespace_model.clients:
|
|
51
|
-
if not client.yaml_data.get("operationGroups"):
|
|
52
|
-
continue
|
|
53
|
-
for og_group in client.yaml_data["operationGroups"]:
|
|
54
|
-
for operation_yaml in og_group["operations"]:
|
|
55
|
-
request_builder = get_request_builder(
|
|
56
|
-
operation_yaml,
|
|
57
|
-
namespace_model=namespace_model,
|
|
58
|
-
client=client,
|
|
59
|
-
)
|
|
60
|
-
if request_builder.overloads:
|
|
61
|
-
client.request_builders.extend(request_builder.overloads) # type: ignore
|
|
62
|
-
client.request_builders.append(request_builder)
|
|
63
|
-
if operation_yaml.get("nextOperation"):
|
|
64
|
-
# i am a paging operation and i have a next operation.
|
|
65
|
-
# Make sure to include my next operation
|
|
66
|
-
client.request_builders.append(
|
|
67
|
-
get_request_builder(
|
|
68
|
-
operation_yaml["nextOperation"],
|
|
69
|
-
namespace_model=namespace_model,
|
|
70
|
-
client=client,
|
|
71
|
-
)
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
_build_convenience_layer(code_model)
|
|
75
|
-
return code_model
|
|
76
|
-
|
|
77
|
-
|
|
78
19
|
def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
79
20
|
|
|
80
21
|
if options["builders_visibility"] not in ["public", "hidden", "embedded"]:
|
|
@@ -242,10 +183,8 @@ class CodeGenerator(Plugin):
|
|
|
242
183
|
with open(self.options["cadl_file"], "r") as fd:
|
|
243
184
|
return yaml.safe_load(fd.read())
|
|
244
185
|
|
|
245
|
-
def get_serializer(self, code_model: CodeModel
|
|
246
|
-
return JinjaSerializer(
|
|
247
|
-
code_model, namespace_model, output_folder=self.output_folder
|
|
248
|
-
)
|
|
186
|
+
def get_serializer(self, code_model: CodeModel):
|
|
187
|
+
return JinjaSerializer(code_model, output_folder=self.output_folder)
|
|
249
188
|
|
|
250
189
|
def process(self) -> bool:
|
|
251
190
|
# List the input file, should be only one
|
|
@@ -254,14 +193,11 @@ class CodeGenerator(Plugin):
|
|
|
254
193
|
yaml_data = self.get_yaml()
|
|
255
194
|
|
|
256
195
|
if options["azure_arm"]:
|
|
257
|
-
|
|
258
|
-
self.remove_cloud_errors(namespace)
|
|
259
|
-
|
|
260
|
-
code_model = _create_code_model(yaml_data=yaml_data, options=options)
|
|
196
|
+
self.remove_cloud_errors(yaml_data)
|
|
261
197
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
198
|
+
code_model = CodeModel(yaml_data=yaml_data, options=options)
|
|
199
|
+
serializer = self.get_serializer(code_model)
|
|
200
|
+
serializer.serialize()
|
|
265
201
|
|
|
266
202
|
return True
|
|
267
203
|
|
|
@@ -357,11 +293,10 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
|
|
|
357
293
|
# Parse the received YAML
|
|
358
294
|
return yaml.safe_load(file_content)
|
|
359
295
|
|
|
360
|
-
def get_serializer(self, code_model: CodeModel
|
|
296
|
+
def get_serializer(self, code_model: CodeModel): # type: ignore
|
|
361
297
|
return JinjaSerializerAutorest(
|
|
362
298
|
self._autorestapi,
|
|
363
299
|
code_model,
|
|
364
|
-
namespace_model,
|
|
365
300
|
output_folder=self.output_folder,
|
|
366
301
|
)
|
|
367
302
|
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
7
|
from typing import Any, Dict, Union
|
|
8
|
-
from .
|
|
9
|
-
from .
|
|
8
|
+
from .base import BaseModel
|
|
9
|
+
from .base_builder import BaseBuilder
|
|
10
|
+
from .code_model import CodeModel
|
|
10
11
|
from .client import Client
|
|
11
12
|
from .model_type import ModelType
|
|
12
13
|
from .dictionary_type import DictionaryType
|
|
@@ -29,7 +30,7 @@ from .primitive_types import (
|
|
|
29
30
|
UnixTimeType,
|
|
30
31
|
)
|
|
31
32
|
from .enum_type import EnumType
|
|
32
|
-
from .
|
|
33
|
+
from .base import BaseType
|
|
33
34
|
from .constant_type import ConstantType
|
|
34
35
|
from .imports import FileImport, ImportType, TypingSection
|
|
35
36
|
from .lro_operation import LROOperation
|
|
@@ -58,7 +59,6 @@ from .request_builder import (
|
|
|
58
59
|
OverloadedRequestBuilder,
|
|
59
60
|
RequestBuilderBase,
|
|
60
61
|
)
|
|
61
|
-
from .base_builder import BaseBuilder
|
|
62
62
|
from .lro_paging_operation import LROPagingOperation
|
|
63
63
|
from .request_builder_parameter import (
|
|
64
64
|
RequestBuilderParameter,
|
|
@@ -80,7 +80,6 @@ __all__ = [
|
|
|
80
80
|
"BaseType",
|
|
81
81
|
"CodeModel",
|
|
82
82
|
"Client",
|
|
83
|
-
"NamespaceModel",
|
|
84
83
|
"ConstantType",
|
|
85
84
|
"ModelType",
|
|
86
85
|
"DictionaryType",
|
|
@@ -148,18 +147,18 @@ TYPE_TO_OBJECT = {
|
|
|
148
147
|
_LOGGER = logging.getLogger(__name__)
|
|
149
148
|
|
|
150
149
|
|
|
151
|
-
def build_type(yaml_data: Dict[str, Any],
|
|
150
|
+
def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
152
151
|
yaml_id = id(yaml_data)
|
|
153
152
|
try:
|
|
154
|
-
return
|
|
153
|
+
return code_model.lookup_type(yaml_id)
|
|
155
154
|
except KeyError:
|
|
156
155
|
# Not created yet, let's create it and add it to the index
|
|
157
156
|
pass
|
|
158
157
|
if yaml_data["type"] == "model":
|
|
159
158
|
# need to special case model to avoid recursion
|
|
160
|
-
response = ModelType(yaml_data,
|
|
161
|
-
|
|
162
|
-
response.fill_instance_from_yaml(yaml_data,
|
|
159
|
+
response = ModelType(yaml_data, code_model)
|
|
160
|
+
code_model.types_map[yaml_id] = response
|
|
161
|
+
response.fill_instance_from_yaml(yaml_data, code_model)
|
|
163
162
|
else:
|
|
164
163
|
object_type = yaml_data.get("type")
|
|
165
164
|
if object_type not in TYPE_TO_OBJECT:
|
|
@@ -168,8 +167,8 @@ def build_type(yaml_data: Dict[str, Any], namespace_model: NamespaceModel) -> Ba
|
|
|
168
167
|
yaml_data["type"],
|
|
169
168
|
)
|
|
170
169
|
object_type = "string"
|
|
171
|
-
response = TYPE_TO_OBJECT[object_type].from_yaml(yaml_data,
|
|
172
|
-
|
|
170
|
+
response = TYPE_TO_OBJECT[object_type].from_yaml(yaml_data, code_model) # type: ignore
|
|
171
|
+
code_model.types_map[yaml_id] = response
|
|
173
172
|
return response
|
|
174
173
|
|
|
175
174
|
|
|
@@ -3,17 +3,35 @@
|
|
|
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, TYPE_CHECKING, List, Optional
|
|
6
7
|
from abc import ABC, abstractmethod
|
|
7
|
-
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
|
8
|
-
|
|
9
|
-
from .base_model import BaseModel
|
|
10
8
|
from .imports import FileImport
|
|
11
9
|
|
|
10
|
+
|
|
12
11
|
if TYPE_CHECKING:
|
|
13
|
-
from .code_model import
|
|
12
|
+
from .code_model import CodeModel
|
|
14
13
|
from .model_type import ModelType
|
|
15
14
|
|
|
16
15
|
|
|
16
|
+
class BaseModel:
|
|
17
|
+
"""This is the base class for model representations that are based on some YAML data.
|
|
18
|
+
|
|
19
|
+
:param yaml_data: the yaml data for this schema
|
|
20
|
+
:type yaml_data: dict[str, Any]
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
24
|
+
self.yaml_data = yaml_data
|
|
25
|
+
self.code_model = code_model
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def id(self) -> int:
|
|
29
|
+
return id(self.yaml_data)
|
|
30
|
+
|
|
31
|
+
def __repr__(self):
|
|
32
|
+
return f"<{self.__class__.__name__}>"
|
|
33
|
+
|
|
34
|
+
|
|
17
35
|
class BaseType(BaseModel, ABC):
|
|
18
36
|
"""This is the base class for all types.
|
|
19
37
|
|
|
@@ -21,10 +39,8 @@ class BaseType(BaseModel, ABC):
|
|
|
21
39
|
:type yaml_data: dict[str, Any]
|
|
22
40
|
"""
|
|
23
41
|
|
|
24
|
-
def __init__(
|
|
25
|
-
|
|
26
|
-
) -> None:
|
|
27
|
-
super().__init__(yaml_data, namespace_model)
|
|
42
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
43
|
+
super().__init__(yaml_data, code_model)
|
|
28
44
|
self.type = yaml_data["type"] # the type discriminator
|
|
29
45
|
self.api_versions: List[str] = yaml_data.get(
|
|
30
46
|
"apiVersions", []
|
|
@@ -32,15 +48,18 @@ class BaseType(BaseModel, ABC):
|
|
|
32
48
|
|
|
33
49
|
@classmethod
|
|
34
50
|
def from_yaml(
|
|
35
|
-
cls, yaml_data: Dict[str, Any],
|
|
51
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
36
52
|
) -> "BaseType":
|
|
37
|
-
return cls(yaml_data=yaml_data,
|
|
53
|
+
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
38
54
|
|
|
39
55
|
def imports( # pylint: disable=no-self-use
|
|
40
56
|
self, **kwargs # pylint: disable=unused-argument
|
|
41
57
|
) -> FileImport:
|
|
42
58
|
return FileImport()
|
|
43
59
|
|
|
60
|
+
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
61
|
+
return self.imports(**kwargs)
|
|
62
|
+
|
|
44
63
|
@property
|
|
45
64
|
def xml_metadata(self) -> Dict[str, Any]:
|
|
46
65
|
"""XML metadata for the type, if the type has it."""
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
+
from typing import List, Dict, Any, Generic, TypeVar, Optional, Union, TYPE_CHECKING
|
|
7
8
|
from abc import abstractmethod
|
|
8
|
-
|
|
9
|
-
from .
|
|
9
|
+
|
|
10
|
+
from .base import BaseModel
|
|
10
11
|
from .parameter_list import (
|
|
11
12
|
ParameterList,
|
|
12
13
|
RequestBuilderParameterList,
|
|
13
14
|
OverloadedRequestBuilderParameterList,
|
|
14
15
|
)
|
|
15
16
|
|
|
16
|
-
|
|
17
17
|
ParameterListType = TypeVar(
|
|
18
18
|
"ParameterListType",
|
|
19
19
|
bound=Union[
|
|
@@ -22,13 +22,11 @@ ParameterListType = TypeVar(
|
|
|
22
22
|
OverloadedRequestBuilderParameterList,
|
|
23
23
|
],
|
|
24
24
|
)
|
|
25
|
-
|
|
26
|
-
|
|
27
25
|
if TYPE_CHECKING:
|
|
28
|
-
from .code_model import
|
|
26
|
+
from .code_model import CodeModel
|
|
27
|
+
from .client import Client
|
|
29
28
|
from .operation import Operation
|
|
30
29
|
from .request_builder import RequestBuilder
|
|
31
|
-
from .client import Client
|
|
32
30
|
|
|
33
31
|
_LOGGER = logging.getLogger(__name__)
|
|
34
32
|
|
|
@@ -41,7 +39,7 @@ class BaseBuilder(
|
|
|
41
39
|
def __init__(
|
|
42
40
|
self,
|
|
43
41
|
yaml_data: Dict[str, Any],
|
|
44
|
-
|
|
42
|
+
code_model: "CodeModel",
|
|
45
43
|
client: "Client",
|
|
46
44
|
name: str,
|
|
47
45
|
parameters: ParameterListType,
|
|
@@ -49,7 +47,7 @@ class BaseBuilder(
|
|
|
49
47
|
overloads=None,
|
|
50
48
|
want_tracing: bool = True,
|
|
51
49
|
) -> None:
|
|
52
|
-
super().__init__(yaml_data=yaml_data,
|
|
50
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
53
51
|
self.client = client
|
|
54
52
|
self.name = name
|
|
55
53
|
self._description: str = yaml_data.get("description", "")
|
|
@@ -66,7 +64,7 @@ class BaseBuilder(
|
|
|
66
64
|
self.api_versions: List[str] = yaml_data["apiVersions"]
|
|
67
65
|
self.added_on: Optional[str] = yaml_data.get("addedOn")
|
|
68
66
|
|
|
69
|
-
if
|
|
67
|
+
if code_model.options["version_tolerant"] and yaml_data.get("abstract"):
|
|
70
68
|
_LOGGER.warning(
|
|
71
69
|
'Not going to generate operation "%s" because we are unable to generate this '
|
|
72
70
|
"type of operation right now. "
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union, List, Optional
|
|
7
7
|
|
|
8
|
-
from .
|
|
8
|
+
from .base import BaseModel
|
|
9
9
|
from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
|
|
10
10
|
from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
11
11
|
from .utils import add_to_pylint_disable
|
|
@@ -13,8 +13,9 @@ from .operation_group import OperationGroup
|
|
|
13
13
|
from .request_builder import (
|
|
14
14
|
RequestBuilder,
|
|
15
15
|
OverloadedRequestBuilder,
|
|
16
|
+
get_request_builder,
|
|
16
17
|
)
|
|
17
|
-
from .parameter import Parameter
|
|
18
|
+
from .parameter import Parameter, ParameterMethodLocation
|
|
18
19
|
|
|
19
20
|
ParameterListType = TypeVar(
|
|
20
21
|
"ParameterListType",
|
|
@@ -22,7 +23,7 @@ ParameterListType = TypeVar(
|
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
if TYPE_CHECKING:
|
|
25
|
-
from .code_model import
|
|
26
|
+
from .code_model import CodeModel
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
@@ -31,10 +32,10 @@ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
|
31
32
|
def __init__(
|
|
32
33
|
self,
|
|
33
34
|
yaml_data: Dict[str, Any],
|
|
34
|
-
|
|
35
|
+
code_model: "CodeModel",
|
|
35
36
|
parameters: ParameterListType,
|
|
36
37
|
):
|
|
37
|
-
super().__init__(yaml_data,
|
|
38
|
+
super().__init__(yaml_data, code_model)
|
|
38
39
|
self.parameters = parameters
|
|
39
40
|
self.url: str = self.yaml_data[
|
|
40
41
|
"url"
|
|
@@ -56,18 +57,49 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
56
57
|
def __init__(
|
|
57
58
|
self,
|
|
58
59
|
yaml_data: Dict[str, Any],
|
|
59
|
-
|
|
60
|
+
code_model: "CodeModel",
|
|
60
61
|
parameters: ClientGlobalParameterList,
|
|
62
|
+
*,
|
|
63
|
+
is_subclient: bool = False,
|
|
61
64
|
):
|
|
62
|
-
super().__init__(yaml_data,
|
|
65
|
+
super().__init__(yaml_data, code_model, parameters)
|
|
63
66
|
self.operation_groups: List[OperationGroup] = []
|
|
64
|
-
self.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
self.
|
|
67
|
+
self.config = Config.from_yaml(yaml_data, self.code_model)
|
|
68
|
+
self.is_subclient = is_subclient
|
|
69
|
+
self.request_builders = self._build_request_builders()
|
|
70
|
+
if self.code_model.options["show_operations"]:
|
|
71
|
+
self.operation_groups = [
|
|
72
|
+
OperationGroup.from_yaml(op_group, code_model, self)
|
|
73
|
+
for op_group in self.yaml_data.get("operationGroups", [])
|
|
74
|
+
]
|
|
75
|
+
self.format_lro_operations()
|
|
76
|
+
|
|
77
|
+
def _build_request_builders(self):
|
|
78
|
+
request_builders: List[Union[RequestBuilder, OverloadedRequestBuilder]] = []
|
|
79
|
+
for og_group in self.yaml_data["operationGroups"]:
|
|
80
|
+
for operation_yaml in og_group["operations"]:
|
|
81
|
+
request_builder = get_request_builder(
|
|
82
|
+
operation_yaml,
|
|
83
|
+
code_model=self.code_model,
|
|
84
|
+
client=self,
|
|
85
|
+
)
|
|
86
|
+
if request_builder.overloads:
|
|
87
|
+
request_builders.extend(request_builder.overloads) # type: ignore
|
|
88
|
+
request_builders.append(request_builder)
|
|
89
|
+
if operation_yaml.get("nextOperation"):
|
|
90
|
+
# i am a paging operation and i have a next operation.
|
|
91
|
+
# Make sure to include my next operation
|
|
92
|
+
request_builders.append(
|
|
93
|
+
get_request_builder(
|
|
94
|
+
operation_yaml["nextOperation"],
|
|
95
|
+
code_model=self.code_model,
|
|
96
|
+
client=self,
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
return request_builders
|
|
68
100
|
|
|
69
101
|
def pipeline_class(self, async_mode: bool) -> str:
|
|
70
|
-
if self.
|
|
102
|
+
if self.code_model.options["azure_arm"]:
|
|
71
103
|
if async_mode:
|
|
72
104
|
return "AsyncARMPipelineClient"
|
|
73
105
|
return "ARMPipelineClient"
|
|
@@ -85,7 +117,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
85
117
|
"""Name of the send request function"""
|
|
86
118
|
return (
|
|
87
119
|
"send_request"
|
|
88
|
-
if self.
|
|
120
|
+
if self.code_model.options["show_send_request"]
|
|
89
121
|
else "_send_request"
|
|
90
122
|
)
|
|
91
123
|
|
|
@@ -105,8 +137,8 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
105
137
|
def filename(self) -> str:
|
|
106
138
|
"""Name of the file for the client"""
|
|
107
139
|
if (
|
|
108
|
-
self.
|
|
109
|
-
or self.
|
|
140
|
+
self.code_model.options["version_tolerant"]
|
|
141
|
+
or self.code_model.options["low_level_client"]
|
|
110
142
|
):
|
|
111
143
|
return "_client"
|
|
112
144
|
return f"_{self.legacy_filename}"
|
|
@@ -130,7 +162,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
130
162
|
file_import.add_submodule_import(
|
|
131
163
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
132
164
|
)
|
|
133
|
-
if self.
|
|
165
|
+
if self.code_model.options["azure_arm"]:
|
|
134
166
|
file_import.add_submodule_import(
|
|
135
167
|
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.AZURECORE
|
|
136
168
|
)
|
|
@@ -140,6 +172,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
140
172
|
)
|
|
141
173
|
|
|
142
174
|
for gp in self.parameters:
|
|
175
|
+
if (
|
|
176
|
+
gp.method_location == ParameterMethodLocation.KWARG
|
|
177
|
+
and gp not in self.parameters.kwargs_to_pop
|
|
178
|
+
):
|
|
179
|
+
continue
|
|
143
180
|
file_import.merge(gp.imports(async_mode))
|
|
144
181
|
file_import.add_submodule_import(
|
|
145
182
|
"._configuration",
|
|
@@ -147,7 +184,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
147
184
|
ImportType.LOCAL,
|
|
148
185
|
)
|
|
149
186
|
file_import.add_msrest_import(
|
|
150
|
-
self.
|
|
187
|
+
self.code_model,
|
|
151
188
|
".." if async_mode else ".",
|
|
152
189
|
MsrestImportType.SerializerDeserializer,
|
|
153
190
|
TypingSection.REGULAR,
|
|
@@ -176,6 +213,15 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
176
213
|
]
|
|
177
214
|
)
|
|
178
215
|
|
|
216
|
+
@property
|
|
217
|
+
def has_operations(self) -> bool:
|
|
218
|
+
return any(
|
|
219
|
+
[
|
|
220
|
+
bool(operation_group.operations)
|
|
221
|
+
for operation_group in self.operation_groups
|
|
222
|
+
]
|
|
223
|
+
)
|
|
224
|
+
|
|
179
225
|
def format_lro_operations(self) -> None:
|
|
180
226
|
"""Adds operations and attributes needed for LROs.
|
|
181
227
|
If there are LRO functions in here, will add initial LRO function. Will also set the return
|
|
@@ -197,9 +243,9 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
197
243
|
azure.core.pipeline.transport.HttpRequests
|
|
198
244
|
"""
|
|
199
245
|
return (
|
|
200
|
-
self.
|
|
246
|
+
self.code_model.options["show_operations"]
|
|
201
247
|
and bool(self.request_builders)
|
|
202
|
-
and not self.
|
|
248
|
+
and not self.code_model.options["version_tolerant"]
|
|
203
249
|
)
|
|
204
250
|
|
|
205
251
|
@property
|
|
@@ -232,18 +278,18 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
232
278
|
)
|
|
233
279
|
for og in self.operation_groups:
|
|
234
280
|
file_import.add_submodule_import(
|
|
235
|
-
f".{self.
|
|
281
|
+
f".{self.code_model.operations_folder_name}",
|
|
236
282
|
og.class_name,
|
|
237
283
|
ImportType.LOCAL,
|
|
238
284
|
)
|
|
239
285
|
|
|
240
286
|
if (
|
|
241
|
-
self.
|
|
242
|
-
and self.
|
|
287
|
+
self.code_model.model_types
|
|
288
|
+
and self.code_model.options["models_mode"] == "msrest"
|
|
243
289
|
):
|
|
244
290
|
path_to_models = ".." if async_mode else "."
|
|
245
|
-
if len(self.
|
|
246
|
-
self.
|
|
291
|
+
if len(self.code_model.model_types) != len(
|
|
292
|
+
self.code_model.public_model_types
|
|
247
293
|
):
|
|
248
294
|
# this means we have hidden models. In that case, we import directly from the models
|
|
249
295
|
# file, not the module, bc we don't expose the hidden models in the models module
|
|
@@ -251,7 +297,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
251
297
|
# Also in this case, we're in version tolerant, so python3 only is true
|
|
252
298
|
file_import.add_submodule_import(
|
|
253
299
|
f"{path_to_models}models",
|
|
254
|
-
self.
|
|
300
|
+
self.code_model.models_filename,
|
|
255
301
|
ImportType.LOCAL,
|
|
256
302
|
alias="models",
|
|
257
303
|
)
|
|
@@ -259,7 +305,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
259
305
|
file_import.add_submodule_import(
|
|
260
306
|
path_to_models, "models", ImportType.LOCAL
|
|
261
307
|
)
|
|
262
|
-
elif self.
|
|
308
|
+
elif self.code_model.options["models_mode"] == "msrest":
|
|
263
309
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
264
310
|
# this import will always be commented, so will always add it to the typing section
|
|
265
311
|
file_import.add_submodule_import(
|
|
@@ -295,12 +341,17 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
295
341
|
|
|
296
342
|
@classmethod
|
|
297
343
|
def from_yaml(
|
|
298
|
-
cls,
|
|
344
|
+
cls,
|
|
345
|
+
yaml_data: Dict[str, Any],
|
|
346
|
+
code_model: "CodeModel",
|
|
347
|
+
*,
|
|
348
|
+
is_subclient: bool = False,
|
|
299
349
|
) -> "Client":
|
|
300
350
|
return cls(
|
|
301
351
|
yaml_data=yaml_data,
|
|
302
|
-
|
|
303
|
-
parameters=ClientGlobalParameterList.from_yaml(yaml_data,
|
|
352
|
+
code_model=code_model,
|
|
353
|
+
parameters=ClientGlobalParameterList.from_yaml(yaml_data, code_model),
|
|
354
|
+
is_subclient=is_subclient,
|
|
304
355
|
)
|
|
305
356
|
|
|
306
357
|
|
|
@@ -316,7 +367,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
316
367
|
|
|
317
368
|
@property
|
|
318
369
|
def sdk_moniker(self) -> str:
|
|
319
|
-
package_name = self.
|
|
370
|
+
package_name = self.code_model.options["package_name"]
|
|
320
371
|
if package_name and package_name.startswith("azure-"):
|
|
321
372
|
package_name = package_name[len("azure-") :]
|
|
322
373
|
return package_name if package_name else self.yaml_data["name"].lower()
|
|
@@ -325,7 +376,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
325
376
|
def name(self) -> str:
|
|
326
377
|
return f"{super().name}Configuration"
|
|
327
378
|
|
|
328
|
-
def
|
|
379
|
+
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
329
380
|
file_import = FileImport()
|
|
330
381
|
file_import.add_submodule_import(
|
|
331
382
|
"azure.core.configuration", "Configuration", ImportType.AZURECORE
|
|
@@ -336,13 +387,11 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
336
387
|
file_import.add_submodule_import(
|
|
337
388
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
338
389
|
)
|
|
339
|
-
if self.
|
|
390
|
+
if self.code_model.options["package_version"]:
|
|
340
391
|
file_import.add_submodule_import(
|
|
341
392
|
".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL
|
|
342
393
|
)
|
|
343
|
-
|
|
344
|
-
file_import.merge(gp.imports(async_mode=async_mode))
|
|
345
|
-
if self.namespace_model.options["azure_arm"]:
|
|
394
|
+
if self.code_model.options["azure_arm"]:
|
|
346
395
|
policy = (
|
|
347
396
|
"AsyncARMChallengeAuthenticationPolicy"
|
|
348
397
|
if async_mode
|
|
@@ -354,14 +403,36 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
354
403
|
file_import.add_submodule_import(
|
|
355
404
|
"azure.mgmt.core.policies", policy, ImportType.AZURECORE
|
|
356
405
|
)
|
|
406
|
+
|
|
407
|
+
return file_import
|
|
408
|
+
|
|
409
|
+
def imports(self, async_mode: bool) -> FileImport:
|
|
410
|
+
file_import = self._imports_shared(async_mode)
|
|
411
|
+
for gp in self.parameters:
|
|
412
|
+
if (
|
|
413
|
+
gp.method_location == ParameterMethodLocation.KWARG
|
|
414
|
+
and gp not in self.parameters.kwargs_to_pop
|
|
415
|
+
):
|
|
416
|
+
continue
|
|
417
|
+
file_import.merge(gp.imports(async_mode=async_mode))
|
|
418
|
+
return file_import
|
|
419
|
+
|
|
420
|
+
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
421
|
+
file_import = self._imports_shared(async_mode)
|
|
422
|
+
for gp in self.parameters:
|
|
423
|
+
if (
|
|
424
|
+
gp.method_location == ParameterMethodLocation.KWARG
|
|
425
|
+
and gp not in self.parameters.kwargs_to_pop
|
|
426
|
+
and gp.client_name == "api_version"
|
|
427
|
+
):
|
|
428
|
+
continue
|
|
429
|
+
file_import.merge(gp.imports_for_multiapi(async_mode=async_mode))
|
|
357
430
|
return file_import
|
|
358
431
|
|
|
359
432
|
@classmethod
|
|
360
|
-
def from_yaml(
|
|
361
|
-
cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
|
|
362
|
-
) -> "Config":
|
|
433
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Config":
|
|
363
434
|
return cls(
|
|
364
435
|
yaml_data=yaml_data,
|
|
365
|
-
|
|
366
|
-
parameters=ConfigGlobalParameterList.from_yaml(yaml_data,
|
|
436
|
+
code_model=code_model,
|
|
437
|
+
parameters=ConfigGlobalParameterList.from_yaml(yaml_data, code_model),
|
|
367
438
|
)
|