@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
|
@@ -4,25 +4,27 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from collections.abc import MutableSequence
|
|
7
|
-
from copy import copy
|
|
8
7
|
import logging
|
|
9
8
|
from typing import cast, List, Callable, Optional, TypeVar, Dict, TYPE_CHECKING
|
|
10
9
|
|
|
11
|
-
from .parameter import Parameter, ParameterLocation
|
|
10
|
+
from .parameter import Parameter, ParameterLocation, ParameterMethodLocation
|
|
12
11
|
from .base_schema import BaseSchema
|
|
13
|
-
from .
|
|
14
|
-
from .primitive_schemas import AnySchema, StringSchema
|
|
12
|
+
from .primitive_schemas import StringSchema
|
|
15
13
|
from .utils import JSON_REGEXP
|
|
16
14
|
|
|
17
15
|
if TYPE_CHECKING:
|
|
18
16
|
from .schema_request import SchemaRequest
|
|
17
|
+
from .code_model import CodeModel
|
|
19
18
|
|
|
20
|
-
T = TypeVar(
|
|
19
|
+
T = TypeVar("T")
|
|
21
20
|
OrderedSet = Dict[T, None]
|
|
22
21
|
|
|
23
22
|
_LOGGER = logging.getLogger(__name__)
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
|
|
25
|
+
def _method_signature_helper(
|
|
26
|
+
positional: List[str], keyword_only: Optional[List[str]], kwarg_params: List[str]
|
|
27
|
+
):
|
|
26
28
|
keyword_only = keyword_only or []
|
|
27
29
|
return positional + keyword_only + kwarg_params
|
|
28
30
|
|
|
@@ -30,7 +32,7 @@ def _method_signature_helper(positional: List[str], keyword_only: Optional[List[
|
|
|
30
32
|
class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
31
33
|
def __init__(
|
|
32
34
|
self,
|
|
33
|
-
code_model,
|
|
35
|
+
code_model: "CodeModel",
|
|
34
36
|
parameters: Optional[List[Parameter]] = None,
|
|
35
37
|
schema_requests: Optional[List["SchemaRequest"]] = None,
|
|
36
38
|
) -> None:
|
|
@@ -61,9 +63,17 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
61
63
|
# Parameter helpers
|
|
62
64
|
|
|
63
65
|
def has_any_location(self, location: ParameterLocation) -> bool:
|
|
64
|
-
return bool(
|
|
66
|
+
return bool(
|
|
67
|
+
[
|
|
68
|
+
parameter
|
|
69
|
+
for parameter in self.parameters
|
|
70
|
+
if parameter.location == location
|
|
71
|
+
]
|
|
72
|
+
)
|
|
65
73
|
|
|
66
|
-
def get_from_predicate(
|
|
74
|
+
def get_from_predicate(
|
|
75
|
+
self, predicate: Callable[[Parameter], bool]
|
|
76
|
+
) -> List[Parameter]:
|
|
67
77
|
return [parameter for parameter in self.parameters if predicate(parameter)]
|
|
68
78
|
|
|
69
79
|
def get_from_location(self, location: ParameterLocation) -> List[Parameter]:
|
|
@@ -72,9 +82,7 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
72
82
|
@property
|
|
73
83
|
def content_types(self) -> List[str]:
|
|
74
84
|
ordered_set = {
|
|
75
|
-
m: None
|
|
76
|
-
for request in self.schema_requests
|
|
77
|
-
for m in request.content_types
|
|
85
|
+
m: None for request in self.schema_requests for m in request.content_types
|
|
78
86
|
}
|
|
79
87
|
return list(ordered_set.keys())
|
|
80
88
|
|
|
@@ -116,7 +124,10 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
116
124
|
# TODO add 'and parameter.location == "Method"' as requirement to this check once
|
|
117
125
|
# I can use send_request on operations.
|
|
118
126
|
# Don't want to duplicate code from send_request.
|
|
119
|
-
return
|
|
127
|
+
return (
|
|
128
|
+
parameter.location == ParameterLocation.Uri
|
|
129
|
+
and parameter.rest_api_name != "$host"
|
|
130
|
+
)
|
|
120
131
|
|
|
121
132
|
@property
|
|
122
133
|
def implementation(self) -> str:
|
|
@@ -139,23 +150,26 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
139
150
|
headers = self.get_from_location(ParameterLocation.Header)
|
|
140
151
|
if not headers:
|
|
141
152
|
return headers
|
|
142
|
-
return list({
|
|
143
|
-
header.serialized_name: header
|
|
144
|
-
for header in headers
|
|
145
|
-
}.values())
|
|
153
|
+
return list({header.serialized_name: header for header in headers}.values())
|
|
146
154
|
|
|
147
155
|
@property
|
|
148
156
|
def grouped(self) -> List[Parameter]:
|
|
149
|
-
return self.get_from_predicate(
|
|
157
|
+
return self.get_from_predicate(
|
|
158
|
+
lambda parameter: cast(bool, parameter.grouped_by)
|
|
159
|
+
)
|
|
150
160
|
|
|
151
161
|
@property
|
|
152
162
|
def groupers(self) -> List[Parameter]:
|
|
153
163
|
groupers: List[Parameter] = []
|
|
154
164
|
for parameter in self.parameters:
|
|
155
|
-
if any(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
if any(
|
|
166
|
+
[
|
|
167
|
+
p
|
|
168
|
+
for p in self.grouped
|
|
169
|
+
if p.grouped_by
|
|
170
|
+
and id(p.grouped_by.yaml_data) == id(parameter.yaml_data)
|
|
171
|
+
]
|
|
172
|
+
):
|
|
159
173
|
groupers.append(parameter)
|
|
160
174
|
return groupers
|
|
161
175
|
|
|
@@ -167,74 +181,98 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
167
181
|
constant from this set of parameters, they are constants on the models and hence they do
|
|
168
182
|
not have impact on any generation at this level
|
|
169
183
|
"""
|
|
170
|
-
return self.get_from_predicate(
|
|
171
|
-
lambda parameter: parameter.constant
|
|
172
|
-
)
|
|
184
|
+
return self.get_from_predicate(lambda parameter: parameter.constant)
|
|
173
185
|
|
|
174
186
|
@property
|
|
175
187
|
def multipart(self) -> List[Parameter]:
|
|
176
|
-
return self.get_from_predicate(
|
|
177
|
-
lambda parameter: parameter.is_multipart and not parameter.is_body_kwarg
|
|
178
|
-
)
|
|
188
|
+
return self.get_from_predicate(lambda parameter: parameter.is_multipart)
|
|
179
189
|
|
|
180
190
|
@property
|
|
181
191
|
def data_inputs(self) -> List[Parameter]:
|
|
182
|
-
return self.get_from_predicate(
|
|
183
|
-
lambda parameter: parameter.is_data_input and not parameter.is_body_kwarg
|
|
184
|
-
)
|
|
192
|
+
return self.get_from_predicate(lambda parameter: parameter.is_data_input)
|
|
185
193
|
|
|
186
194
|
def _filter_out_multiple_content_type(self, kwarg_params):
|
|
187
195
|
"""We don't want multiple content type kwargs in the method signature"""
|
|
188
|
-
content_type_params = [
|
|
196
|
+
content_type_params = [
|
|
197
|
+
k for k in kwarg_params if k.rest_api_name == "Content-Type"
|
|
198
|
+
]
|
|
189
199
|
if len(content_type_params) > 1:
|
|
190
200
|
# we don't want multiple content type params in the method, just one
|
|
191
201
|
# we'll pick the one with the default content type
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
seen_content_type = False
|
|
203
|
+
new_kwarg_params = []
|
|
204
|
+
for k in kwarg_params:
|
|
205
|
+
if k.rest_api_name == "Content-Type":
|
|
206
|
+
if (
|
|
207
|
+
not seen_content_type
|
|
208
|
+
and k.default_value_declaration
|
|
209
|
+
== f'"{self.default_content_type}"'
|
|
210
|
+
):
|
|
211
|
+
new_kwarg_params.append(k)
|
|
212
|
+
seen_content_type = True
|
|
213
|
+
else:
|
|
214
|
+
continue
|
|
215
|
+
else:
|
|
216
|
+
new_kwarg_params.append(k)
|
|
217
|
+
kwarg_params = new_kwarg_params
|
|
199
218
|
return kwarg_params
|
|
200
219
|
|
|
201
220
|
@property
|
|
202
221
|
def method(self) -> List[Parameter]:
|
|
203
|
-
"""The list of parameter used in method signature.
|
|
204
|
-
"""
|
|
222
|
+
"""The list of parameter used in method signature."""
|
|
205
223
|
# Client level should not be on Method, etc.
|
|
206
224
|
parameters_of_this_implementation = self.get_from_predicate(
|
|
207
225
|
lambda parameter: parameter.implementation == self.implementation
|
|
226
|
+
and parameter.in_method_signature
|
|
208
227
|
)
|
|
209
|
-
positional = [
|
|
228
|
+
positional = [
|
|
229
|
+
p
|
|
230
|
+
for p in parameters_of_this_implementation
|
|
231
|
+
if p.method_location == ParameterMethodLocation.POSITIONAL
|
|
232
|
+
]
|
|
210
233
|
keyword_only = self._filter_out_multiple_content_type(
|
|
211
|
-
[
|
|
234
|
+
[
|
|
235
|
+
p
|
|
236
|
+
for p in parameters_of_this_implementation
|
|
237
|
+
if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
|
|
238
|
+
]
|
|
212
239
|
)
|
|
213
240
|
kwargs = self._filter_out_multiple_content_type(
|
|
214
|
-
[
|
|
241
|
+
[
|
|
242
|
+
p
|
|
243
|
+
for p in parameters_of_this_implementation
|
|
244
|
+
if p.method_location
|
|
245
|
+
in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
|
|
246
|
+
]
|
|
215
247
|
)
|
|
248
|
+
|
|
216
249
|
def _sort(params):
|
|
217
|
-
return sorted(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
)
|
|
221
|
-
return signature_parameters
|
|
250
|
+
return sorted(
|
|
251
|
+
params, key=lambda x: not x.default_value and x.required, reverse=True
|
|
252
|
+
)
|
|
222
253
|
|
|
254
|
+
signature_parameters = _sort(positional) + _sort(keyword_only) + _sort(kwargs)
|
|
255
|
+
return signature_parameters
|
|
223
256
|
|
|
224
257
|
def method_signature(self, is_python3_file: bool) -> List[str]:
|
|
225
258
|
return _method_signature_helper(
|
|
226
259
|
positional=self.method_signature_positional(is_python3_file),
|
|
227
260
|
keyword_only=self.method_signature_keyword_only(is_python3_file),
|
|
228
|
-
kwarg_params=self.method_signature_kwargs(is_python3_file)
|
|
261
|
+
kwarg_params=self.method_signature_kwargs(is_python3_file),
|
|
229
262
|
)
|
|
230
263
|
|
|
231
264
|
def method_signature_positional(self, is_python3_file: bool) -> List[str]:
|
|
232
|
-
return [
|
|
265
|
+
return [
|
|
266
|
+
parameter.method_signature(is_python3_file) for parameter in self.positional
|
|
267
|
+
]
|
|
233
268
|
|
|
234
269
|
def method_signature_keyword_only(self, is_python3_file: bool) -> List[str]:
|
|
235
270
|
if not (self.keyword_only and is_python3_file):
|
|
236
271
|
return []
|
|
237
|
-
return ["*,"] + [
|
|
272
|
+
return ["*,"] + [
|
|
273
|
+
parameter.method_signature(is_python3_file)
|
|
274
|
+
for parameter in self.keyword_only
|
|
275
|
+
]
|
|
238
276
|
|
|
239
277
|
@staticmethod
|
|
240
278
|
def method_signature_kwargs(is_python3_file: bool) -> List[str]:
|
|
@@ -242,15 +280,28 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
242
280
|
|
|
243
281
|
@property
|
|
244
282
|
def positional(self) -> List[Parameter]:
|
|
245
|
-
return [
|
|
283
|
+
return [
|
|
284
|
+
p
|
|
285
|
+
for p in self.method
|
|
286
|
+
if p.method_location == ParameterMethodLocation.POSITIONAL
|
|
287
|
+
]
|
|
246
288
|
|
|
247
289
|
@property
|
|
248
290
|
def keyword_only(self) -> List[Parameter]:
|
|
249
|
-
return [
|
|
291
|
+
return [
|
|
292
|
+
p
|
|
293
|
+
for p in self.method
|
|
294
|
+
if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
|
|
295
|
+
]
|
|
250
296
|
|
|
251
297
|
@property
|
|
252
298
|
def kwargs(self) -> List[Parameter]:
|
|
253
|
-
return [
|
|
299
|
+
return [
|
|
300
|
+
p
|
|
301
|
+
for p in self.method
|
|
302
|
+
if p.method_location
|
|
303
|
+
in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
|
|
304
|
+
]
|
|
254
305
|
|
|
255
306
|
def kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
|
|
256
307
|
kwargs_to_pop = self.kwargs
|
|
@@ -258,118 +309,65 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
258
309
|
kwargs_to_pop += self.keyword_only
|
|
259
310
|
return kwargs_to_pop
|
|
260
311
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
f"{p.serialized_name}={p.serialized_name}"
|
|
268
|
-
for p in self.keyword_only
|
|
269
|
-
])
|
|
312
|
+
def call(self, is_python3_file: bool) -> List[str]:
|
|
313
|
+
retval = [p.serialized_name for p in self.positional]
|
|
314
|
+
if is_python3_file:
|
|
315
|
+
retval.extend(
|
|
316
|
+
[f"{p.serialized_name}={p.serialized_name}" for p in self.keyword_only]
|
|
317
|
+
)
|
|
270
318
|
retval.append("**kwargs")
|
|
271
319
|
return retval
|
|
272
320
|
|
|
273
321
|
@property
|
|
274
322
|
def is_flattened(self) -> bool:
|
|
275
|
-
return cast(
|
|
276
|
-
|
|
277
|
-
def _create_files_or_data_param(
|
|
278
|
-
params: List[Parameter], serialized_name: str, description: str
|
|
279
|
-
) -> Parameter:
|
|
280
|
-
params[0].need_import = False
|
|
281
|
-
param = copy(params[0])
|
|
282
|
-
param.serialized_name = serialized_name
|
|
283
|
-
param.schema = DictionarySchema(
|
|
284
|
-
namespace="",
|
|
285
|
-
yaml_data={},
|
|
286
|
-
element_type=AnySchema(namespace="", yaml_data={}),
|
|
287
|
-
)
|
|
288
|
-
param.description = description
|
|
289
|
-
return param
|
|
290
|
-
|
|
291
|
-
class ParameterOnlyPathAndBodyPositionalList(ParameterList):
|
|
292
|
-
# use this to change the files and data parameter in the method
|
|
293
|
-
|
|
294
|
-
@property
|
|
295
|
-
def method(self) -> List[Parameter]:
|
|
296
|
-
method_params = super().method
|
|
297
|
-
files_params = [p for p in method_params if p.is_multipart]
|
|
298
|
-
data_params = [p for p in method_params if p.is_data_input]
|
|
299
|
-
if not (files_params or data_params):
|
|
300
|
-
return method_params
|
|
301
|
-
|
|
302
|
-
# update files param
|
|
303
|
-
file_and_data_params = []
|
|
304
|
-
if files_params:
|
|
305
|
-
files_param = _create_files_or_data_param(
|
|
306
|
-
files_params,
|
|
307
|
-
serialized_name="files",
|
|
308
|
-
description="Multipart input for files. See the template in our example to find the input shape."
|
|
309
|
-
)
|
|
310
|
-
file_and_data_params.append(files_param)
|
|
311
|
-
if data_params:
|
|
312
|
-
data_param = _create_files_or_data_param(
|
|
313
|
-
data_params,
|
|
314
|
-
serialized_name="data",
|
|
315
|
-
description="Form-encoded input for data. See the template in our example to find the input shape."
|
|
316
|
-
)
|
|
317
|
-
file_and_data_params.append(data_param)
|
|
318
|
-
method_params = [p for p in method_params if not p.is_multipart and not p.is_data_input]
|
|
319
|
-
positional = [p for p in method_params if p.is_positional]
|
|
320
|
-
keyword_only = self._filter_out_multiple_content_type(
|
|
321
|
-
[p for p in method_params if p.is_keyword_only]
|
|
322
|
-
)
|
|
323
|
-
kwargs = self._filter_out_multiple_content_type(
|
|
324
|
-
[p for p in method_params if p.is_kwarg]
|
|
323
|
+
return cast(
|
|
324
|
+
bool, self.get_from_predicate(lambda parameter: parameter.flattened)
|
|
325
325
|
)
|
|
326
|
-
return positional + file_and_data_params + keyword_only + kwargs
|
|
327
326
|
|
|
328
|
-
def get_parameter_list(code_model):
|
|
329
|
-
if code_model.options["only_path_and_body_params_positional"]:
|
|
330
|
-
return ParameterOnlyPathAndBodyPositionalList
|
|
331
|
-
return ParameterList
|
|
332
327
|
|
|
333
328
|
class GlobalParameterList(ParameterList):
|
|
334
|
-
|
|
335
329
|
@property
|
|
336
330
|
def implementation(self) -> str:
|
|
337
331
|
return "Client"
|
|
338
332
|
|
|
339
333
|
@property
|
|
340
334
|
def method(self) -> List[Parameter]:
|
|
341
|
-
"""The list of parameter used in method signature.
|
|
342
|
-
"""
|
|
335
|
+
"""The list of parameter used in method signature."""
|
|
343
336
|
# Client level should not be on Method, etc.
|
|
344
|
-
positional = [
|
|
337
|
+
positional = [
|
|
338
|
+
p
|
|
339
|
+
for p in self.parameters
|
|
340
|
+
if p.method_location == ParameterMethodLocation.POSITIONAL
|
|
341
|
+
]
|
|
345
342
|
keyword_only = self._filter_out_multiple_content_type(
|
|
346
|
-
[
|
|
343
|
+
[
|
|
344
|
+
p
|
|
345
|
+
for p in self.parameters
|
|
346
|
+
if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
|
|
347
|
+
]
|
|
347
348
|
)
|
|
348
349
|
kwargs = self._filter_out_multiple_content_type(
|
|
349
|
-
[
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
[
|
|
351
|
+
p
|
|
352
|
+
for p in self.parameters
|
|
353
|
+
if p.method_location
|
|
354
|
+
in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
|
|
355
|
+
]
|
|
355
356
|
)
|
|
356
|
-
return signature_parameters
|
|
357
357
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
except AttributeError:
|
|
363
|
-
raise ValueError("You need to first set the code model")
|
|
358
|
+
def _sort(params):
|
|
359
|
+
return sorted(
|
|
360
|
+
params, key=lambda x: not x.default_value and x.required, reverse=True
|
|
361
|
+
)
|
|
364
362
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
self._code_model = val
|
|
363
|
+
signature_parameters = _sort(positional) + _sort(keyword_only) + _sort(kwargs)
|
|
364
|
+
return signature_parameters
|
|
368
365
|
|
|
369
366
|
@property
|
|
370
367
|
def host_variable_name(self) -> str:
|
|
371
368
|
return (
|
|
372
|
-
"endpoint"
|
|
369
|
+
"endpoint"
|
|
370
|
+
if self.code_model.options["version_tolerant"]
|
|
373
371
|
or self.code_model.options["low_level_client"]
|
|
374
372
|
else "base_url"
|
|
375
373
|
)
|
|
@@ -377,17 +375,17 @@ class GlobalParameterList(ParameterList):
|
|
|
377
375
|
@staticmethod
|
|
378
376
|
def _wanted_path_parameter(parameter: Parameter) -> bool:
|
|
379
377
|
return (
|
|
380
|
-
parameter.location == ParameterLocation.Uri
|
|
381
|
-
parameter.implementation == "Client"
|
|
382
|
-
parameter.rest_api_name != "$host"
|
|
378
|
+
parameter.location == ParameterLocation.Uri
|
|
379
|
+
and parameter.implementation == "Client"
|
|
380
|
+
and parameter.rest_api_name != "$host"
|
|
383
381
|
)
|
|
384
382
|
|
|
385
383
|
def add_host(self, host_value: Optional[str]) -> None:
|
|
386
384
|
# only adds if we don't have a parameterized host
|
|
387
385
|
host_param = Parameter(
|
|
388
|
-
self.code_model,
|
|
389
386
|
yaml_data={},
|
|
390
|
-
|
|
387
|
+
code_model=self.code_model,
|
|
388
|
+
schema=StringSchema(yaml_data={"type": "str"}, code_model=self.code_model),
|
|
391
389
|
rest_api_name=self.host_variable_name,
|
|
392
390
|
serialized_name=self.host_variable_name,
|
|
393
391
|
description=f"Service URL.",
|
|
@@ -397,15 +395,19 @@ class GlobalParameterList(ParameterList):
|
|
|
397
395
|
skip_url_encoding=False,
|
|
398
396
|
constraints=[],
|
|
399
397
|
client_default_value=host_value,
|
|
400
|
-
keyword_only=self.code_model.options["version_tolerant"] or self.code_model.options["low_level_client"],
|
|
401
398
|
)
|
|
399
|
+
if (
|
|
400
|
+
self.code_model.options["version_tolerant"]
|
|
401
|
+
or self.code_model.options["low_level_client"]
|
|
402
|
+
):
|
|
403
|
+
host_param.method_location = ParameterMethodLocation.KEYWORD_ONLY
|
|
402
404
|
self.parameters.append(host_param)
|
|
403
405
|
|
|
404
406
|
def add_credential_global_parameter(self) -> None:
|
|
405
407
|
credential_parameter = Parameter(
|
|
406
|
-
self.code_model,
|
|
407
408
|
yaml_data={},
|
|
408
|
-
|
|
409
|
+
code_model=self.code_model,
|
|
410
|
+
schema=self.code_model.credential_model.credential_schema_policy.credential,
|
|
409
411
|
serialized_name="credential",
|
|
410
412
|
rest_api_name="credential",
|
|
411
413
|
implementation="Client",
|
|
@@ -415,7 +417,10 @@ class GlobalParameterList(ParameterList):
|
|
|
415
417
|
skip_url_encoding=True,
|
|
416
418
|
constraints=[],
|
|
417
419
|
)
|
|
418
|
-
if
|
|
420
|
+
if (
|
|
421
|
+
self.code_model.options["version_tolerant"]
|
|
422
|
+
or self.code_model.options["low_level_client"]
|
|
423
|
+
):
|
|
419
424
|
self.parameters.append(credential_parameter)
|
|
420
425
|
else:
|
|
421
426
|
self.parameters.insert(0, credential_parameter)
|
|
@@ -423,7 +428,11 @@ class GlobalParameterList(ParameterList):
|
|
|
423
428
|
@property
|
|
424
429
|
def host(self) -> Optional[Parameter]:
|
|
425
430
|
try:
|
|
426
|
-
return next(
|
|
431
|
+
return next(
|
|
432
|
+
p
|
|
433
|
+
for p in self.parameters
|
|
434
|
+
if p.serialized_name == self.host_variable_name
|
|
435
|
+
)
|
|
427
436
|
except StopIteration:
|
|
428
437
|
return None
|
|
429
438
|
|
|
@@ -432,8 +441,7 @@ class GlobalParameterList(ParameterList):
|
|
|
432
441
|
if self.code_model.service_client.has_parameterized_host:
|
|
433
442
|
return None
|
|
434
443
|
return next(
|
|
435
|
-
p for p in self.parameters
|
|
436
|
-
if p.serialized_name == self.host_variable_name
|
|
444
|
+
p for p in self.parameters if p.serialized_name == self.host_variable_name
|
|
437
445
|
).default_value_declaration
|
|
438
446
|
|
|
439
447
|
@property
|
|
@@ -447,17 +455,24 @@ class GlobalParameterList(ParameterList):
|
|
|
447
455
|
|
|
448
456
|
def kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
|
|
449
457
|
return [
|
|
450
|
-
k
|
|
458
|
+
k
|
|
459
|
+
for k in super().kwargs_to_pop(is_python3_file)
|
|
451
460
|
if not self._param_is_in_config_method(k.serialized_name)
|
|
452
461
|
]
|
|
453
462
|
|
|
454
463
|
def config_kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
|
|
455
464
|
current_kwargs_to_pop = super().kwargs_to_pop(is_python3_file)
|
|
456
|
-
return [
|
|
465
|
+
return [
|
|
466
|
+
k
|
|
467
|
+
for k in current_kwargs_to_pop
|
|
468
|
+
if self._param_is_in_config_method(k.serialized_name)
|
|
469
|
+
]
|
|
457
470
|
|
|
458
471
|
@property
|
|
459
472
|
def config_method(self) -> List[Parameter]:
|
|
460
|
-
return [
|
|
473
|
+
return [
|
|
474
|
+
p for p in self.method if self._param_is_in_config_method(p.serialized_name)
|
|
475
|
+
]
|
|
461
476
|
|
|
462
477
|
def client_method_signature(self, is_python3_file: bool) -> List[str]:
|
|
463
478
|
return self.method_signature(is_python3_file)
|
|
@@ -469,17 +484,23 @@ class GlobalParameterList(ParameterList):
|
|
|
469
484
|
for p in self.positional
|
|
470
485
|
if self._param_is_in_config_method(p.serialized_name)
|
|
471
486
|
]
|
|
472
|
-
keyword_only_params = [
|
|
487
|
+
keyword_only_params = [
|
|
488
|
+
p
|
|
489
|
+
for p in self.keyword_only
|
|
490
|
+
if self._param_is_in_config_method(p.serialized_name)
|
|
491
|
+
]
|
|
473
492
|
keyword_only_method_signature = []
|
|
474
493
|
if is_python3_file:
|
|
475
494
|
keyword_only_method_signature = (
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
p.method_signature(is_python3_file) for p in keyword_only_params
|
|
479
|
-
|
|
480
|
-
|
|
495
|
+
(
|
|
496
|
+
["*,"]
|
|
497
|
+
+ [p.method_signature(is_python3_file) for p in keyword_only_params]
|
|
498
|
+
)
|
|
499
|
+
if keyword_only_params
|
|
500
|
+
else []
|
|
501
|
+
)
|
|
481
502
|
return _method_signature_helper(
|
|
482
503
|
positional=positional,
|
|
483
504
|
keyword_only=keyword_only_method_signature,
|
|
484
|
-
kwarg_params=self.method_signature_kwargs(is_python3_file)
|
|
505
|
+
kwarg_params=self.method_signature_kwargs(is_python3_file),
|
|
485
506
|
)
|