@autorest/python 5.13.0 → 5.16.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 +67 -0
- package/autorest/__init__.py +1 -2
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +239 -105
- package/autorest/codegen/models/__init__.py +29 -18
- package/autorest/codegen/models/base_builder.py +48 -11
- package/autorest/codegen/models/base_model.py +6 -4
- package/autorest/codegen/models/base_schema.py +21 -24
- package/autorest/codegen/models/client.py +70 -20
- package/autorest/codegen/models/code_model.py +144 -129
- package/autorest/codegen/models/constant_schema.py +32 -16
- package/autorest/codegen/models/credential_model.py +55 -0
- package/autorest/codegen/models/credential_schema.py +21 -16
- package/autorest/codegen/models/credential_schema_policy.py +11 -15
- package/autorest/codegen/models/dictionary_schema.py +27 -24
- package/autorest/codegen/models/enum_schema.py +41 -62
- package/autorest/codegen/models/imports.py +72 -41
- package/autorest/codegen/models/list_schema.py +40 -18
- package/autorest/codegen/models/lro_operation.py +61 -25
- package/autorest/codegen/models/lro_paging_operation.py +5 -6
- package/autorest/codegen/models/object_schema.py +113 -59
- package/autorest/codegen/models/operation.py +251 -111
- package/autorest/codegen/models/operation_group.py +67 -32
- package/autorest/codegen/models/paging_operation.py +48 -21
- package/autorest/codegen/models/parameter.py +182 -90
- package/autorest/codegen/models/parameter_list.py +184 -163
- package/autorest/codegen/models/primitive_schemas.py +89 -70
- package/autorest/codegen/models/property.py +49 -31
- package/autorest/codegen/models/request_builder.py +67 -32
- package/autorest/codegen/models/request_builder_parameter.py +54 -23
- package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
- package/autorest/codegen/models/schema_request.py +16 -6
- package/autorest/codegen/models/schema_response.py +35 -17
- package/autorest/codegen/models/utils.py +24 -1
- package/autorest/codegen/serializers/__init__.py +273 -89
- package/autorest/codegen/serializers/builder_serializer.py +711 -333
- package/autorest/codegen/serializers/client_serializer.py +114 -43
- package/autorest/codegen/serializers/general_serializer.py +84 -25
- package/autorest/codegen/serializers/import_serializer.py +93 -31
- package/autorest/codegen/serializers/metadata_serializer.py +73 -24
- package/autorest/codegen/serializers/model_base_serializer.py +42 -14
- package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
- package/autorest/codegen/serializers/model_init_serializer.py +5 -1
- package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
- package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/patch_serializer.py +14 -2
- package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
- package/autorest/codegen/serializers/utils.py +60 -21
- package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
- package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
- package/autorest/codegen/templates/README.md.jinja2 +105 -0
- package/autorest/codegen/templates/config.py.jinja2 +4 -4
- package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
- package/autorest/codegen/templates/enum.py.jinja2 +1 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
- package/autorest/codegen/templates/init.py.jinja2 +9 -6
- package/autorest/codegen/templates/keywords.jinja2 +14 -1
- package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
- package/autorest/codegen/templates/model.py.jinja2 +1 -6
- package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
- package/autorest/codegen/templates/operation.py.jinja2 +8 -11
- package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/patch.py.jinja2 +18 -29
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
- package/autorest/codegen/templates/setup.py.jinja2 +79 -20
- package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +13 -6
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- 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 +35 -18
- 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 +18 -23
- package/autorest/multiapi/serializers/import_serializer.py +47 -15
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/namer/__init__.py +2 -4
- package/autorest/namer/name_converter.py +200 -103
- package/autorest/namer/python_mappings.py +10 -22
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/rest.py +0 -42
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from itertools import chain
|
|
7
6
|
import logging
|
|
8
|
-
from typing import cast, List, Dict, Optional, Any, Set
|
|
7
|
+
from typing import cast, List, Dict, Optional, Any, Set
|
|
9
8
|
|
|
10
9
|
from .base_schema import BaseSchema
|
|
11
|
-
from .credential_schema_policy import (
|
|
12
|
-
ARMChallengeAuthenticationPolicy, BearerTokenCredentialPolicy, CredentialSchemaPolicy
|
|
13
|
-
)
|
|
14
10
|
from .enum_schema import EnumSchema
|
|
15
11
|
from .object_schema import ObjectSchema
|
|
16
12
|
from .operation_group import OperationGroup
|
|
@@ -20,15 +16,13 @@ from .paging_operation import PagingOperation
|
|
|
20
16
|
from .parameter import Parameter
|
|
21
17
|
from .client import Client
|
|
22
18
|
from .parameter_list import GlobalParameterList
|
|
23
|
-
from .schema_response import SchemaResponse
|
|
24
19
|
from .property import Property
|
|
25
|
-
from .primitive_schemas import IOSchema
|
|
26
20
|
from .request_builder import RequestBuilder
|
|
27
|
-
from .
|
|
28
|
-
|
|
21
|
+
from .credential_model import CredentialModel
|
|
29
22
|
|
|
30
23
|
_LOGGER = logging.getLogger(__name__)
|
|
31
24
|
|
|
25
|
+
|
|
32
26
|
class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-public-methods
|
|
33
27
|
"""Holds all of the information we have parsed out of the yaml file. The CodeModel is what gets
|
|
34
28
|
serialized by the serializers.
|
|
@@ -51,14 +45,24 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
51
45
|
:type primitives: Dict[int, ~autorest.models.BaseSchema]
|
|
52
46
|
:param operation_groups: The operation groups we are going to serialize
|
|
53
47
|
:type operation_groups: list[~autorest.models.OperationGroup]
|
|
48
|
+
:param package_dependency: All the dependencies needed in setup.py
|
|
49
|
+
:type package_dependency: Dict[str, str]
|
|
50
|
+
:param credential_model: The class contains all the credential info
|
|
51
|
+
:type credential_model: CredentialMode
|
|
54
52
|
"""
|
|
55
53
|
|
|
56
54
|
def __init__(
|
|
57
55
|
self,
|
|
56
|
+
yaml_data: Dict[str, Any],
|
|
58
57
|
options: Dict[str, Any],
|
|
59
58
|
) -> None:
|
|
60
|
-
self.
|
|
61
|
-
self.
|
|
59
|
+
self.yaml_data = yaml_data
|
|
60
|
+
self.send_request_name = (
|
|
61
|
+
"send_request" if options["show_send_request"] else "_send_request"
|
|
62
|
+
)
|
|
63
|
+
self.rest_layer_name = (
|
|
64
|
+
"rest" if options["builders_visibility"] == "public" else "_rest"
|
|
65
|
+
)
|
|
62
66
|
self.options = options
|
|
63
67
|
self.module_name: str = ""
|
|
64
68
|
self.class_name: str = ""
|
|
@@ -73,9 +77,9 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
73
77
|
params = GlobalParameterList(self)
|
|
74
78
|
params.code_model = self
|
|
75
79
|
self.service_client: Client = Client(self, params)
|
|
76
|
-
self.
|
|
77
|
-
self.
|
|
78
|
-
self.
|
|
80
|
+
self.request_builders: List[RequestBuilder] = []
|
|
81
|
+
self.package_dependency: Dict[str, str] = {}
|
|
82
|
+
self._credential_model: Optional[CredentialModel] = None
|
|
79
83
|
|
|
80
84
|
@property
|
|
81
85
|
def global_parameters(self) -> GlobalParameterList:
|
|
@@ -85,16 +89,6 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
85
89
|
def global_parameters(self, val: GlobalParameterList) -> None:
|
|
86
90
|
self.service_client.parameters = val
|
|
87
91
|
|
|
88
|
-
@property
|
|
89
|
-
def rest(self) -> Rest:
|
|
90
|
-
if not self._rest:
|
|
91
|
-
raise ValueError("rest is None. Can not call it, you first have to set it.")
|
|
92
|
-
return self._rest
|
|
93
|
-
|
|
94
|
-
@rest.setter
|
|
95
|
-
def rest(self, p: Rest) -> None:
|
|
96
|
-
self._rest = p
|
|
97
|
-
|
|
98
92
|
def lookup_schema(self, schema_id: int) -> BaseSchema:
|
|
99
93
|
"""Looks to see if the schema has already been created.
|
|
100
94
|
|
|
@@ -109,6 +103,30 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
109
103
|
return elt_value
|
|
110
104
|
raise KeyError("Didn't find it!!!!!")
|
|
111
105
|
|
|
106
|
+
def lookup_request_builder(self, request_builder_id: int) -> RequestBuilder:
|
|
107
|
+
"""Find the request builder based off of id"""
|
|
108
|
+
try:
|
|
109
|
+
return next(
|
|
110
|
+
rb
|
|
111
|
+
for rb in self.request_builders
|
|
112
|
+
if id(rb.yaml_data) == request_builder_id
|
|
113
|
+
)
|
|
114
|
+
except StopIteration:
|
|
115
|
+
raise KeyError(f"No request builder with id {request_builder_id} found.")
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def exception_ids(self) -> Set[int]:
|
|
119
|
+
exceptions_set = set()
|
|
120
|
+
for group in self.yaml_data["operationGroups"]:
|
|
121
|
+
for operation in group["operations"]:
|
|
122
|
+
if not operation.get("exceptions"):
|
|
123
|
+
continue
|
|
124
|
+
for exception in operation["exceptions"]:
|
|
125
|
+
if not exception.get("schema"):
|
|
126
|
+
continue
|
|
127
|
+
exceptions_set.add(id(exception["schema"]))
|
|
128
|
+
return exceptions_set
|
|
129
|
+
|
|
112
130
|
@staticmethod
|
|
113
131
|
def _sort_schemas_helper(current, seen_schema_names, seen_schema_yaml_ids):
|
|
114
132
|
if current.id in seen_schema_yaml_ids:
|
|
@@ -125,12 +143,16 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
125
143
|
continue
|
|
126
144
|
seen_schema_names.add(current.name)
|
|
127
145
|
seen_schema_yaml_ids.add(current.id)
|
|
128
|
-
ancestors =
|
|
146
|
+
ancestors = (
|
|
147
|
+
CodeModel._sort_schemas_helper(
|
|
148
|
+
parent, seen_schema_names, seen_schema_yaml_ids
|
|
149
|
+
)
|
|
150
|
+
+ ancestors
|
|
151
|
+
)
|
|
129
152
|
seen_schema_names.add(current.name)
|
|
130
153
|
seen_schema_yaml_ids.add(current.id)
|
|
131
154
|
return ancestors
|
|
132
155
|
|
|
133
|
-
|
|
134
156
|
def sort_schemas(self) -> None:
|
|
135
157
|
"""Sorts the final object schemas by inheritance and by alphabetical order.
|
|
136
158
|
|
|
@@ -141,12 +163,17 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
141
163
|
seen_schema_yaml_ids: Set[int] = set()
|
|
142
164
|
sorted_schemas: List[ObjectSchema] = []
|
|
143
165
|
for schema in sorted(self.schemas.values(), key=lambda x: x.name.lower()):
|
|
144
|
-
sorted_schemas.extend(
|
|
166
|
+
sorted_schemas.extend(
|
|
167
|
+
CodeModel._sort_schemas_helper(
|
|
168
|
+
schema, seen_schema_names, seen_schema_yaml_ids
|
|
169
|
+
)
|
|
170
|
+
)
|
|
145
171
|
self.sorted_schemas = sorted_schemas
|
|
146
172
|
|
|
147
173
|
def setup_client_input_parameters(self, yaml_data: Dict[str, Any]):
|
|
148
174
|
dollar_host = [
|
|
149
|
-
parameter
|
|
175
|
+
parameter
|
|
176
|
+
for parameter in self.global_parameters
|
|
150
177
|
if parameter.rest_api_name == "$host"
|
|
151
178
|
]
|
|
152
179
|
if not dollar_host:
|
|
@@ -154,14 +181,18 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
154
181
|
# So far now, let's get the first one in the first operation
|
|
155
182
|
# UGLY as hell.....
|
|
156
183
|
if yaml_data.get("operationGroups"):
|
|
157
|
-
first_req_of_first_op_of_first_grp = yaml_data["operationGroups"][0][
|
|
184
|
+
first_req_of_first_op_of_first_grp = yaml_data["operationGroups"][0][
|
|
185
|
+
"operations"
|
|
186
|
+
][0]["requests"][0]
|
|
158
187
|
self.service_client.parameterized_host_template = (
|
|
159
188
|
first_req_of_first_op_of_first_grp["protocol"]["http"]["uri"]
|
|
160
189
|
)
|
|
161
190
|
else:
|
|
162
191
|
for host in dollar_host:
|
|
163
192
|
self.global_parameters.remove(host)
|
|
164
|
-
self.service_client.parameters.add_host(
|
|
193
|
+
self.service_client.parameters.add_host(
|
|
194
|
+
dollar_host[0].yaml_data["clientDefaultValue"]
|
|
195
|
+
)
|
|
165
196
|
|
|
166
197
|
def format_lro_operations(self) -> None:
|
|
167
198
|
"""Adds operations and attributes needed for LROs.
|
|
@@ -178,8 +209,8 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
178
209
|
i += 1
|
|
179
210
|
|
|
180
211
|
def remove_next_operation(self) -> None:
|
|
181
|
-
"""Linking paging operations together.
|
|
182
|
-
|
|
212
|
+
"""Linking paging operations together."""
|
|
213
|
+
|
|
183
214
|
def _lookup_operation(yaml_id: int) -> Operation:
|
|
184
215
|
for operation_group in self.operation_groups:
|
|
185
216
|
for operation in operation_group.operations:
|
|
@@ -192,15 +223,21 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
192
223
|
for operation in operation_group.operations:
|
|
193
224
|
# when we add in "LRO" functions we don't include yaml_data, so yaml_data can be empty in these cases
|
|
194
225
|
next_link_yaml = None
|
|
195
|
-
if operation.yaml_data and operation.yaml_data[
|
|
196
|
-
|
|
226
|
+
if operation.yaml_data and operation.yaml_data["language"][
|
|
227
|
+
"python"
|
|
228
|
+
].get("paging"):
|
|
229
|
+
next_link_yaml = operation.yaml_data["language"]["python"][
|
|
230
|
+
"paging"
|
|
231
|
+
].get("nextLinkOperation")
|
|
197
232
|
if isinstance(operation, PagingOperation) and next_link_yaml:
|
|
198
233
|
next_operation = _lookup_operation(id(next_link_yaml))
|
|
199
234
|
operation.next_operation = next_operation
|
|
200
235
|
next_operations.append(next_operation)
|
|
201
236
|
|
|
202
237
|
operation_group.operations = [
|
|
203
|
-
operation
|
|
238
|
+
operation
|
|
239
|
+
for operation in operation_group.operations
|
|
240
|
+
if operation not in next_operations
|
|
204
241
|
]
|
|
205
242
|
|
|
206
243
|
@property
|
|
@@ -208,18 +245,16 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
208
245
|
return self.schemas or self.enums
|
|
209
246
|
|
|
210
247
|
@property
|
|
211
|
-
def
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
raise ValueError("You want to find the Credential Schema Policy, but have not given a value")
|
|
218
|
-
return self._credential_schema_policy
|
|
248
|
+
def credential_model(self) -> CredentialModel:
|
|
249
|
+
if not self._credential_model:
|
|
250
|
+
raise ValueError(
|
|
251
|
+
"You want to find the Credential Model, but have not given a value"
|
|
252
|
+
)
|
|
253
|
+
return self._credential_model
|
|
219
254
|
|
|
220
|
-
@
|
|
221
|
-
def
|
|
222
|
-
self.
|
|
255
|
+
@credential_model.setter
|
|
256
|
+
def credential_model(self, val: CredentialModel) -> None:
|
|
257
|
+
self._credential_model = val
|
|
223
258
|
|
|
224
259
|
@staticmethod
|
|
225
260
|
def _add_properties_from_inheritance_helper(schema, properties) -> List[Property]:
|
|
@@ -230,14 +265,17 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
230
265
|
parent = cast(ObjectSchema, base_model)
|
|
231
266
|
# need to make sure that the properties we choose from our parent also don't contain
|
|
232
267
|
# any of our own properties
|
|
233
|
-
schema_property_names = set(
|
|
268
|
+
schema_property_names = set(
|
|
269
|
+
[p.name for p in properties] + [p.name for p in schema.properties]
|
|
270
|
+
)
|
|
234
271
|
chosen_parent_properties = [
|
|
235
|
-
p for p in parent.properties
|
|
236
|
-
if p.name not in schema_property_names
|
|
272
|
+
p for p in parent.properties if p.name not in schema_property_names
|
|
237
273
|
]
|
|
238
274
|
properties = (
|
|
239
|
-
CodeModel._add_properties_from_inheritance_helper(
|
|
240
|
-
|
|
275
|
+
CodeModel._add_properties_from_inheritance_helper(
|
|
276
|
+
parent, chosen_parent_properties
|
|
277
|
+
)
|
|
278
|
+
+ properties
|
|
241
279
|
)
|
|
242
280
|
|
|
243
281
|
return properties
|
|
@@ -258,7 +296,9 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
258
296
|
:rtype: None
|
|
259
297
|
"""
|
|
260
298
|
for schema in self.schemas.values():
|
|
261
|
-
schema.properties = CodeModel._add_properties_from_inheritance_helper(
|
|
299
|
+
schema.properties = CodeModel._add_properties_from_inheritance_helper(
|
|
300
|
+
schema, schema.properties
|
|
301
|
+
)
|
|
262
302
|
|
|
263
303
|
@staticmethod
|
|
264
304
|
def _add_exceptions_from_inheritance_helper(schema) -> bool:
|
|
@@ -267,7 +307,9 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
267
307
|
parent_is_exception: List[bool] = []
|
|
268
308
|
for base_model in schema.base_models:
|
|
269
309
|
parent = cast(ObjectSchema, base_model)
|
|
270
|
-
parent_is_exception.append(
|
|
310
|
+
parent_is_exception.append(
|
|
311
|
+
CodeModel._add_exceptions_from_inheritance_helper(parent)
|
|
312
|
+
)
|
|
271
313
|
return any(parent_is_exception)
|
|
272
314
|
|
|
273
315
|
def _add_exceptions_from_inheritance(self) -> None:
|
|
@@ -277,7 +319,9 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
277
319
|
:rtype: None
|
|
278
320
|
"""
|
|
279
321
|
for schema in self.schemas.values():
|
|
280
|
-
schema.is_exception = CodeModel._add_exceptions_from_inheritance_helper(
|
|
322
|
+
schema.is_exception = CodeModel._add_exceptions_from_inheritance_helper(
|
|
323
|
+
schema
|
|
324
|
+
)
|
|
281
325
|
|
|
282
326
|
def add_inheritance_to_models(self) -> None:
|
|
283
327
|
"""Adds base classes and properties from base classes to schemas with parents.
|
|
@@ -288,7 +332,9 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
288
332
|
for schema in self.schemas.values():
|
|
289
333
|
if schema.base_models:
|
|
290
334
|
# right now, the base model property just holds the name of the parent class
|
|
291
|
-
schema.base_models = [
|
|
335
|
+
schema.base_models = [
|
|
336
|
+
b for b in self.schemas.values() if b.id in schema.base_models
|
|
337
|
+
]
|
|
292
338
|
self._add_properties_from_inheritance()
|
|
293
339
|
self._add_exceptions_from_inheritance()
|
|
294
340
|
|
|
@@ -300,100 +346,69 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
300
346
|
return
|
|
301
347
|
raise KeyError("Didn't find the target property")
|
|
302
348
|
|
|
303
|
-
def _populate_schema(self, obj: Any) -> None:
|
|
304
|
-
schema_obj = obj.schema
|
|
305
|
-
if schema_obj and not isinstance(schema_obj, dict):
|
|
306
|
-
return
|
|
307
|
-
|
|
308
|
-
if schema_obj:
|
|
309
|
-
schema_obj_id = id(obj.schema)
|
|
310
|
-
_LOGGER.debug("Looking for id %s for member %s", schema_obj_id, obj)
|
|
311
|
-
try:
|
|
312
|
-
obj.schema = self.lookup_schema(schema_obj_id)
|
|
313
|
-
except KeyError:
|
|
314
|
-
_LOGGER.critical("Unable to ref the object")
|
|
315
|
-
raise
|
|
316
|
-
if isinstance(obj, Parameter) and obj.target_property_name:
|
|
317
|
-
self._populate_target_property(obj)
|
|
318
|
-
if isinstance(obj, SchemaResponse) and obj.is_stream_response:
|
|
319
|
-
obj.schema = IOSchema(namespace=None, yaml_data={})
|
|
320
|
-
|
|
321
|
-
def add_schema_link_to_operation(self) -> None:
|
|
322
|
-
"""Puts created schemas into operation classes `schema` property
|
|
323
|
-
|
|
324
|
-
:return: None
|
|
325
|
-
:rtype: None
|
|
326
|
-
"""
|
|
327
|
-
# Index schemas
|
|
328
|
-
for operation_group in self.operation_groups:
|
|
329
|
-
for operation in operation_group.operations:
|
|
330
|
-
for obj in chain(
|
|
331
|
-
operation.parameters,
|
|
332
|
-
operation.multiple_content_type_parameters or [],
|
|
333
|
-
operation.responses,
|
|
334
|
-
operation.exceptions,
|
|
335
|
-
chain.from_iterable(response.headers for response in operation.responses),
|
|
336
|
-
):
|
|
337
|
-
self._populate_schema(obj)
|
|
338
|
-
|
|
339
|
-
def add_schema_link_to_request_builder(self) -> None:
|
|
340
|
-
for request_builder in self.rest.request_builders:
|
|
341
|
-
for obj in chain(
|
|
342
|
-
request_builder.parameters,
|
|
343
|
-
chain.from_iterable(request.parameters for request in request_builder.schema_requests),
|
|
344
|
-
request_builder.responses,
|
|
345
|
-
):
|
|
346
|
-
self._populate_schema(obj)
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
def add_schema_link_to_global_parameters(self) -> None:
|
|
350
|
-
for parameter in self.global_parameters:
|
|
351
|
-
self._populate_schema(parameter)
|
|
352
|
-
|
|
353
349
|
def generate_single_parameter_from_multiple_content_types_operation(self) -> None:
|
|
354
350
|
for operation_group in self.operation_groups:
|
|
355
351
|
for operation in operation_group.operations:
|
|
356
352
|
if operation.multiple_content_type_parameters:
|
|
357
353
|
operation.convert_multiple_content_type_parameters()
|
|
358
354
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
def need_vendored_code(self, async_mode: bool) -> bool:
|
|
356
|
+
if async_mode:
|
|
357
|
+
return self.need_mixin_abc
|
|
358
|
+
return (
|
|
359
|
+
self.need_request_converter or self.need_format_url or self.need_mixin_abc
|
|
360
|
+
)
|
|
362
361
|
|
|
363
362
|
@property
|
|
364
363
|
def need_request_converter(self) -> bool:
|
|
365
|
-
return
|
|
364
|
+
return (
|
|
365
|
+
self.options["show_operations"]
|
|
366
|
+
and bool(self.request_builders)
|
|
367
|
+
and not self.options["version_tolerant"]
|
|
368
|
+
)
|
|
366
369
|
|
|
367
370
|
@property
|
|
368
371
|
def need_format_url(self) -> bool:
|
|
369
|
-
return any(rq for rq in self.
|
|
372
|
+
return any(rq for rq in self.request_builders if rq.parameters.path)
|
|
370
373
|
|
|
371
374
|
@property
|
|
372
|
-
def
|
|
373
|
-
return any(
|
|
374
|
-
|
|
375
|
-
for
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
def _lookup_request_builder(self, schema_id: int) -> RequestBuilder:
|
|
380
|
-
"""Looks to see if the schema has already been created.
|
|
375
|
+
def need_mixin_abc(self) -> bool:
|
|
376
|
+
return any(
|
|
377
|
+
o
|
|
378
|
+
for o in self.operation_groups
|
|
379
|
+
if o.is_empty_operation_group and self.options["python3_only"]
|
|
380
|
+
)
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
382
|
+
@property
|
|
383
|
+
def has_lro_operations(self) -> bool:
|
|
384
|
+
return any(
|
|
385
|
+
[
|
|
386
|
+
isinstance(operation, LROOperation)
|
|
387
|
+
for operation_group in self.operation_groups
|
|
388
|
+
for operation in operation_group.operations
|
|
389
|
+
]
|
|
390
|
+
)
|
|
391
391
|
|
|
392
392
|
def link_operation_to_request_builder(self) -> None:
|
|
393
393
|
for operation_group in self.operation_groups:
|
|
394
394
|
for operation in operation_group.operations:
|
|
395
|
-
request_builder =
|
|
395
|
+
request_builder = operation.request_builder
|
|
396
396
|
if isinstance(operation, LROOperation):
|
|
397
397
|
request_builder.name = request_builder.name + "_initial"
|
|
398
398
|
operation.request_builder = request_builder
|
|
399
399
|
operation.link_body_kwargs_to_body_params()
|
|
400
|
+
|
|
401
|
+
def get_models_filename(self, is_python3_file: bool) -> str:
|
|
402
|
+
if (
|
|
403
|
+
self.options["version_tolerant"] or self.options["low_level_client"]
|
|
404
|
+
) and self.options["python3_only"]:
|
|
405
|
+
return "_models"
|
|
406
|
+
if is_python3_file:
|
|
407
|
+
return "_models_py3"
|
|
408
|
+
return "_models"
|
|
409
|
+
|
|
410
|
+
@property
|
|
411
|
+
def enums_filename(self) -> str:
|
|
412
|
+
if self.options["version_tolerant"] or self.options["low_level_client"]:
|
|
413
|
+
return "_enums"
|
|
414
|
+
return f"_{self.module_name}_enums"
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Dict, Any, Optional
|
|
7
|
+
from typing import Dict, Any, Optional, TYPE_CHECKING
|
|
8
8
|
from .base_schema import BaseSchema
|
|
9
9
|
from .primitive_schemas import get_primitive_schema, PrimitiveSchema
|
|
10
10
|
from .imports import FileImport
|
|
11
11
|
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .code_model import CodeModel
|
|
14
|
+
|
|
12
15
|
_LOGGER = logging.getLogger(__name__)
|
|
13
16
|
|
|
14
17
|
|
|
@@ -23,9 +26,13 @@ class ConstantSchema(BaseSchema):
|
|
|
23
26
|
"""
|
|
24
27
|
|
|
25
28
|
def __init__(
|
|
26
|
-
self,
|
|
29
|
+
self,
|
|
30
|
+
yaml_data: Dict[str, Any],
|
|
31
|
+
code_model: "CodeModel",
|
|
32
|
+
schema: PrimitiveSchema,
|
|
33
|
+
value: Optional[str],
|
|
27
34
|
) -> None:
|
|
28
|
-
super(
|
|
35
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
29
36
|
self.value = value
|
|
30
37
|
self.schema = schema
|
|
31
38
|
|
|
@@ -33,7 +40,8 @@ class ConstantSchema(BaseSchema):
|
|
|
33
40
|
if value != self.value:
|
|
34
41
|
_LOGGER.warning(
|
|
35
42
|
"Passed in value of %s differs from constant value of %s. Choosing constant value",
|
|
36
|
-
str(value),
|
|
43
|
+
str(value),
|
|
44
|
+
str(self.value),
|
|
37
45
|
)
|
|
38
46
|
if self.value is None:
|
|
39
47
|
return "None"
|
|
@@ -60,12 +68,13 @@ class ConstantSchema(BaseSchema):
|
|
|
60
68
|
"""
|
|
61
69
|
return self.schema.docstring_type
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return self.schema.type_annotation
|
|
71
|
+
def type_annotation(self, *, is_operation_file: bool = False) -> str:
|
|
72
|
+
return self.schema.type_annotation(is_operation_file=is_operation_file)
|
|
66
73
|
|
|
67
74
|
@classmethod
|
|
68
|
-
def from_yaml(
|
|
75
|
+
def from_yaml(
|
|
76
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
77
|
+
) -> "ConstantSchema":
|
|
69
78
|
"""Constructs a ConstantSchema from yaml data.
|
|
70
79
|
|
|
71
80
|
:param yaml_data: the yaml data from which we will construct this schema
|
|
@@ -74,24 +83,31 @@ class ConstantSchema(BaseSchema):
|
|
|
74
83
|
:return: A created ConstantSchema
|
|
75
84
|
:rtype: ~autorest.models.ConstantSchema
|
|
76
85
|
"""
|
|
77
|
-
name =
|
|
86
|
+
name = (
|
|
87
|
+
yaml_data["language"]["python"]["name"]
|
|
88
|
+
if yaml_data["language"]["python"].get("name")
|
|
89
|
+
else ""
|
|
90
|
+
)
|
|
78
91
|
_LOGGER.debug("Parsing %s constant", name)
|
|
79
92
|
return cls(
|
|
80
|
-
namespace=namespace,
|
|
81
93
|
yaml_data=yaml_data,
|
|
82
|
-
|
|
94
|
+
code_model=code_model,
|
|
95
|
+
schema=get_primitive_schema(
|
|
96
|
+
yaml_data=yaml_data["valueType"], code_model=code_model
|
|
97
|
+
),
|
|
83
98
|
value=yaml_data.get("value", {}).get("value", None),
|
|
84
99
|
)
|
|
85
100
|
|
|
86
101
|
def get_json_template_representation(self, **kwargs: Any) -> Any:
|
|
87
|
-
kwargs[
|
|
102
|
+
kwargs["default_value_declaration"] = self.schema.get_declaration(self.value)
|
|
88
103
|
return self.schema.get_json_template_representation(**kwargs)
|
|
89
104
|
|
|
90
|
-
def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
|
|
91
|
-
kwargs['default_value_declaration'] = self.schema.get_declaration(self.value)
|
|
92
|
-
return self.schema.get_files_and_data_template_representation(**kwargs)
|
|
93
|
-
|
|
94
105
|
def imports(self) -> FileImport:
|
|
95
106
|
file_import = FileImport()
|
|
96
107
|
file_import.merge(self.schema.imports())
|
|
97
108
|
return file_import
|
|
109
|
+
|
|
110
|
+
def model_file_imports(self) -> FileImport:
|
|
111
|
+
file_import = self.imports()
|
|
112
|
+
file_import.merge(self.schema.model_file_imports())
|
|
113
|
+
return file_import
|
|
@@ -0,0 +1,55 @@
|
|
|
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 Set, Optional, Type
|
|
7
|
+
from .credential_schema_policy import (
|
|
8
|
+
CredentialSchemaPolicy,
|
|
9
|
+
BearerTokenCredentialPolicy,
|
|
10
|
+
)
|
|
11
|
+
from .credential_schema_policy import ARMChallengeAuthenticationPolicy
|
|
12
|
+
from .credential_schema import TokenCredentialSchema, AzureKeyCredentialSchema
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CredentialModel:
|
|
16
|
+
"""Store info about credential."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, azure_arm: bool) -> None:
|
|
19
|
+
self.azure_arm: bool = azure_arm
|
|
20
|
+
self.credential_scopes: Set[str] = set()
|
|
21
|
+
self.key_header_name: str = ""
|
|
22
|
+
self.policy_type: Optional[Type[CredentialSchemaPolicy]] = None
|
|
23
|
+
self._credential_schema_policy: Optional[CredentialSchemaPolicy] = None
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def default_authentication_policy(self) -> Type[CredentialSchemaPolicy]:
|
|
27
|
+
return (
|
|
28
|
+
ARMChallengeAuthenticationPolicy
|
|
29
|
+
if self.azure_arm
|
|
30
|
+
else BearerTokenCredentialPolicy
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def credential_schema_policy(self) -> CredentialSchemaPolicy:
|
|
35
|
+
if not self._credential_schema_policy:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
"You want to find the Credential Schema Policy, but have not given a value"
|
|
38
|
+
)
|
|
39
|
+
return self._credential_schema_policy
|
|
40
|
+
|
|
41
|
+
def build_authentication_policy(self):
|
|
42
|
+
if hasattr(self.policy_type, "credential_scopes"):
|
|
43
|
+
self._credential_schema_policy = (
|
|
44
|
+
self.policy_type( # pylint: disable=not-callable
|
|
45
|
+
credential=TokenCredentialSchema(async_mode=False),
|
|
46
|
+
credential_scopes=list(self.credential_scopes),
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
elif hasattr(self.policy_type, "credential_key_header_name"):
|
|
50
|
+
self._credential_schema_policy = (
|
|
51
|
+
self.policy_type( # pylint: disable=not-callable
|
|
52
|
+
credential=AzureKeyCredentialSchema(),
|
|
53
|
+
credential_key_header_name=self.key_header_name,
|
|
54
|
+
)
|
|
55
|
+
)
|