@autorest/python 5.16.0 → 5.19.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 +79 -4
- package/README.md +30 -4
- package/autorest/__init__.py +1 -1
- package/autorest/codegen/__init__.py +55 -211
- package/autorest/codegen/models/__init__.py +116 -83
- package/autorest/codegen/models/base_builder.py +49 -88
- package/autorest/codegen/models/base_model.py +1 -1
- package/autorest/codegen/models/{base_schema.py → base_type.py} +61 -39
- package/autorest/codegen/models/client.py +165 -53
- package/autorest/codegen/models/code_model.py +122 -257
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
- 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 +80 -2
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +79 -156
- package/autorest/codegen/models/lro_paging_operation.py +28 -11
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +331 -298
- package/autorest/codegen/models/operation_group.py +54 -91
- package/autorest/codegen/models/paging_operation.py +82 -123
- package/autorest/codegen/models/parameter.py +289 -396
- package/autorest/codegen/models/parameter_list.py +355 -360
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +123 -139
- package/autorest/codegen/models/request_builder.py +130 -102
- package/autorest/codegen/models/request_builder_parameter.py +112 -100
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +12 -19
- package/autorest/codegen/serializers/__init__.py +55 -37
- package/autorest/codegen/serializers/builder_serializer.py +695 -1144
- package/autorest/codegen/serializers/client_serializer.py +92 -89
- package/autorest/codegen/serializers/general_serializer.py +15 -69
- package/autorest/codegen/serializers/import_serializer.py +7 -4
- package/autorest/codegen/serializers/metadata_serializer.py +15 -104
- package/autorest/codegen/serializers/model_base_serializer.py +49 -36
- package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
- package/autorest/codegen/serializers/model_init_serializer.py +2 -4
- package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
- package/autorest/codegen/serializers/operation_groups_serializer.py +7 -13
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/request_builders_serializer.py +13 -30
- package/autorest/codegen/serializers/utils.py +0 -140
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +10 -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 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
- 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 +6 -8
- package/autorest/codegen/templates/operation_group.py.jinja2 +21 -8
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_tools.jinja2 +11 -3
- package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +10 -15
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
- package/autorest/codegen/templates/setup.py.jinja2 +13 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +11 -1
- package/autorest/jsonrpc/server.py +15 -3
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/models/client.py +12 -2
- package/autorest/multiapi/models/code_model.py +1 -1
- package/autorest/multiapi/serializers/__init__.py +18 -4
- 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/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 +21 -16
- package/package.json +2 -2
- package/autorest/codegen/models/credential_model.py +0 -55
- package/autorest/codegen/models/credential_schema.py +0 -95
- package/autorest/codegen/models/credential_schema_policy.py +0 -73
- package/autorest/codegen/models/dictionary_schema.py +0 -106
- package/autorest/codegen/models/enum_schema.py +0 -225
- package/autorest/codegen/models/list_schema.py +0 -135
- package/autorest/codegen/models/object_schema.py +0 -303
- package/autorest/codegen/models/primitive_schemas.py +0 -495
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
- package/autorest/codegen/models/schema_request.py +0 -55
- package/autorest/codegen/models/schema_response.py +0 -141
- package/autorest/namer/__init__.py +0 -23
- package/autorest/namer/name_converter.py +0 -509
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
7
|
from typing import Dict, Any, Optional, TYPE_CHECKING
|
|
8
|
-
from .
|
|
9
|
-
from .primitive_schemas import get_primitive_schema, PrimitiveSchema
|
|
8
|
+
from .base_type import BaseType
|
|
10
9
|
from .imports import FileImport
|
|
10
|
+
from .utils import add_to_description
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from .code_model import CodeModel
|
|
@@ -15,29 +15,29 @@ if TYPE_CHECKING:
|
|
|
15
15
|
_LOGGER = logging.getLogger(__name__)
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class
|
|
18
|
+
class ConstantType(BaseType):
|
|
19
19
|
"""Schema for constants that will be serialized.
|
|
20
20
|
|
|
21
21
|
:param yaml_data: the yaml data for this schema
|
|
22
22
|
:type yaml_data: dict[str, Any]
|
|
23
23
|
:param str value: The actual value of this constant.
|
|
24
24
|
:param schema: The schema for the value of this constant.
|
|
25
|
-
:type schema: ~autorest.models.
|
|
25
|
+
:type schema: ~autorest.models.PrimitiveType
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
28
|
def __init__(
|
|
29
29
|
self,
|
|
30
30
|
yaml_data: Dict[str, Any],
|
|
31
31
|
code_model: "CodeModel",
|
|
32
|
-
|
|
32
|
+
value_type: BaseType,
|
|
33
33
|
value: Optional[str],
|
|
34
34
|
) -> None:
|
|
35
35
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
36
|
+
self.value_type = value_type
|
|
36
37
|
self.value = value
|
|
37
|
-
self.schema = schema
|
|
38
38
|
|
|
39
|
-
def get_declaration(self, value
|
|
40
|
-
if value != self.value:
|
|
39
|
+
def get_declaration(self, value=None):
|
|
40
|
+
if value and value != self.value:
|
|
41
41
|
_LOGGER.warning(
|
|
42
42
|
"Passed in value of %s differs from constant value of %s. Choosing constant value",
|
|
43
43
|
str(value),
|
|
@@ -45,7 +45,15 @@ class ConstantSchema(BaseSchema):
|
|
|
45
45
|
)
|
|
46
46
|
if self.value is None:
|
|
47
47
|
return "None"
|
|
48
|
-
return self.
|
|
48
|
+
return self.value_type.get_declaration(self.value)
|
|
49
|
+
|
|
50
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
51
|
+
if is_operation_file:
|
|
52
|
+
return ""
|
|
53
|
+
return add_to_description(
|
|
54
|
+
self.yaml_data.get("description", ""),
|
|
55
|
+
f"Default value is {self.get_declaration()}.",
|
|
56
|
+
)
|
|
49
57
|
|
|
50
58
|
@property
|
|
51
59
|
def serialization_type(self) -> str:
|
|
@@ -54,60 +62,61 @@ class ConstantSchema(BaseSchema):
|
|
|
54
62
|
:return: The serialization value for msrest
|
|
55
63
|
:rtype: str
|
|
56
64
|
"""
|
|
57
|
-
return self.
|
|
65
|
+
return self.value_type.serialization_type
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
def docstring_text(self) -> str:
|
|
67
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
61
68
|
return "constant"
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
def docstring_type(self) -> str:
|
|
70
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
65
71
|
"""The python type used for RST syntax input and type annotation.
|
|
66
72
|
|
|
67
73
|
:param str namespace: Optional. The namespace for the models.
|
|
68
74
|
"""
|
|
69
|
-
return self.
|
|
75
|
+
return self.value_type.docstring_type(**kwargs)
|
|
70
76
|
|
|
71
|
-
def type_annotation(self,
|
|
72
|
-
return self.
|
|
77
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
78
|
+
return self.value_type.type_annotation(**kwargs)
|
|
73
79
|
|
|
74
80
|
@classmethod
|
|
75
81
|
def from_yaml(
|
|
76
82
|
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
77
|
-
) -> "
|
|
78
|
-
"""Constructs a
|
|
83
|
+
) -> "ConstantType":
|
|
84
|
+
"""Constructs a ConstantType from yaml data.
|
|
79
85
|
|
|
80
86
|
:param yaml_data: the yaml data from which we will construct this schema
|
|
81
87
|
:type yaml_data: dict[str, Any]
|
|
82
88
|
|
|
83
|
-
:return: A created
|
|
84
|
-
:rtype: ~autorest.models.
|
|
89
|
+
:return: A created ConstantType
|
|
90
|
+
:rtype: ~autorest.models.ConstantType
|
|
85
91
|
"""
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if yaml_data["language"]["python"].get("name")
|
|
89
|
-
else ""
|
|
90
|
-
)
|
|
91
|
-
_LOGGER.debug("Parsing %s constant", name)
|
|
92
|
+
from . import build_type
|
|
93
|
+
|
|
92
94
|
return cls(
|
|
93
95
|
yaml_data=yaml_data,
|
|
94
96
|
code_model=code_model,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
),
|
|
98
|
-
value=yaml_data.get("value", {}).get("value", None),
|
|
97
|
+
value_type=build_type(yaml_data["valueType"], code_model),
|
|
98
|
+
value=yaml_data["value"],
|
|
99
99
|
)
|
|
100
100
|
|
|
101
|
-
def get_json_template_representation(
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
def get_json_template_representation(
|
|
102
|
+
self,
|
|
103
|
+
*,
|
|
104
|
+
optional: bool = True,
|
|
105
|
+
# pylint: disable=unused-argument
|
|
106
|
+
client_default_value_declaration: Optional[str] = None,
|
|
107
|
+
description: Optional[str] = None,
|
|
108
|
+
) -> Any:
|
|
109
|
+
return self.value_type.get_json_template_representation(
|
|
110
|
+
optional=optional,
|
|
111
|
+
client_default_value_declaration=self.get_declaration(),
|
|
112
|
+
description=description,
|
|
113
|
+
)
|
|
104
114
|
|
|
105
|
-
def imports(self) -> FileImport:
|
|
115
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
106
116
|
file_import = FileImport()
|
|
107
|
-
file_import.merge(self.
|
|
117
|
+
file_import.merge(self.value_type.imports(**kwargs))
|
|
108
118
|
return file_import
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return file_import
|
|
120
|
+
@property
|
|
121
|
+
def instance_check_template(self) -> str:
|
|
122
|
+
return self.value_type.instance_check_template
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from abc import abstractmethod
|
|
7
|
+
from typing import (
|
|
8
|
+
Optional,
|
|
9
|
+
Any,
|
|
10
|
+
Dict,
|
|
11
|
+
TYPE_CHECKING,
|
|
12
|
+
List,
|
|
13
|
+
Generic,
|
|
14
|
+
TypeVar,
|
|
15
|
+
Union,
|
|
16
|
+
cast,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
20
|
+
from .base_type import BaseType
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from .code_model import CodeModel
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _CredentialPolicyBaseType:
|
|
27
|
+
"""Base class for our different credential policy types.
|
|
28
|
+
|
|
29
|
+
Inherited by our BearerTokenCredentialPolicy and AzureKeyCredentialPolicy types.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
33
|
+
self.yaml_data = yaml_data
|
|
34
|
+
self.code_model = code_model
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def call(self, async_mode: bool) -> str:
|
|
38
|
+
"""
|
|
39
|
+
How to call this credential policy. Used to initialize the credential policy in the config file.
|
|
40
|
+
"""
|
|
41
|
+
...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
|
|
45
|
+
"""Credential policy type representing BearerTokenCredentialPolicy"""
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
yaml_data: Dict[str, Any],
|
|
50
|
+
code_model: "CodeModel",
|
|
51
|
+
credential_scopes: List[str],
|
|
52
|
+
) -> None:
|
|
53
|
+
super().__init__(yaml_data, code_model)
|
|
54
|
+
self.credential_scopes = credential_scopes
|
|
55
|
+
|
|
56
|
+
def call(self, async_mode: bool) -> str:
|
|
57
|
+
policy_name = f"{'Async' if async_mode else ''}BearerTokenCredentialPolicy"
|
|
58
|
+
return f"policies.{policy_name}(self.credential, *self.credential_scopes, **kwargs)"
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def from_yaml(
|
|
62
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
63
|
+
) -> "BearerTokenCredentialPolicyType":
|
|
64
|
+
return cls(yaml_data, code_model, yaml_data["credentialScopes"])
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
|
|
68
|
+
"""Credential policy type representing ARMChallengeAuthenticationPolicy"""
|
|
69
|
+
|
|
70
|
+
def call(self, async_mode: bool) -> str:
|
|
71
|
+
policy_name = f"{'Async' if async_mode else ''}ARMChallengeAuthenticationPolicy"
|
|
72
|
+
return f"{policy_name}(self.credential, *self.credential_scopes, **kwargs)"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
76
|
+
def __init__(
|
|
77
|
+
self, yaml_data: Dict[str, Any], code_model: "CodeModel", key: str
|
|
78
|
+
) -> None:
|
|
79
|
+
super().__init__(yaml_data, code_model)
|
|
80
|
+
self.key = key
|
|
81
|
+
|
|
82
|
+
def call(self, async_mode: bool) -> str:
|
|
83
|
+
return f'policies.AzureKeyCredentialPolicy(self.credential, "{self.key}", **kwargs)'
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def from_yaml(
|
|
87
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
88
|
+
) -> "AzureKeyCredentialPolicyType":
|
|
89
|
+
return cls(yaml_data, code_model, yaml_data["key"])
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
CredentialPolicyType = TypeVar(
|
|
93
|
+
"CredentialPolicyType",
|
|
94
|
+
bound=Union[
|
|
95
|
+
BearerTokenCredentialPolicyType,
|
|
96
|
+
ARMChallengeAuthenticationPolicyType,
|
|
97
|
+
AzureKeyCredentialPolicyType,
|
|
98
|
+
],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class CredentialType(
|
|
103
|
+
Generic[CredentialPolicyType], BaseType
|
|
104
|
+
): # pylint:disable=abstract-method
|
|
105
|
+
"""Store info about the type of the credential. Can be either an AzureKeyCredential or a TokenCredential"""
|
|
106
|
+
|
|
107
|
+
def __init__(
|
|
108
|
+
self,
|
|
109
|
+
yaml_data: Dict[str, Any],
|
|
110
|
+
code_model: "CodeModel",
|
|
111
|
+
policy: CredentialPolicyType,
|
|
112
|
+
) -> None:
|
|
113
|
+
super().__init__(yaml_data, code_model)
|
|
114
|
+
self.policy = policy
|
|
115
|
+
|
|
116
|
+
def description(
|
|
117
|
+
self, *, is_operation_file: bool # pylint: disable=unused-argument
|
|
118
|
+
) -> str:
|
|
119
|
+
return ""
|
|
120
|
+
|
|
121
|
+
def get_json_template_representation(
|
|
122
|
+
self,
|
|
123
|
+
*,
|
|
124
|
+
optional: bool = True,
|
|
125
|
+
client_default_value_declaration: Optional[str] = None,
|
|
126
|
+
description: Optional[str] = None,
|
|
127
|
+
) -> Any:
|
|
128
|
+
raise TypeError(
|
|
129
|
+
"You should not try to get a JSON template representation of a CredentialSchema"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
133
|
+
return "credential"
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def serialization_type(self) -> str:
|
|
137
|
+
return self.docstring_type()
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def from_yaml(
|
|
141
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
142
|
+
) -> "CredentialType":
|
|
143
|
+
from . import build_type
|
|
144
|
+
|
|
145
|
+
return cls(
|
|
146
|
+
yaml_data,
|
|
147
|
+
code_model,
|
|
148
|
+
policy=cast(
|
|
149
|
+
CredentialPolicyType, build_type(yaml_data["policy"], code_model)
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class TokenCredentialType(
|
|
155
|
+
CredentialType[ # pylint: disable=unsubscriptable-object
|
|
156
|
+
Union[BearerTokenCredentialPolicyType, ARMChallengeAuthenticationPolicyType]
|
|
157
|
+
]
|
|
158
|
+
):
|
|
159
|
+
"""Type of a token credential. Used by BearerAuth and ARMChallenge policies"""
|
|
160
|
+
|
|
161
|
+
def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=no-self-use
|
|
162
|
+
if kwargs.pop("async_mode"):
|
|
163
|
+
return '"AsyncTokenCredential"'
|
|
164
|
+
return '"TokenCredential"'
|
|
165
|
+
|
|
166
|
+
def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=no-self-use
|
|
167
|
+
if kwargs.pop("async_mode"):
|
|
168
|
+
return "~azure.core.credentials_async.AsyncTokenCredential"
|
|
169
|
+
return "~azure.core.credentials.TokenCredential"
|
|
170
|
+
|
|
171
|
+
def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=no-self-use
|
|
172
|
+
file_import = FileImport()
|
|
173
|
+
if kwargs.pop("async_mode"):
|
|
174
|
+
file_import.add_submodule_import(
|
|
175
|
+
"azure.core.credentials_async",
|
|
176
|
+
"AsyncTokenCredential",
|
|
177
|
+
ImportType.AZURECORE,
|
|
178
|
+
typing_section=TypingSection.TYPING,
|
|
179
|
+
)
|
|
180
|
+
else:
|
|
181
|
+
file_import.add_submodule_import(
|
|
182
|
+
"azure.core.credentials",
|
|
183
|
+
"TokenCredential",
|
|
184
|
+
ImportType.AZURECORE,
|
|
185
|
+
typing_section=TypingSection.TYPING,
|
|
186
|
+
)
|
|
187
|
+
return file_import
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def instance_check_template(self) -> str:
|
|
191
|
+
return "hasattr({}, get_token)"
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class AzureKeyCredentialType(
|
|
195
|
+
# pylint: disable=unsubscriptable-object
|
|
196
|
+
CredentialType[AzureKeyCredentialPolicyType]
|
|
197
|
+
):
|
|
198
|
+
"""Type for an AzureKeyCredential"""
|
|
199
|
+
|
|
200
|
+
def docstring_type( # pylint: disable=no-self-use
|
|
201
|
+
self, **kwargs: Any # pylint: disable=unused-argument
|
|
202
|
+
) -> str:
|
|
203
|
+
return "~azure.core.credentials.AzureKeyCredential"
|
|
204
|
+
|
|
205
|
+
def type_annotation( # pylint: disable=no-self-use
|
|
206
|
+
self, **kwargs: Any # pylint: disable=unused-argument
|
|
207
|
+
) -> str:
|
|
208
|
+
return "AzureKeyCredential"
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def instance_check_template(self) -> str:
|
|
212
|
+
return "isinstance({}, AzureKeyCredential)"
|
|
213
|
+
|
|
214
|
+
def imports( # pylint: disable=no-self-use
|
|
215
|
+
self, **kwargs: Any # pylint: disable=unused-argument
|
|
216
|
+
) -> FileImport:
|
|
217
|
+
file_import = FileImport()
|
|
218
|
+
file_import.add_submodule_import(
|
|
219
|
+
"azure.core.credentials",
|
|
220
|
+
"AzureKeyCredential",
|
|
221
|
+
ImportType.AZURECORE,
|
|
222
|
+
typing_section=TypingSection.CONDITIONAL,
|
|
223
|
+
)
|
|
224
|
+
return file_import
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Any, Dict, Optional, TYPE_CHECKING, List
|
|
7
|
+
from .base_type import BaseType
|
|
8
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from .code_model import CodeModel
|
|
12
|
+
from .model_type import ModelType
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DictionaryType(BaseType):
|
|
16
|
+
"""Schema for dictionaries that will be serialized.
|
|
17
|
+
|
|
18
|
+
:param yaml_data: the yaml data for this schema
|
|
19
|
+
:type yaml_data: dict[str, Any]
|
|
20
|
+
:param element_type: The type of the value for the dictionary
|
|
21
|
+
:type element_type: ~autorest.models.BaseType
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
yaml_data: Dict[str, Any],
|
|
27
|
+
code_model: "CodeModel",
|
|
28
|
+
element_type: BaseType,
|
|
29
|
+
) -> None:
|
|
30
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
31
|
+
self.element_type = element_type
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def serialization_type(self) -> str:
|
|
35
|
+
"""Returns the serialization value for msrest.
|
|
36
|
+
|
|
37
|
+
:return: The serialization value for msrest
|
|
38
|
+
:rtype: str
|
|
39
|
+
"""
|
|
40
|
+
return f"{{{self.element_type.serialization_type}}}"
|
|
41
|
+
|
|
42
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
43
|
+
"""The python type used for type annotation
|
|
44
|
+
|
|
45
|
+
:return: The type annotation for this schema
|
|
46
|
+
:rtype: str
|
|
47
|
+
"""
|
|
48
|
+
return f"Dict[str, {self.element_type.type_annotation(**kwargs)}]"
|
|
49
|
+
|
|
50
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
51
|
+
return "" if is_operation_file else self.yaml_data.get("description", "")
|
|
52
|
+
|
|
53
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
54
|
+
return f"dict mapping str to {self.element_type.docstring_text(**kwargs)}"
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def xml_serialization_ctxt(self) -> Optional[str]:
|
|
58
|
+
"""No serialization ctxt for dictionaries"""
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
62
|
+
"""The python type used for RST syntax input and type annotation.
|
|
63
|
+
|
|
64
|
+
:param str namespace: Optional. The namespace for the models.
|
|
65
|
+
"""
|
|
66
|
+
return f"dict[str, {self.element_type.docstring_type(**kwargs)}]"
|
|
67
|
+
|
|
68
|
+
def get_json_template_representation(
|
|
69
|
+
self,
|
|
70
|
+
*,
|
|
71
|
+
optional: bool = True,
|
|
72
|
+
client_default_value_declaration: Optional[str] = None,
|
|
73
|
+
description: Optional[str] = None,
|
|
74
|
+
) -> Any:
|
|
75
|
+
return {
|
|
76
|
+
f'"str"': self.element_type.get_json_template_representation(
|
|
77
|
+
optional=optional,
|
|
78
|
+
client_default_value_declaration=client_default_value_declaration,
|
|
79
|
+
description=description,
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
84
|
+
from .model_type import ModelType
|
|
85
|
+
|
|
86
|
+
if isinstance(self.element_type, ModelType):
|
|
87
|
+
is_polymorphic_subtype = (
|
|
88
|
+
self.element_type.discriminator_value
|
|
89
|
+
and not self.element_type.discriminated_subtypes
|
|
90
|
+
)
|
|
91
|
+
if (
|
|
92
|
+
self.element_type.name not in (m.name for m in polymorphic_subtypes)
|
|
93
|
+
and is_polymorphic_subtype
|
|
94
|
+
):
|
|
95
|
+
polymorphic_subtypes.append(self.element_type)
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def from_yaml(
|
|
99
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
100
|
+
) -> "DictionaryType":
|
|
101
|
+
"""Constructs a DictionaryType from yaml data.
|
|
102
|
+
|
|
103
|
+
:param yaml_data: the yaml data from which we will construct this schema
|
|
104
|
+
:type yaml_data: dict[str, Any]
|
|
105
|
+
|
|
106
|
+
:return: A created DictionaryType
|
|
107
|
+
:rtype: ~autorest.models.DictionaryType
|
|
108
|
+
"""
|
|
109
|
+
element_schema: Dict[str, Any] = yaml_data["elementType"]
|
|
110
|
+
|
|
111
|
+
from . import build_type # pylint: disable=import-outside-toplevel
|
|
112
|
+
|
|
113
|
+
element_type = build_type(yaml_data=element_schema, code_model=code_model)
|
|
114
|
+
|
|
115
|
+
return cls(
|
|
116
|
+
yaml_data=yaml_data,
|
|
117
|
+
code_model=code_model,
|
|
118
|
+
element_type=element_type,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
122
|
+
file_import = FileImport()
|
|
123
|
+
file_import.add_submodule_import(
|
|
124
|
+
"typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
125
|
+
)
|
|
126
|
+
file_import.merge(self.element_type.imports(**kwargs))
|
|
127
|
+
return file_import
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def instance_check_template(self) -> str:
|
|
131
|
+
return "isinstance({}, dict)"
|