@autorest/python 6.13.16 → 6.13.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/__init__.py +4 -12
- package/autorest/_utils.py +5 -20
- package/autorest/black/__init__.py +1 -3
- package/autorest/codegen/__init__.py +29 -96
- package/autorest/codegen/models/__init__.py +1 -3
- package/autorest/codegen/models/base.py +2 -6
- package/autorest/codegen/models/base_builder.py +2 -6
- package/autorest/codegen/models/client.py +24 -86
- package/autorest/codegen/models/code_model.py +13 -53
- package/autorest/codegen/models/combined_type.py +3 -9
- package/autorest/codegen/models/constant_type.py +4 -14
- package/autorest/codegen/models/credential_types.py +11 -35
- package/autorest/codegen/models/dictionary_type.py +4 -12
- package/autorest/codegen/models/enum_type.py +10 -31
- package/autorest/codegen/models/imports.py +15 -41
- package/autorest/codegen/models/list_type.py +7 -23
- package/autorest/codegen/models/lro_operation.py +6 -18
- package/autorest/codegen/models/lro_paging_operation.py +1 -3
- package/autorest/codegen/models/model_type.py +21 -73
- package/autorest/codegen/models/operation.py +41 -139
- package/autorest/codegen/models/operation_group.py +21 -60
- package/autorest/codegen/models/paging_operation.py +13 -43
- package/autorest/codegen/models/parameter.py +16 -54
- package/autorest/codegen/models/parameter_list.py +27 -103
- package/autorest/codegen/models/primitive_types.py +15 -49
- package/autorest/codegen/models/property.py +8 -28
- package/autorest/codegen/models/request_builder.py +11 -39
- package/autorest/codegen/models/request_builder_parameter.py +4 -13
- package/autorest/codegen/models/response.py +16 -57
- package/autorest/codegen/serializers/__init__.py +46 -150
- package/autorest/codegen/serializers/builder_serializer.py +113 -402
- package/autorest/codegen/serializers/client_serializer.py +25 -78
- package/autorest/codegen/serializers/enum_serializer.py +1 -3
- package/autorest/codegen/serializers/general_serializer.py +6 -22
- package/autorest/codegen/serializers/import_serializer.py +13 -40
- package/autorest/codegen/serializers/metadata_serializer.py +7 -21
- package/autorest/codegen/serializers/model_init_serializer.py +1 -5
- package/autorest/codegen/serializers/model_serializer.py +13 -51
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -3
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -8
- package/autorest/codegen/serializers/parameter_serializer.py +8 -26
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -3
- package/autorest/codegen/serializers/sample_serializer.py +13 -39
- package/autorest/codegen/serializers/test_serializer.py +10 -30
- package/autorest/codegen/serializers/types_serializer.py +1 -3
- package/autorest/codegen/templates/serialization.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +1 -3
- package/autorest/jsonrpc/server.py +3 -9
- package/autorest/jsonrpc/stdstream.py +4 -12
- package/autorest/m2r/__init__.py +2 -6
- package/autorest/m4reformatter/__init__.py +72 -237
- package/autorest/multiapi/__init__.py +4 -11
- package/autorest/multiapi/models/client.py +7 -21
- package/autorest/multiapi/models/code_model.py +9 -28
- package/autorest/multiapi/models/config.py +1 -3
- package/autorest/multiapi/models/global_parameters.py +6 -16
- package/autorest/multiapi/models/imports.py +5 -9
- package/autorest/multiapi/models/operation_mixin_group.py +5 -17
- package/autorest/multiapi/serializers/__init__.py +10 -31
- package/autorest/multiapi/serializers/import_serializer.py +8 -24
- package/autorest/multiapi/utils.py +2 -6
- package/autorest/multiclient/__init__.py +1 -3
- package/autorest/postprocess/__init__.py +9 -29
- package/autorest/postprocess/get_all.py +1 -3
- package/autorest/postprocess/venvtools.py +1 -3
- package/autorest/preprocess/__init__.py +43 -129
- package/install.py +2 -0
- package/package.json +1 -1
- package/prepare.py +3 -1
- package/requirements.txt +1 -1
- package/run_cadl.py +1 -3
- package/setup.py +25 -25
- package/start.py +2 -0
- package/venvtools.py +15 -10
|
@@ -33,12 +33,8 @@ from .parameter import (
|
|
|
33
33
|
ConfigParameter,
|
|
34
34
|
)
|
|
35
35
|
|
|
36
|
-
ParameterType = TypeVar(
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
BodyParameterType = TypeVar(
|
|
40
|
-
"BodyParameterType", bound=Union[BodyParameter, RequestBuilderBodyParameter]
|
|
41
|
-
)
|
|
36
|
+
ParameterType = TypeVar("ParameterType", bound=Union[Parameter, RequestBuilderParameter])
|
|
37
|
+
BodyParameterType = TypeVar("BodyParameterType", bound=Union[BodyParameter, RequestBuilderBodyParameter])
|
|
42
38
|
|
|
43
39
|
if TYPE_CHECKING:
|
|
44
40
|
from .code_model import CodeModel
|
|
@@ -52,17 +48,13 @@ class ParameterImplementation(Enum):
|
|
|
52
48
|
_LOGGER = logging.getLogger(__name__)
|
|
53
49
|
|
|
54
50
|
|
|
55
|
-
def method_signature_helper(
|
|
56
|
-
positional: List[str], keyword_only: Optional[List[str]], kwarg_params: List[str]
|
|
57
|
-
):
|
|
51
|
+
def method_signature_helper(positional: List[str], keyword_only: Optional[List[str]], kwarg_params: List[str]):
|
|
58
52
|
keyword_only = keyword_only or []
|
|
59
53
|
return positional + keyword_only + kwarg_params
|
|
60
54
|
|
|
61
55
|
|
|
62
56
|
def _sort(params):
|
|
63
|
-
return sorted(
|
|
64
|
-
params, key=lambda x: not (x.client_default_value or x.optional), reverse=True
|
|
65
|
-
)
|
|
57
|
+
return sorted(params, key=lambda x: not (x.client_default_value or x.optional), reverse=True)
|
|
66
58
|
|
|
67
59
|
|
|
68
60
|
class _ParameterListBase(
|
|
@@ -110,17 +102,13 @@ class _ParameterListBase(
|
|
|
110
102
|
|
|
111
103
|
@staticmethod
|
|
112
104
|
@abstractmethod
|
|
113
|
-
def body_parameter_creator() ->
|
|
114
|
-
Callable[[Dict[str, Any], "CodeModel"], BodyParameterType]
|
|
115
|
-
):
|
|
105
|
+
def body_parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], BodyParameterType]:
|
|
116
106
|
"""Callable for creating body parameters"""
|
|
117
107
|
|
|
118
108
|
@property
|
|
119
109
|
def grouped(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
120
110
|
"""All parameters that are inside a parameter group"""
|
|
121
|
-
params: List[Union[ParameterType, BodyParameterType]] = [
|
|
122
|
-
p for p in self.parameters if p.grouped_by
|
|
123
|
-
]
|
|
111
|
+
params: List[Union[ParameterType, BodyParameterType]] = [p for p in self.parameters if p.grouped_by]
|
|
124
112
|
if self.has_body and self.body_parameter.grouped_by:
|
|
125
113
|
params.append(self.body_parameter)
|
|
126
114
|
return params
|
|
@@ -137,11 +125,7 @@ class _ParameterListBase(
|
|
|
137
125
|
@property
|
|
138
126
|
def path(self) -> List[ParameterType]:
|
|
139
127
|
"""All path parameters"""
|
|
140
|
-
return [
|
|
141
|
-
p
|
|
142
|
-
for p in self.parameters
|
|
143
|
-
if p.location in (ParameterLocation.PATH, ParameterLocation.ENDPOINT_PATH)
|
|
144
|
-
]
|
|
128
|
+
return [p for p in self.parameters if p.location in (ParameterLocation.PATH, ParameterLocation.ENDPOINT_PATH)]
|
|
145
129
|
|
|
146
130
|
@property
|
|
147
131
|
def query(self) -> List[ParameterType]:
|
|
@@ -162,34 +146,20 @@ class _ParameterListBase(
|
|
|
162
146
|
def positional(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
163
147
|
"""All positional parameters"""
|
|
164
148
|
return _sort(
|
|
165
|
-
[
|
|
166
|
-
p
|
|
167
|
-
for p in self.unsorted_method_params
|
|
168
|
-
if p.method_location == ParameterMethodLocation.POSITIONAL
|
|
169
|
-
]
|
|
149
|
+
[p for p in self.unsorted_method_params if p.method_location == ParameterMethodLocation.POSITIONAL]
|
|
170
150
|
)
|
|
171
151
|
|
|
172
152
|
@property
|
|
173
153
|
def keyword_only(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
174
154
|
"""All keyword only parameters"""
|
|
175
155
|
return _sort(
|
|
176
|
-
[
|
|
177
|
-
p
|
|
178
|
-
for p in self.unsorted_method_params
|
|
179
|
-
if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
|
|
180
|
-
]
|
|
156
|
+
[p for p in self.unsorted_method_params if p.method_location == ParameterMethodLocation.KEYWORD_ONLY]
|
|
181
157
|
)
|
|
182
158
|
|
|
183
159
|
@property
|
|
184
160
|
def kwarg(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
185
161
|
"""All kwargs"""
|
|
186
|
-
return _sort(
|
|
187
|
-
[
|
|
188
|
-
p
|
|
189
|
-
for p in self.unsorted_method_params
|
|
190
|
-
if p.method_location == ParameterMethodLocation.KWARG
|
|
191
|
-
]
|
|
192
|
-
)
|
|
162
|
+
return _sort([p for p in self.unsorted_method_params if p.method_location == ParameterMethodLocation.KWARG])
|
|
193
163
|
|
|
194
164
|
@property
|
|
195
165
|
def body_parameter(self) -> BodyParameterType:
|
|
@@ -261,20 +231,12 @@ class _ParameterListBase(
|
|
|
261
231
|
"""Method kwargs we want to pop"""
|
|
262
232
|
# don't want to pop bodies unless it's a constant
|
|
263
233
|
kwargs_to_pop = self.kwarg
|
|
264
|
-
return [
|
|
265
|
-
k
|
|
266
|
-
for k in kwargs_to_pop
|
|
267
|
-
if k.location != ParameterLocation.BODY or k.constant
|
|
268
|
-
]
|
|
234
|
+
return [k for k in kwargs_to_pop if k.location != ParameterLocation.BODY or k.constant]
|
|
269
235
|
|
|
270
236
|
@property
|
|
271
237
|
def call(self) -> List[str]:
|
|
272
238
|
"""How to pass in parameters to call the operation"""
|
|
273
|
-
retval = [
|
|
274
|
-
p.client_name
|
|
275
|
-
for p in self.method
|
|
276
|
-
if p.method_location == ParameterMethodLocation.POSITIONAL
|
|
277
|
-
]
|
|
239
|
+
retval = [p.client_name for p in self.method if p.method_location == ParameterMethodLocation.POSITIONAL]
|
|
278
240
|
retval.extend(
|
|
279
241
|
[
|
|
280
242
|
f"{p.client_name}={p.client_name}"
|
|
@@ -287,15 +249,10 @@ class _ParameterListBase(
|
|
|
287
249
|
|
|
288
250
|
@classmethod
|
|
289
251
|
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel"):
|
|
290
|
-
parameters = [
|
|
291
|
-
cls.parameter_creator()(parameter, code_model)
|
|
292
|
-
for parameter in yaml_data["parameters"]
|
|
293
|
-
]
|
|
252
|
+
parameters = [cls.parameter_creator()(parameter, code_model) for parameter in yaml_data["parameters"]]
|
|
294
253
|
body_parameter = None
|
|
295
254
|
if yaml_data.get("bodyParameter"):
|
|
296
|
-
body_parameter = cls.body_parameter_creator()(
|
|
297
|
-
yaml_data["bodyParameter"], code_model
|
|
298
|
-
)
|
|
255
|
+
body_parameter = cls.body_parameter_creator()(yaml_data["bodyParameter"], code_model)
|
|
299
256
|
return cls(
|
|
300
257
|
yaml_data,
|
|
301
258
|
code_model,
|
|
@@ -304,11 +261,7 @@ class _ParameterListBase(
|
|
|
304
261
|
)
|
|
305
262
|
|
|
306
263
|
|
|
307
|
-
class _ParameterList(
|
|
308
|
-
_ParameterListBase[ # pylint: disable=unsubscriptable-object
|
|
309
|
-
Parameter, BodyParameter
|
|
310
|
-
]
|
|
311
|
-
):
|
|
264
|
+
class _ParameterList(_ParameterListBase[Parameter, BodyParameter]): # pylint: disable=unsubscriptable-object
|
|
312
265
|
"""Base Parameter class for the two operation ParameterLists"""
|
|
313
266
|
|
|
314
267
|
@staticmethod
|
|
@@ -316,9 +269,7 @@ class _ParameterList(
|
|
|
316
269
|
return Parameter.from_yaml
|
|
317
270
|
|
|
318
271
|
@staticmethod
|
|
319
|
-
def body_parameter_creator() ->
|
|
320
|
-
Callable[[Dict[str, Any], "CodeModel"], BodyParameter]
|
|
321
|
-
):
|
|
272
|
+
def body_parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], BodyParameter]:
|
|
322
273
|
return BodyParameter.from_yaml
|
|
323
274
|
|
|
324
275
|
@property
|
|
@@ -327,9 +278,7 @@ class _ParameterList(
|
|
|
327
278
|
|
|
328
279
|
@property
|
|
329
280
|
def path(self) -> List[Parameter]:
|
|
330
|
-
return [
|
|
331
|
-
k for k in super().path if k.location == ParameterLocation.ENDPOINT_PATH
|
|
332
|
-
]
|
|
281
|
+
return [k for k in super().path if k.location == ParameterLocation.ENDPOINT_PATH]
|
|
333
282
|
|
|
334
283
|
|
|
335
284
|
class ParameterList(_ParameterList):
|
|
@@ -337,22 +286,16 @@ class ParameterList(_ParameterList):
|
|
|
337
286
|
|
|
338
287
|
|
|
339
288
|
class _RequestBuilderParameterList(
|
|
340
|
-
_ParameterListBase[ # pylint: disable=unsubscriptable-object
|
|
341
|
-
RequestBuilderParameter, RequestBuilderBodyParameter
|
|
342
|
-
]
|
|
289
|
+
_ParameterListBase[RequestBuilderParameter, RequestBuilderBodyParameter] # pylint: disable=unsubscriptable-object
|
|
343
290
|
):
|
|
344
291
|
"""_RequestBuilderParameterList is base parameter list for RequestBuilder classes"""
|
|
345
292
|
|
|
346
293
|
@staticmethod
|
|
347
|
-
def parameter_creator() ->
|
|
348
|
-
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameter]
|
|
349
|
-
):
|
|
294
|
+
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameter]:
|
|
350
295
|
return RequestBuilderParameter.from_yaml
|
|
351
296
|
|
|
352
297
|
@staticmethod
|
|
353
|
-
def body_parameter_creator() ->
|
|
354
|
-
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameter]
|
|
355
|
-
):
|
|
298
|
+
def body_parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameter]:
|
|
356
299
|
return RequestBuilderBodyParameter.from_yaml
|
|
357
300
|
|
|
358
301
|
@property
|
|
@@ -367,34 +310,21 @@ class _RequestBuilderParameterList(
|
|
|
367
310
|
retval = [
|
|
368
311
|
p
|
|
369
312
|
for p in super().unsorted_method_params
|
|
370
|
-
if not (
|
|
371
|
-
p.location == ParameterLocation.BODY
|
|
372
|
-
and cast(RequestBuilderBodyParameter, p).is_partial_body
|
|
373
|
-
)
|
|
313
|
+
if not (p.location == ParameterLocation.BODY and cast(RequestBuilderBodyParameter, p).is_partial_body)
|
|
374
314
|
]
|
|
375
|
-
retval.extend(
|
|
376
|
-
[
|
|
377
|
-
p
|
|
378
|
-
for p in self.parameters
|
|
379
|
-
if p.implementation == "Client" and p.in_method_signature
|
|
380
|
-
]
|
|
381
|
-
)
|
|
315
|
+
retval.extend([p for p in self.parameters if p.implementation == "Client" and p.in_method_signature])
|
|
382
316
|
return retval
|
|
383
317
|
|
|
384
318
|
@property
|
|
385
319
|
def path(self) -> List[RequestBuilderParameter]:
|
|
386
|
-
return [
|
|
387
|
-
p for p in super().path if p.location != ParameterLocation.ENDPOINT_PATH
|
|
388
|
-
]
|
|
320
|
+
return [p for p in super().path if p.location != ParameterLocation.ENDPOINT_PATH]
|
|
389
321
|
|
|
390
322
|
@property
|
|
391
323
|
def constant(
|
|
392
324
|
self,
|
|
393
325
|
) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameter]]:
|
|
394
326
|
"""All constant parameters"""
|
|
395
|
-
return [
|
|
396
|
-
p for p in super().constant if p.location != ParameterLocation.ENDPOINT_PATH
|
|
397
|
-
]
|
|
327
|
+
return [p for p in super().constant if p.location != ParameterLocation.ENDPOINT_PATH]
|
|
398
328
|
|
|
399
329
|
|
|
400
330
|
class RequestBuilderParameterList(_RequestBuilderParameterList):
|
|
@@ -405,15 +335,11 @@ class OverloadedRequestBuilderParameterList(_RequestBuilderParameterList):
|
|
|
405
335
|
"""Parameter list for OverloadedRequestBuilder"""
|
|
406
336
|
|
|
407
337
|
|
|
408
|
-
class _ClientGlobalParameterList( # pylint: disable=abstract-method
|
|
409
|
-
_ParameterListBase[ParameterType, BodyParameter]
|
|
410
|
-
):
|
|
338
|
+
class _ClientGlobalParameterList(_ParameterListBase[ParameterType, BodyParameter]): # pylint: disable=abstract-method
|
|
411
339
|
"""Base parameter list for client and config classes"""
|
|
412
340
|
|
|
413
341
|
@staticmethod
|
|
414
|
-
def body_parameter_creator() ->
|
|
415
|
-
Callable[[Dict[str, Any], "CodeModel"], BodyParameter]
|
|
416
|
-
):
|
|
342
|
+
def body_parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], BodyParameter]:
|
|
417
343
|
return BodyParameter.from_yaml
|
|
418
344
|
|
|
419
345
|
@property
|
|
@@ -429,9 +355,7 @@ class _ClientGlobalParameterList( # pylint: disable=abstract-method
|
|
|
429
355
|
|
|
430
356
|
@property
|
|
431
357
|
def path(self) -> List[ParameterType]:
|
|
432
|
-
return [
|
|
433
|
-
p for p in super().path if p.location == ParameterLocation.ENDPOINT_PATH
|
|
434
|
-
]
|
|
358
|
+
return [p for p in super().path if p.location == ParameterLocation.ENDPOINT_PATH]
|
|
435
359
|
|
|
436
360
|
|
|
437
361
|
class ClientGlobalParameterList(_ClientGlobalParameterList[ClientParameter]):
|
|
@@ -24,9 +24,7 @@ class RawString(object):
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class PrimitiveType(BaseType): # pylint: disable=abstract-method
|
|
27
|
-
def description(
|
|
28
|
-
self, *, is_operation_file: bool # pylint: disable=unused-argument
|
|
29
|
-
) -> str:
|
|
27
|
+
def description(self, *, is_operation_file: bool) -> str: # pylint: disable=unused-argument
|
|
30
28
|
return ""
|
|
31
29
|
|
|
32
30
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
@@ -46,25 +44,18 @@ class PrimitiveType(BaseType): # pylint: disable=abstract-method
|
|
|
46
44
|
if optional:
|
|
47
45
|
comment = add_to_description(comment, "Optional.")
|
|
48
46
|
if self.client_default_value is not None:
|
|
49
|
-
client_default_value_declaration = (
|
|
50
|
-
|
|
51
|
-
or self.get_declaration(self.client_default_value)
|
|
47
|
+
client_default_value_declaration = client_default_value_declaration or self.get_declaration(
|
|
48
|
+
self.client_default_value
|
|
52
49
|
)
|
|
53
50
|
if client_default_value_declaration:
|
|
54
|
-
comment = add_to_description(
|
|
55
|
-
comment, f"Default value is {client_default_value_declaration}."
|
|
56
|
-
)
|
|
51
|
+
comment = add_to_description(comment, f"Default value is {client_default_value_declaration}.")
|
|
57
52
|
else:
|
|
58
|
-
client_default_value_declaration =
|
|
59
|
-
self.default_template_representation_declaration
|
|
60
|
-
)
|
|
53
|
+
client_default_value_declaration = self.default_template_representation_declaration
|
|
61
54
|
if description:
|
|
62
55
|
comment = add_to_description(comment, description)
|
|
63
56
|
if comment:
|
|
64
57
|
comment = f"# {comment}"
|
|
65
|
-
return client_default_value_declaration + (
|
|
66
|
-
"" if self.code_model.for_test else comment
|
|
67
|
-
)
|
|
58
|
+
return client_default_value_declaration + ("" if self.code_model.for_test else comment)
|
|
68
59
|
|
|
69
60
|
@property
|
|
70
61
|
def default_template_representation_declaration(self) -> str:
|
|
@@ -149,9 +140,7 @@ class BinaryIteratorType(PrimitiveType):
|
|
|
149
140
|
|
|
150
141
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
151
142
|
file_import = FileImport(self.code_model)
|
|
152
|
-
file_import.add_submodule_import(
|
|
153
|
-
"typing", self._iterator_name(**kwargs), ImportType.STDLIB
|
|
154
|
-
)
|
|
143
|
+
file_import.add_submodule_import("typing", self._iterator_name(**kwargs), ImportType.STDLIB)
|
|
155
144
|
return file_import
|
|
156
145
|
|
|
157
146
|
@property
|
|
@@ -176,16 +165,12 @@ class AnyType(PrimitiveType):
|
|
|
176
165
|
|
|
177
166
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
178
167
|
file_import = FileImport(self.code_model)
|
|
179
|
-
file_import.add_submodule_import(
|
|
180
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
181
|
-
)
|
|
168
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
182
169
|
return file_import
|
|
183
170
|
|
|
184
171
|
@property
|
|
185
172
|
def instance_check_template(self) -> str:
|
|
186
|
-
raise ValueError(
|
|
187
|
-
"Shouldn't do instance check on an anytype, it can be anything"
|
|
188
|
-
)
|
|
173
|
+
raise ValueError("Shouldn't do instance check on an anytype, it can be anything")
|
|
189
174
|
|
|
190
175
|
|
|
191
176
|
class AnyObjectType(PrimitiveType):
|
|
@@ -230,26 +215,10 @@ class NumberType(PrimitiveType): # pylint: disable=abstract-method
|
|
|
230
215
|
@property
|
|
231
216
|
def serialization_constraints(self) -> List[str]:
|
|
232
217
|
validation_constraints = [
|
|
233
|
-
(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
),
|
|
238
|
-
(
|
|
239
|
-
f"maximum={self.maximum}"
|
|
240
|
-
if self.maximum is not None and not self.exclusive_maximum
|
|
241
|
-
else None
|
|
242
|
-
),
|
|
243
|
-
(
|
|
244
|
-
f"minimum_ex={self.minimum}"
|
|
245
|
-
if self.minimum is not None and self.exclusive_minimum
|
|
246
|
-
else None
|
|
247
|
-
),
|
|
248
|
-
(
|
|
249
|
-
f"minimum={self.minimum}"
|
|
250
|
-
if self.minimum is not None and not self.exclusive_minimum
|
|
251
|
-
else None
|
|
252
|
-
),
|
|
218
|
+
(f"maximum_ex={self.maximum}" if self.maximum is not None and self.exclusive_maximum else None),
|
|
219
|
+
(f"maximum={self.maximum}" if self.maximum is not None and not self.exclusive_maximum else None),
|
|
220
|
+
(f"minimum_ex={self.minimum}" if self.minimum is not None and self.exclusive_minimum else None),
|
|
221
|
+
(f"minimum={self.minimum}" if self.minimum is not None and not self.exclusive_minimum else None),
|
|
253
222
|
f"multiple={self.multiple}" if self.multiple else None,
|
|
254
223
|
]
|
|
255
224
|
return [x for x in validation_constraints if x is not None]
|
|
@@ -353,9 +322,7 @@ class StringType(PrimitiveType):
|
|
|
353
322
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
354
323
|
self.max_length: Optional[int] = yaml_data.get("maxLength")
|
|
355
324
|
self.min_length: Optional[int] = (
|
|
356
|
-
yaml_data.get("minLength", 0)
|
|
357
|
-
if yaml_data.get("maxLength")
|
|
358
|
-
else yaml_data.get("minLength")
|
|
325
|
+
yaml_data.get("minLength", 0) if yaml_data.get("maxLength") else yaml_data.get("minLength")
|
|
359
326
|
)
|
|
360
327
|
self.pattern: Optional[str] = yaml_data.get("pattern")
|
|
361
328
|
|
|
@@ -400,8 +367,7 @@ class DatetimeType(PrimitiveType):
|
|
|
400
367
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
401
368
|
self.encode = (
|
|
402
369
|
"rfc3339"
|
|
403
|
-
if yaml_data.get("encode", "date-time") == "date-time"
|
|
404
|
-
or yaml_data.get("encode", "date-time") == "rfc3339"
|
|
370
|
+
if yaml_data.get("encode", "date-time") == "date-time" or yaml_data.get("encode", "date-time") == "rfc3339"
|
|
405
371
|
else "rfc7231"
|
|
406
372
|
)
|
|
407
373
|
|
|
@@ -37,12 +37,8 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
37
37
|
if self.client_default_value is None:
|
|
38
38
|
self.client_default_value = self.type.client_default_value
|
|
39
39
|
self.flattened_names: List[str] = yaml_data.get("flattenedNames", [])
|
|
40
|
-
self.is_multipart_file_input: bool = yaml_data.get(
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
self.flatten = self.yaml_data.get("flatten", False) and not getattr(
|
|
44
|
-
self.type, "flattened_property", False
|
|
45
|
-
)
|
|
40
|
+
self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False)
|
|
41
|
+
self.flatten = self.yaml_data.get("flatten", False) and not getattr(self.type, "flattened_property", False)
|
|
46
42
|
|
|
47
43
|
@property
|
|
48
44
|
def pylint_disable(self) -> str:
|
|
@@ -59,9 +55,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
59
55
|
description = add_to_description(description, "Required.")
|
|
60
56
|
# don't want model type documentation as part of property doc
|
|
61
57
|
type_description = (
|
|
62
|
-
""
|
|
63
|
-
if isinstance(self.type, ModelType)
|
|
64
|
-
else self.type.description(is_operation_file=is_operation_file)
|
|
58
|
+
"" if isinstance(self.type, ModelType) else self.type.description(is_operation_file=is_operation_file)
|
|
65
59
|
)
|
|
66
60
|
return add_to_description(description, type_description)
|
|
67
61
|
|
|
@@ -77,11 +71,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
77
71
|
def constant(self) -> bool:
|
|
78
72
|
# this bool doesn't consider you to be constant if you are a discriminator
|
|
79
73
|
# you also have to be required to be considered a constant
|
|
80
|
-
return (
|
|
81
|
-
isinstance(self.type, ConstantType)
|
|
82
|
-
and not self.optional
|
|
83
|
-
and not self.is_discriminator
|
|
84
|
-
)
|
|
74
|
+
return isinstance(self.type, ConstantType) and not self.optional and not self.is_discriminator
|
|
85
75
|
|
|
86
76
|
@property
|
|
87
77
|
def is_input(self):
|
|
@@ -104,16 +94,10 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
104
94
|
"""If this discriminator is on the base model for polymorphic inheritance"""
|
|
105
95
|
if self.is_enum_discriminator:
|
|
106
96
|
return self.is_polymorphic and self.client_default_value is None
|
|
107
|
-
return (
|
|
108
|
-
self.is_discriminator
|
|
109
|
-
and self.is_polymorphic
|
|
110
|
-
and cast(ConstantType, self.type).value is None
|
|
111
|
-
)
|
|
97
|
+
return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
|
|
112
98
|
|
|
113
99
|
def type_annotation(self, *, is_operation_file: bool = False) -> str:
|
|
114
|
-
types_type_annotation = self.type.type_annotation(
|
|
115
|
-
is_operation_file=is_operation_file
|
|
116
|
-
)
|
|
100
|
+
types_type_annotation = self.type.type_annotation(is_operation_file=is_operation_file)
|
|
117
101
|
if self.is_multipart_file_input:
|
|
118
102
|
# we only support FileType or list of FileType
|
|
119
103
|
types_type_annotation = types_type_annotation.replace("bytes", "FileType")
|
|
@@ -137,9 +121,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
137
121
|
file_type_str = '"filetype"' if self.code_model.for_test else "filetype"
|
|
138
122
|
return f"[{file_type_str}]" if self.type.type == "list" else file_type_str
|
|
139
123
|
if self.client_default_value:
|
|
140
|
-
client_default_value_declaration = self.get_declaration(
|
|
141
|
-
self.client_default_value
|
|
142
|
-
)
|
|
124
|
+
client_default_value_declaration = self.get_declaration(self.client_default_value)
|
|
143
125
|
if self.description(is_operation_file=True):
|
|
144
126
|
description = self.description(is_operation_file=True)
|
|
145
127
|
# make sure there is no \n otherwise the json template will be invalid
|
|
@@ -172,9 +154,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
172
154
|
file_import = FileImport(self.code_model)
|
|
173
155
|
if self.is_discriminator and isinstance(self.type, EnumType):
|
|
174
156
|
return file_import
|
|
175
|
-
file_import.merge(
|
|
176
|
-
self.type.imports(**kwargs, relative_path="..", model_typing=True)
|
|
177
|
-
)
|
|
157
|
+
file_import.merge(self.type.imports(**kwargs, relative_path="..", model_typing=True))
|
|
178
158
|
if self.optional and self.client_default_value is None:
|
|
179
159
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
180
160
|
if self.code_model.options["models_mode"] == "dpg":
|
|
@@ -87,19 +87,12 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
87
87
|
def imports(self) -> FileImport:
|
|
88
88
|
file_import = FileImport(self.code_model)
|
|
89
89
|
relative_path = ".."
|
|
90
|
-
if
|
|
91
|
-
not self.code_model.options["builders_visibility"] == "embedded"
|
|
92
|
-
and self.group_name
|
|
93
|
-
):
|
|
90
|
+
if not self.code_model.options["builders_visibility"] == "embedded" and self.group_name:
|
|
94
91
|
relative_path = "..." if self.group_name else ".."
|
|
95
92
|
if self.abstract:
|
|
96
93
|
return file_import
|
|
97
94
|
for parameter in self.parameters.method:
|
|
98
|
-
file_import.merge(
|
|
99
|
-
parameter.imports(
|
|
100
|
-
async_mode=False, relative_path=relative_path, operation=self
|
|
101
|
-
)
|
|
102
|
-
)
|
|
95
|
+
file_import.merge(parameter.imports(async_mode=False, relative_path=relative_path, operation=self))
|
|
103
96
|
|
|
104
97
|
file_import.add_submodule_import(
|
|
105
98
|
"rest",
|
|
@@ -113,33 +106,23 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
113
106
|
"case_insensitive_dict",
|
|
114
107
|
ImportType.SDKCORE,
|
|
115
108
|
)
|
|
116
|
-
file_import.add_submodule_import(
|
|
117
|
-
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
118
|
-
)
|
|
109
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL)
|
|
119
110
|
file_import.add_msrest_import(
|
|
120
111
|
relative_path=(
|
|
121
112
|
"..."
|
|
122
|
-
if (
|
|
123
|
-
not self.code_model.options["builders_visibility"] == "embedded"
|
|
124
|
-
and self.group_name
|
|
125
|
-
)
|
|
113
|
+
if (not self.code_model.options["builders_visibility"] == "embedded" and self.group_name)
|
|
126
114
|
else ".."
|
|
127
115
|
),
|
|
128
116
|
msrest_import_type=MsrestImportType.Serializer,
|
|
129
117
|
typing_section=TypingSection.REGULAR,
|
|
130
118
|
)
|
|
131
|
-
if
|
|
132
|
-
self.overloads
|
|
133
|
-
and self.code_model.options["builders_visibility"] != "embedded"
|
|
134
|
-
):
|
|
119
|
+
if self.overloads and self.code_model.options["builders_visibility"] != "embedded":
|
|
135
120
|
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
|
|
136
121
|
return file_import
|
|
137
122
|
|
|
138
123
|
@staticmethod
|
|
139
124
|
@abstractmethod
|
|
140
|
-
def parameter_list_type() ->
|
|
141
|
-
Callable[[Dict[str, Any], "CodeModel"], ParameterListType]
|
|
142
|
-
): ...
|
|
125
|
+
def parameter_list_type() -> Callable[[Dict[str, Any], "CodeModel"], ParameterListType]: ...
|
|
143
126
|
|
|
144
127
|
@classmethod
|
|
145
128
|
def get_name(
|
|
@@ -150,13 +133,8 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
150
133
|
client: "Client",
|
|
151
134
|
) -> str:
|
|
152
135
|
additional_mark = ""
|
|
153
|
-
if
|
|
154
|
-
|
|
155
|
-
and code_model.options["builders_visibility"] == "embedded"
|
|
156
|
-
):
|
|
157
|
-
additional_mark = (
|
|
158
|
-
yaml_data["groupName"] or client.yaml_data["builderPadName"]
|
|
159
|
-
)
|
|
136
|
+
if code_model.options["combine_operation_files"] and code_model.options["builders_visibility"] == "embedded":
|
|
137
|
+
additional_mark = yaml_data["groupName"] or client.yaml_data["builderPadName"]
|
|
160
138
|
names = [
|
|
161
139
|
"build",
|
|
162
140
|
additional_mark,
|
|
@@ -193,19 +171,13 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
193
171
|
|
|
194
172
|
class RequestBuilder(RequestBuilderBase[RequestBuilderParameterList]):
|
|
195
173
|
@staticmethod
|
|
196
|
-
def parameter_list_type() ->
|
|
197
|
-
Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameterList]
|
|
198
|
-
):
|
|
174
|
+
def parameter_list_type() -> Callable[[Dict[str, Any], "CodeModel"], RequestBuilderParameterList]:
|
|
199
175
|
return RequestBuilderParameterList.from_yaml
|
|
200
176
|
|
|
201
177
|
|
|
202
|
-
class OverloadedRequestBuilder(
|
|
203
|
-
RequestBuilderBase[OverloadedRequestBuilderParameterList]
|
|
204
|
-
):
|
|
178
|
+
class OverloadedRequestBuilder(RequestBuilderBase[OverloadedRequestBuilderParameterList]):
|
|
205
179
|
@staticmethod
|
|
206
|
-
def parameter_list_type() ->
|
|
207
|
-
Callable[[Dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList]
|
|
208
|
-
):
|
|
180
|
+
def parameter_list_type() -> Callable[[Dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList]:
|
|
209
181
|
return OverloadedRequestBuilderParameterList.from_yaml
|
|
210
182
|
|
|
211
183
|
|
|
@@ -40,9 +40,7 @@ class RequestBuilderBodyParameter(BodyParameter):
|
|
|
40
40
|
@property
|
|
41
41
|
def in_method_signature(self) -> bool:
|
|
42
42
|
return (
|
|
43
|
-
super().in_method_signature
|
|
44
|
-
and not self.is_partial_body
|
|
45
|
-
and self.code_model.options["models_mode"] != "dpg"
|
|
43
|
+
super().in_method_signature and not self.is_partial_body and self.code_model.options["models_mode"] != "dpg"
|
|
46
44
|
)
|
|
47
45
|
|
|
48
46
|
@property
|
|
@@ -54,9 +52,7 @@ class RequestBuilderBodyParameter(BodyParameter):
|
|
|
54
52
|
)
|
|
55
53
|
|
|
56
54
|
@classmethod
|
|
57
|
-
def from_yaml(
|
|
58
|
-
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
59
|
-
) -> "RequestBuilderBodyParameter":
|
|
55
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "RequestBuilderBodyParameter":
|
|
60
56
|
return super().from_yaml(yaml_data, code_model) # type: ignore
|
|
61
57
|
|
|
62
58
|
@property
|
|
@@ -92,9 +88,7 @@ class RequestBuilderParameter(Parameter):
|
|
|
92
88
|
if self.grouped_by and not self.in_flattened_body:
|
|
93
89
|
return True
|
|
94
90
|
return super().in_method_signature and not (
|
|
95
|
-
self.location == ParameterLocation.ENDPOINT_PATH
|
|
96
|
-
or self.in_flattened_body
|
|
97
|
-
or self.grouper
|
|
91
|
+
self.location == ParameterLocation.ENDPOINT_PATH or self.in_flattened_body or self.grouper
|
|
98
92
|
)
|
|
99
93
|
|
|
100
94
|
@property
|
|
@@ -106,10 +100,7 @@ class RequestBuilderParameter(Parameter):
|
|
|
106
100
|
super_method_location = super().method_location
|
|
107
101
|
if super_method_location == ParameterMethodLocation.KWARG:
|
|
108
102
|
return super_method_location
|
|
109
|
-
if
|
|
110
|
-
self.in_overriden
|
|
111
|
-
and super_method_location == ParameterMethodLocation.KEYWORD_ONLY
|
|
112
|
-
):
|
|
103
|
+
if self.in_overriden and super_method_location == ParameterMethodLocation.KEYWORD_ONLY:
|
|
113
104
|
return ParameterMethodLocation.KWARG
|
|
114
105
|
if self.location != ParameterLocation.PATH:
|
|
115
106
|
return ParameterMethodLocation.KEYWORD_ONLY
|