@autorest/python 5.15.0 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -3,134 +3,123 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
import
|
|
7
|
-
from typing import Dict, List, Any, Set
|
|
8
|
-
|
|
9
|
-
from .base_model import BaseModel
|
|
10
|
-
from .operation import Operation
|
|
11
|
-
from .lro_operation import LROOperation
|
|
12
|
-
from .paging_operation import PagingOperation
|
|
13
|
-
from .lro_paging_operation import LROPagingOperation
|
|
14
|
-
from .imports import FileImport, ImportType
|
|
6
|
+
from typing import Dict, List, Any, TYPE_CHECKING
|
|
15
7
|
|
|
8
|
+
from autorest.codegen.models.utils import OrderedSet
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
from .base_model import BaseModel
|
|
11
|
+
from .operation import OperationBase, get_operation
|
|
12
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
13
|
+
from .utils import add_to_pylint_disable
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
paging_operation = yaml_data.get("extensions", {}).get("x-ms-pageable")
|
|
22
|
-
operation_schema = Operation
|
|
23
|
-
if lro_operation and paging_operation:
|
|
24
|
-
operation_schema = LROPagingOperation
|
|
25
|
-
elif lro_operation:
|
|
26
|
-
operation_schema = LROOperation
|
|
27
|
-
elif paging_operation:
|
|
28
|
-
operation_schema = PagingOperation
|
|
29
|
-
operation = operation_schema.from_yaml(yaml_data, code_model=code_model)
|
|
30
|
-
return operation
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from .code_model import CodeModel
|
|
31
17
|
|
|
32
18
|
|
|
33
19
|
class OperationGroup(BaseModel):
|
|
34
|
-
"""Represent an operation group.
|
|
20
|
+
"""Represent an operation group."""
|
|
35
21
|
|
|
36
|
-
"""
|
|
37
22
|
def __init__(
|
|
38
23
|
self,
|
|
39
|
-
code_model,
|
|
40
24
|
yaml_data: Dict[str, Any],
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
api_versions: Set[str]
|
|
25
|
+
code_model: "CodeModel",
|
|
26
|
+
operations: List[OperationBase],
|
|
27
|
+
api_versions: List[str],
|
|
45
28
|
) -> None:
|
|
46
|
-
super().__init__(yaml_data)
|
|
47
|
-
self.
|
|
48
|
-
self.
|
|
49
|
-
self.class_name = class_name
|
|
29
|
+
super().__init__(yaml_data, code_model)
|
|
30
|
+
self.class_name: str = yaml_data["className"]
|
|
31
|
+
self.property_name: str = yaml_data["propertyName"]
|
|
50
32
|
self.operations = operations
|
|
51
33
|
self.api_versions = api_versions
|
|
52
34
|
|
|
35
|
+
@property
|
|
36
|
+
def has_abstract_operations(self) -> bool:
|
|
37
|
+
return any(o for o in self.operations if o.abstract)
|
|
38
|
+
|
|
39
|
+
def base_class(self, async_mode: bool) -> str:
|
|
40
|
+
base_classes: List[str] = []
|
|
41
|
+
if self.is_mixin and self.code_model.need_mixin_abc:
|
|
42
|
+
base_classes.append("MixinABC")
|
|
43
|
+
if not (async_mode or self.code_model.options["python3_only"]):
|
|
44
|
+
base_classes.append("object")
|
|
45
|
+
if self.has_abstract_operations:
|
|
46
|
+
base_classes.append("abc.ABC")
|
|
47
|
+
return ", ".join(base_classes)
|
|
48
|
+
|
|
53
49
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
54
50
|
file_import = FileImport()
|
|
55
51
|
for operation in self.operations:
|
|
56
|
-
file_import.merge(
|
|
57
|
-
|
|
52
|
+
file_import.merge(
|
|
53
|
+
operation.imports_for_multiapi(
|
|
54
|
+
async_mode, relative_path=".." if async_mode else "."
|
|
55
|
+
)
|
|
56
|
+
)
|
|
58
57
|
return file_import
|
|
59
58
|
|
|
59
|
+
@property
|
|
60
|
+
def pylint_disable(self) -> str:
|
|
61
|
+
retval: str = ""
|
|
62
|
+
if self.has_abstract_operations:
|
|
63
|
+
retval = add_to_pylint_disable(retval, "abstract-class-instantiated")
|
|
64
|
+
return retval
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def mypy_ignore(self) -> str:
|
|
68
|
+
if self.has_abstract_operations:
|
|
69
|
+
return " # type: ignore"
|
|
70
|
+
return ""
|
|
71
|
+
|
|
60
72
|
def imports(self, async_mode: bool, is_python3_file: bool) -> FileImport:
|
|
61
73
|
file_import = FileImport()
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
file_import.add_submodule_import("azure.core.exceptions", "ResourceExistsError", ImportType.AZURECORE)
|
|
74
|
+
|
|
75
|
+
relative_path = "..." if async_mode else ".."
|
|
65
76
|
for operation in self.operations:
|
|
66
|
-
file_import.merge(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]
|
|
77
|
-
else:
|
|
78
|
-
operation_group_builders = self.code_model.rest.request_builders
|
|
79
|
-
for request_builder in operation_group_builders:
|
|
80
|
-
python3_only = self.code_model.options["python3_only"]
|
|
81
|
-
typed_sync_operation_file = self.code_model.options["add_python3_operation_files"]
|
|
82
|
-
suffix = "_py3" if typed_sync_operation_file and not python3_only else ""
|
|
77
|
+
file_import.merge(
|
|
78
|
+
operation.imports(
|
|
79
|
+
async_mode, is_python3_file, relative_path=relative_path
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
# for multiapi
|
|
83
|
+
if not self.code_model.options["version_tolerant"]:
|
|
84
|
+
if (
|
|
85
|
+
self.code_model.model_types or self.code_model.enums
|
|
86
|
+
) and self.code_model.options["models_mode"]:
|
|
83
87
|
file_import.add_submodule_import(
|
|
84
|
-
|
|
85
|
-
request_builder.name,
|
|
86
|
-
import_type=ImportType.LOCAL
|
|
88
|
+
relative_path, "models", ImportType.LOCAL, alias="_models"
|
|
87
89
|
)
|
|
88
90
|
if self.code_model.need_mixin_abc:
|
|
89
|
-
file_import.add_submodule_import(
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
file_import.add_submodule_import(".._vendor", "MixinABC", ImportType.LOCAL)
|
|
92
|
+
file_import.add_submodule_import(
|
|
93
|
+
"typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
94
|
+
)
|
|
95
|
+
file_import.define_mypy_type("T", "TypeVar('T')")
|
|
92
96
|
type_value = "Optional[Callable[[PipelineResponse[HttpRequest, {}HttpResponse], T, Dict[str, Any]], Any]]"
|
|
93
97
|
file_import.define_mypy_type(
|
|
94
|
-
"ClsType",
|
|
95
|
-
type_value.format(""),
|
|
96
|
-
type_value.format("Async")
|
|
98
|
+
"ClsType", type_value.format(""), type_value.format("Async")
|
|
97
99
|
)
|
|
98
100
|
return file_import
|
|
99
101
|
|
|
100
|
-
|
|
101
102
|
@property
|
|
102
103
|
def filename(self) -> str:
|
|
103
|
-
|
|
104
|
-
if self.is_empty_operation_group:
|
|
105
|
-
basename = self.code_model.module_name
|
|
106
|
-
|
|
107
|
-
if basename == "operations" or self.code_model.options["combine_operation_files"]:
|
|
108
|
-
return f"_operations"
|
|
109
|
-
return f"_{basename}_operations"
|
|
104
|
+
return self.operations[0].filename
|
|
110
105
|
|
|
111
106
|
@property
|
|
112
|
-
def
|
|
113
|
-
"""The operation group with no name is the direct client methods.
|
|
114
|
-
""
|
|
115
|
-
return not self.yaml_data["language"]["default"]["name"]
|
|
107
|
+
def is_mixin(self) -> bool:
|
|
108
|
+
"""The operation group with no name is the direct client methods."""
|
|
109
|
+
return self.property_name == ""
|
|
116
110
|
|
|
117
111
|
@classmethod
|
|
118
|
-
def from_yaml(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
operations.append(operation)
|
|
127
|
-
api_versions.update(operation.api_versions)
|
|
128
|
-
|
|
112
|
+
def from_yaml(
|
|
113
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
114
|
+
) -> "OperationGroup":
|
|
115
|
+
operations = [get_operation(o, code_model) for o in yaml_data["operations"]]
|
|
116
|
+
api_versions: OrderedSet[str] = {}
|
|
117
|
+
for operation in operations:
|
|
118
|
+
for api_version in operation.api_versions:
|
|
119
|
+
api_versions[api_version] = None
|
|
129
120
|
return cls(
|
|
130
|
-
code_model=code_model,
|
|
131
121
|
yaml_data=yaml_data,
|
|
132
|
-
|
|
133
|
-
class_name=yaml_data["language"]["python"]["className"],
|
|
122
|
+
code_model=code_model,
|
|
134
123
|
operations=operations,
|
|
135
|
-
api_versions=api_versions
|
|
124
|
+
api_versions=list(api_versions.keys()),
|
|
136
125
|
)
|
|
@@ -3,164 +3,148 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from .
|
|
10
|
-
from .
|
|
11
|
-
|
|
6
|
+
from typing import Dict, List, Any, Optional, Union, TYPE_CHECKING, cast, TypeVar
|
|
7
|
+
|
|
8
|
+
from .operation import Operation, OperationBase
|
|
9
|
+
from .response import PagingResponse, LROPagingResponse, Response
|
|
10
|
+
from .request_builder import (
|
|
11
|
+
OverloadedRequestBuilder,
|
|
12
|
+
RequestBuilder,
|
|
13
|
+
get_request_builder,
|
|
14
|
+
)
|
|
12
15
|
from .imports import ImportType, FileImport, TypingSection
|
|
13
|
-
from .object_schema import ObjectSchema
|
|
14
|
-
from .schema_request import SchemaRequest
|
|
15
16
|
from .parameter_list import ParameterList
|
|
17
|
+
from .model_type import ModelType
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from .code_model import CodeModel
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
PagingResponseType = TypeVar(
|
|
23
|
+
"PagingResponseType", bound=Union[PagingResponse, LROPagingResponse]
|
|
24
|
+
)
|
|
18
25
|
|
|
19
26
|
|
|
20
|
-
class
|
|
27
|
+
class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
21
28
|
def __init__(
|
|
22
29
|
self,
|
|
23
|
-
code_model,
|
|
24
30
|
yaml_data: Dict[str, Any],
|
|
31
|
+
code_model: "CodeModel",
|
|
25
32
|
name: str,
|
|
26
|
-
|
|
27
|
-
api_versions: Set[str],
|
|
33
|
+
request_builder: RequestBuilder,
|
|
28
34
|
parameters: ParameterList,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
summary: Optional[str] = None,
|
|
32
|
-
responses: Optional[List[SchemaResponse]] = None,
|
|
33
|
-
exceptions: Optional[List[SchemaResponse]] = None,
|
|
34
|
-
want_description_docstring: bool = True,
|
|
35
|
-
want_tracing: bool = True,
|
|
35
|
+
responses: List[PagingResponseType],
|
|
36
|
+
exceptions: List[Response],
|
|
36
37
|
*,
|
|
37
|
-
|
|
38
|
+
overloads: Optional[List[Operation]] = None,
|
|
39
|
+
public: bool = True,
|
|
40
|
+
want_tracing: bool = True,
|
|
41
|
+
abstract: bool = False,
|
|
42
|
+
override_success_response_to_200: bool = False,
|
|
38
43
|
) -> None:
|
|
39
|
-
super(
|
|
40
|
-
code_model,
|
|
41
|
-
yaml_data,
|
|
42
|
-
name,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
super().__init__(
|
|
45
|
+
code_model=code_model,
|
|
46
|
+
yaml_data=yaml_data,
|
|
47
|
+
name=name,
|
|
48
|
+
request_builder=request_builder,
|
|
49
|
+
parameters=parameters,
|
|
50
|
+
responses=responses,
|
|
51
|
+
exceptions=exceptions,
|
|
52
|
+
overloads=overloads,
|
|
53
|
+
public=public,
|
|
54
|
+
want_tracing=want_tracing,
|
|
55
|
+
abstract=abstract,
|
|
56
|
+
)
|
|
57
|
+
self.next_request_builder: Optional[
|
|
58
|
+
Union[RequestBuilder, OverloadedRequestBuilder]
|
|
59
|
+
] = (
|
|
60
|
+
get_request_builder(self.yaml_data["nextOperation"], code_model)
|
|
61
|
+
if self.yaml_data.get("nextOperation")
|
|
62
|
+
else None
|
|
53
63
|
)
|
|
54
|
-
self._item_name: str = yaml_data["extensions"]["x-ms-pageable"].get("itemName")
|
|
55
|
-
self._next_link_name: str = yaml_data["extensions"]["x-ms-pageable"].get("nextLinkName")
|
|
56
|
-
self.operation_name: str = yaml_data["extensions"]["x-ms-pageable"].get("operationName")
|
|
57
|
-
self.next_operation: Optional[Operation] = None
|
|
58
64
|
self.override_success_response_to_200 = override_success_response_to_200
|
|
65
|
+
self.pager_sync: str = yaml_data["pagerSync"]
|
|
66
|
+
self.pager_async: str = yaml_data["pagerAsync"]
|
|
59
67
|
|
|
60
|
-
def
|
|
68
|
+
def _get_attr_name(self, rest_api_name: str) -> str:
|
|
61
69
|
response = self.responses[0]
|
|
62
|
-
if not isinstance(response.schema, ObjectSchema):
|
|
63
|
-
raise ValueError(
|
|
64
|
-
"The response of a paging operation must be of type " + f"ObjectSchema but {response.schema} is not"
|
|
65
|
-
)
|
|
66
|
-
return response
|
|
67
|
-
|
|
68
|
-
def _find_python_name(self, rest_api_name: str, log_name: str) -> str:
|
|
69
|
-
response = self.responses[0]
|
|
70
|
-
response_schema = cast(ObjectSchema, response.schema)
|
|
71
|
-
if response_schema:
|
|
72
|
-
for prop in response_schema.properties:
|
|
73
|
-
if prop.original_swagger_name == rest_api_name:
|
|
74
|
-
return prop.name
|
|
75
|
-
raise ValueError(
|
|
76
|
-
f"While scanning x-ms-pageable, was unable to find "
|
|
77
|
-
+ f"{log_name}:{rest_api_name} in model {response_schema.name}"
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
def _get_paging_extension(self, extension_name):
|
|
81
|
-
return self.yaml_data["extensions"][extension_name]
|
|
82
|
-
|
|
83
|
-
def item_name(self, code_model) -> str:
|
|
84
|
-
item_name = self._item_name or "value"
|
|
85
70
|
try:
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
return next(
|
|
72
|
+
p.client_name
|
|
73
|
+
for p in cast(ModelType, response.type).properties
|
|
74
|
+
if p.rest_api_name == rest_api_name
|
|
89
75
|
)
|
|
90
|
-
except
|
|
91
|
-
response = self._get_response()
|
|
76
|
+
except StopIteration:
|
|
92
77
|
raise ValueError(
|
|
93
|
-
f"
|
|
94
|
-
+ f" {cast(ObjectSchema, response.schema).name} has no array called 'value'"
|
|
78
|
+
f"Can't find a matching property in response for {rest_api_name}"
|
|
95
79
|
)
|
|
96
80
|
|
|
81
|
+
def get_pager(self, async_mode: bool) -> str:
|
|
82
|
+
return self.responses[0].get_pager(async_mode)
|
|
83
|
+
|
|
97
84
|
@property
|
|
98
|
-
def
|
|
99
|
-
|
|
85
|
+
def continuation_token_name(self) -> Optional[str]:
|
|
86
|
+
rest_api_name = self.yaml_data["continuationTokenName"]
|
|
87
|
+
if not rest_api_name:
|
|
100
88
|
# That's an ok scenario, it just means no next page possible
|
|
101
89
|
return None
|
|
102
90
|
if self.code_model.options["models_mode"]:
|
|
103
|
-
return self.
|
|
104
|
-
return
|
|
91
|
+
return self._get_attr_name(rest_api_name)
|
|
92
|
+
return rest_api_name
|
|
105
93
|
|
|
106
94
|
@property
|
|
107
|
-
def
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
extension_name = "pager-async" if async_mode else "pager-sync"
|
|
113
|
-
return self._get_paging_extension(extension_name)
|
|
114
|
-
|
|
115
|
-
def get_pager(self, async_mode: bool) -> str:
|
|
116
|
-
return self.get_pager_path(async_mode).split(".")[-1]
|
|
95
|
+
def item_name(self) -> str:
|
|
96
|
+
rest_api_name = self.yaml_data["itemName"]
|
|
97
|
+
if self.code_model.options["models_mode"]:
|
|
98
|
+
return self._get_attr_name(rest_api_name)
|
|
99
|
+
return rest_api_name
|
|
117
100
|
|
|
118
101
|
@property
|
|
119
|
-
def
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return
|
|
102
|
+
def operation_type(self) -> str:
|
|
103
|
+
return "paging"
|
|
104
|
+
|
|
105
|
+
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
106
|
+
return f"ClsType[{Response.type_annotation(self.responses[0], async_mode=async_mode)}]"
|
|
124
107
|
|
|
125
|
-
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
126
|
-
file_import = super()._imports_shared(async_mode)
|
|
108
|
+
def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
109
|
+
file_import = super()._imports_shared(async_mode, **kwargs)
|
|
127
110
|
if async_mode:
|
|
128
|
-
file_import.add_submodule_import(
|
|
111
|
+
file_import.add_submodule_import(
|
|
112
|
+
"typing", "AsyncIterable", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
113
|
+
)
|
|
129
114
|
else:
|
|
130
|
-
file_import.add_submodule_import(
|
|
115
|
+
file_import.add_submodule_import(
|
|
116
|
+
"typing", "Iterable", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
117
|
+
)
|
|
131
118
|
if (
|
|
132
|
-
self.next_request_builder
|
|
133
|
-
self.code_model.options["builders_visibility"] == "embedded"
|
|
119
|
+
self.next_request_builder
|
|
120
|
+
and self.code_model.options["builders_visibility"] == "embedded"
|
|
134
121
|
and not async_mode
|
|
135
122
|
):
|
|
136
123
|
file_import.merge(self.next_request_builder.imports())
|
|
137
124
|
return file_import
|
|
138
125
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
pager = self.get_pager(async_mode)
|
|
143
|
-
|
|
144
|
-
file_import.add_submodule_import(pager_import_path, pager, ImportType.AZURECORE, TypingSection.CONDITIONAL)
|
|
145
|
-
|
|
146
|
-
return file_import
|
|
147
|
-
|
|
148
|
-
def imports(self, async_mode: bool, is_python3_file: bool) -> FileImport:
|
|
149
|
-
file_import = self._imports_base(async_mode, is_python3_file)
|
|
150
|
-
# operation adds an import for distributed_trace_async, we don't want it
|
|
151
|
-
file_import.imports = [i for i in file_import.imports if not i.submodule_name == "distributed_trace_async"]
|
|
152
|
-
|
|
153
|
-
pager_import_path = ".".join(self.get_pager_path(async_mode).split(".")[:-1])
|
|
154
|
-
pager = self.get_pager(async_mode)
|
|
155
|
-
|
|
156
|
-
file_import.add_submodule_import(pager_import_path, pager, ImportType.AZURECORE)
|
|
157
|
-
|
|
158
|
-
if async_mode:
|
|
159
|
-
file_import.add_submodule_import("azure.core.async_paging", "AsyncList", ImportType.AZURECORE)
|
|
126
|
+
@property
|
|
127
|
+
def has_optional_return_type(self) -> bool:
|
|
128
|
+
return False
|
|
160
129
|
|
|
130
|
+
def imports(
|
|
131
|
+
self, async_mode: bool, is_python3_file: bool, **kwargs: Any
|
|
132
|
+
) -> FileImport:
|
|
133
|
+
file_import = self._imports_shared(async_mode, **kwargs)
|
|
134
|
+
file_import.merge(super().imports(async_mode, is_python3_file, **kwargs))
|
|
161
135
|
if self.code_model.options["tracing"] and self.want_tracing:
|
|
162
136
|
file_import.add_submodule_import(
|
|
163
|
-
"azure.core.tracing.decorator",
|
|
137
|
+
"azure.core.tracing.decorator",
|
|
138
|
+
"distributed_trace",
|
|
139
|
+
ImportType.AZURECORE,
|
|
140
|
+
)
|
|
141
|
+
if self.next_request_builder:
|
|
142
|
+
file_import.merge(
|
|
143
|
+
self.get_request_builder_import(self.next_request_builder, async_mode)
|
|
164
144
|
)
|
|
165
145
|
|
|
166
146
|
return file_import
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class PagingOperation(PagingOperationBase[PagingResponse]):
|
|
150
|
+
...
|