@autorest/python 6.2.0 → 6.2.1
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/codegen/__init__.py +9 -74
- package/autorest/codegen/models/__init__.py +11 -12
- package/autorest/codegen/models/{base_type.py → base.py} +29 -10
- package/autorest/codegen/models/base_builder.py +8 -10
- package/autorest/codegen/models/client.py +111 -40
- package/autorest/codegen/models/code_model.py +131 -90
- package/autorest/codegen/models/combined_type.py +7 -7
- package/autorest/codegen/models/constant_type.py +44 -10
- package/autorest/codegen/models/credential_types.py +17 -19
- package/autorest/codegen/models/dictionary_type.py +7 -9
- package/autorest/codegen/models/enum_type.py +19 -24
- package/autorest/codegen/models/imports.py +82 -33
- package/autorest/codegen/models/list_type.py +11 -15
- package/autorest/codegen/models/lro_operation.py +6 -10
- package/autorest/codegen/models/model_type.py +20 -21
- package/autorest/codegen/models/operation.py +49 -42
- package/autorest/codegen/models/operation_group.py +11 -11
- package/autorest/codegen/models/paging_operation.py +8 -10
- package/autorest/codegen/models/parameter.py +44 -31
- package/autorest/codegen/models/parameter_list.py +16 -22
- package/autorest/codegen/models/primitive_types.py +12 -23
- package/autorest/codegen/models/property.py +11 -11
- package/autorest/codegen/models/request_builder.py +19 -19
- package/autorest/codegen/models/request_builder_parameter.py +14 -16
- package/autorest/codegen/models/response.py +24 -28
- package/autorest/codegen/serializers/__init__.py +202 -187
- package/autorest/codegen/serializers/builder_serializer.py +46 -49
- package/autorest/codegen/serializers/client_serializer.py +9 -7
- package/autorest/codegen/serializers/enum_serializer.py +4 -4
- package/autorest/codegen/serializers/general_serializer.py +26 -36
- package/autorest/codegen/serializers/import_serializer.py +30 -36
- package/autorest/codegen/serializers/metadata_serializer.py +35 -17
- package/autorest/codegen/serializers/model_init_serializer.py +6 -10
- package/autorest/codegen/serializers/model_serializer.py +42 -27
- package/autorest/codegen/serializers/operation_groups_serializer.py +12 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +13 -6
- package/autorest/codegen/serializers/patch_serializer.py +4 -4
- package/autorest/codegen/serializers/request_builders_serializer.py +6 -6
- package/autorest/codegen/serializers/sample_serializer.py +10 -12
- package/autorest/codegen/templates/client_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/config.py.jinja2 +1 -1
- package/autorest/codegen/templates/config_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/enum_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/init.py.jinja2 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
- package/autorest/codegen/templates/model_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -3
- package/autorest/codegen/templates/operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -3
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +4 -1
- package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
- package/autorest/codegen/templates/rest_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/sample.py.jinja2 +5 -5
- package/autorest/codegen/templates/validation.py.jinja2 +1 -1
- package/autorest/codegen/templates/vendor.py.jinja2 +6 -6
- package/autorest/codegen/templates/version.py.jinja2 +2 -2
- package/autorest/m4reformatter/__init__.py +7 -6
- package/autorest/multiapi/models/imports.py +89 -18
- package/autorest/multiapi/serializers/import_serializer.py +88 -7
- package/autorest/multiapi/utils.py +6 -0
- package/autorest/preprocess/__init__.py +23 -26
- package/package.json +1 -1
- package/run_cadl.py +0 -1
- package/autorest/cadlflags/__init__.py +0 -130
- package/autorest/codegen/models/base_model.py +0 -30
|
@@ -39,7 +39,7 @@ from .model_type import ModelType
|
|
|
39
39
|
from .request_builder import OverloadedRequestBuilder, RequestBuilder
|
|
40
40
|
|
|
41
41
|
if TYPE_CHECKING:
|
|
42
|
-
from .code_model import
|
|
42
|
+
from .code_model import CodeModel
|
|
43
43
|
from .client import Client
|
|
44
44
|
|
|
45
45
|
ResponseType = TypeVar(
|
|
@@ -54,7 +54,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
54
54
|
def __init__(
|
|
55
55
|
self,
|
|
56
56
|
yaml_data: Dict[str, Any],
|
|
57
|
-
|
|
57
|
+
code_model: "CodeModel",
|
|
58
58
|
client: "Client",
|
|
59
59
|
name: str,
|
|
60
60
|
request_builder: Union[RequestBuilder, OverloadedRequestBuilder],
|
|
@@ -67,7 +67,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
67
67
|
want_tracing: bool = True,
|
|
68
68
|
) -> None:
|
|
69
69
|
super().__init__(
|
|
70
|
-
|
|
70
|
+
code_model=code_model,
|
|
71
71
|
client=client,
|
|
72
72
|
yaml_data=yaml_data,
|
|
73
73
|
name=name,
|
|
@@ -98,7 +98,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
98
98
|
|
|
99
99
|
def response_type_annotation(self, **kwargs) -> str:
|
|
100
100
|
if (
|
|
101
|
-
self.
|
|
101
|
+
self.code_model.options["head_as_boolean"]
|
|
102
102
|
and self.request_builder.method.lower() == "head"
|
|
103
103
|
):
|
|
104
104
|
return "bool"
|
|
@@ -127,7 +127,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
127
127
|
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
128
128
|
if (
|
|
129
129
|
self.request_builder.method.lower() == "head"
|
|
130
|
-
and self.
|
|
130
|
+
and self.code_model.options["head_as_boolean"]
|
|
131
131
|
):
|
|
132
132
|
return "ClsType[None]"
|
|
133
133
|
return f"ClsType[{self.response_type_annotation(async_mode=async_mode)}]"
|
|
@@ -136,7 +136,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
136
136
|
responses_with_body = [r for r in self.responses if r.type]
|
|
137
137
|
if (
|
|
138
138
|
self.request_builder.method.lower() == "head"
|
|
139
|
-
and self.
|
|
139
|
+
and self.code_model.options["head_as_boolean"]
|
|
140
140
|
):
|
|
141
141
|
return "bool"
|
|
142
142
|
if responses_with_body:
|
|
@@ -154,9 +154,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
154
154
|
|
|
155
155
|
def response_docstring_text(self, **kwargs) -> str:
|
|
156
156
|
retval = self._response_docstring_helper("docstring_text", **kwargs)
|
|
157
|
-
if not self.
|
|
157
|
+
if not self.code_model.options["version_tolerant"]:
|
|
158
158
|
retval += " or the result of cls(response)"
|
|
159
|
-
if self.
|
|
159
|
+
if self.code_model.options["models_mode"] == "dpg" and any(
|
|
160
160
|
isinstance(r.type, ModelType) for r in self.responses
|
|
161
161
|
):
|
|
162
162
|
r = next(r for r in self.responses if isinstance(r.type, ModelType))
|
|
@@ -204,13 +204,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
204
204
|
)
|
|
205
205
|
)
|
|
206
206
|
|
|
207
|
-
def _imports_shared(
|
|
207
|
+
def _imports_shared(
|
|
208
|
+
self, async_mode: bool, **kwargs: Any # pylint: disable=unused-argument
|
|
209
|
+
) -> FileImport:
|
|
208
210
|
file_import = FileImport()
|
|
209
211
|
file_import.add_submodule_import(
|
|
210
212
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
211
213
|
)
|
|
212
|
-
for param in self.parameters.method:
|
|
213
|
-
file_import.merge(param.imports(async_mode, **kwargs))
|
|
214
214
|
|
|
215
215
|
response_types = [
|
|
216
216
|
r.type_annotation(async_mode=async_mode) for r in self.responses if r.type
|
|
@@ -231,11 +231,18 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
231
231
|
if self.abstract:
|
|
232
232
|
return FileImport()
|
|
233
233
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
234
|
+
for param in self.parameters.method:
|
|
235
|
+
file_import.merge(
|
|
236
|
+
param.imports_for_multiapi(
|
|
237
|
+
async_mode,
|
|
238
|
+
**kwargs,
|
|
239
|
+
)
|
|
240
|
+
)
|
|
234
241
|
for response in self.responses:
|
|
235
242
|
file_import.merge(
|
|
236
243
|
response.imports_for_multiapi(async_mode=async_mode, **kwargs)
|
|
237
244
|
)
|
|
238
|
-
if self.
|
|
245
|
+
if self.code_model.options["models_mode"]:
|
|
239
246
|
for exception in self.exceptions:
|
|
240
247
|
file_import.merge(
|
|
241
248
|
exception.imports_for_multiapi(async_mode=async_mode, **kwargs)
|
|
@@ -272,12 +279,12 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
272
279
|
) -> FileImport:
|
|
273
280
|
"""Helper method to get a request builder import."""
|
|
274
281
|
file_import = FileImport()
|
|
275
|
-
if self.
|
|
282
|
+
if self.code_model.options["builders_visibility"] != "embedded":
|
|
276
283
|
group_name = request_builder.group_name
|
|
277
284
|
rest_import_path = "..." if async_mode else ".."
|
|
278
285
|
if group_name:
|
|
279
286
|
file_import.add_submodule_import(
|
|
280
|
-
f"{rest_import_path}{self.
|
|
287
|
+
f"{rest_import_path}{self.code_model.rest_layer_name}",
|
|
281
288
|
group_name,
|
|
282
289
|
import_type=ImportType.LOCAL,
|
|
283
290
|
alias=f"rest_{group_name}",
|
|
@@ -285,16 +292,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
285
292
|
else:
|
|
286
293
|
file_import.add_submodule_import(
|
|
287
294
|
rest_import_path,
|
|
288
|
-
self.
|
|
295
|
+
self.code_model.rest_layer_name,
|
|
289
296
|
import_type=ImportType.LOCAL,
|
|
290
297
|
alias="rest",
|
|
291
298
|
)
|
|
292
|
-
if
|
|
293
|
-
self.namespace_model.options["builders_visibility"] == "embedded"
|
|
294
|
-
and async_mode
|
|
295
|
-
):
|
|
299
|
+
if self.code_model.options["builders_visibility"] == "embedded" and async_mode:
|
|
296
300
|
file_import.add_submodule_import(
|
|
297
|
-
f"...{self.
|
|
301
|
+
f"...{self.code_model.operations_folder_name}.{self.filename}",
|
|
298
302
|
request_builder.name,
|
|
299
303
|
import_type=ImportType.LOCAL,
|
|
300
304
|
)
|
|
@@ -305,9 +309,16 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
305
309
|
return FileImport()
|
|
306
310
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
307
311
|
|
|
312
|
+
for param in self.parameters.method:
|
|
313
|
+
file_import.merge(
|
|
314
|
+
param.imports(
|
|
315
|
+
async_mode,
|
|
316
|
+
**kwargs,
|
|
317
|
+
)
|
|
318
|
+
)
|
|
308
319
|
for response in self.responses:
|
|
309
320
|
file_import.merge(response.imports(async_mode=async_mode, **kwargs))
|
|
310
|
-
if self.
|
|
321
|
+
if self.code_model.options["models_mode"]:
|
|
311
322
|
for exception in self.exceptions:
|
|
312
323
|
file_import.merge(exception.imports(async_mode=async_mode, **kwargs))
|
|
313
324
|
|
|
@@ -327,7 +338,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
327
338
|
file_import.add_submodule_import(
|
|
328
339
|
"azure.core.exceptions", error, ImportType.AZURECORE
|
|
329
340
|
)
|
|
330
|
-
if self.
|
|
341
|
+
if self.code_model.options["azure_arm"]:
|
|
331
342
|
file_import.add_submodule_import(
|
|
332
343
|
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE
|
|
333
344
|
)
|
|
@@ -343,7 +354,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
343
354
|
if self.deprecated:
|
|
344
355
|
file_import.add_import("warnings", ImportType.STDLIB)
|
|
345
356
|
|
|
346
|
-
if self.
|
|
357
|
+
if self.code_model.need_request_converter:
|
|
347
358
|
relative_path = "..." if async_mode else ".."
|
|
348
359
|
file_import.add_submodule_import(
|
|
349
360
|
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
@@ -359,7 +370,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
359
370
|
"azure.core.pipeline.transport", "HttpResponse", ImportType.AZURECORE
|
|
360
371
|
)
|
|
361
372
|
if (
|
|
362
|
-
self.
|
|
373
|
+
self.code_model.options["builders_visibility"] == "embedded"
|
|
363
374
|
and not async_mode
|
|
364
375
|
):
|
|
365
376
|
file_import.merge(self.request_builder.imports())
|
|
@@ -381,11 +392,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
381
392
|
file_import.add_submodule_import(
|
|
382
393
|
"typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
383
394
|
)
|
|
384
|
-
if
|
|
385
|
-
self.namespace_model.options["tracing"]
|
|
386
|
-
and self.want_tracing
|
|
387
|
-
and not async_mode
|
|
388
|
-
):
|
|
395
|
+
if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
|
|
389
396
|
file_import.add_submodule_import(
|
|
390
397
|
f"azure.core.tracing.decorator",
|
|
391
398
|
f"distributed_trace",
|
|
@@ -418,11 +425,11 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
418
425
|
basename = self.group_name
|
|
419
426
|
if basename == "":
|
|
420
427
|
# in a mixin
|
|
421
|
-
basename = self.
|
|
428
|
+
basename = self.code_model.clients[0].legacy_filename
|
|
422
429
|
|
|
423
430
|
if (
|
|
424
431
|
basename == "operations"
|
|
425
|
-
or self.
|
|
432
|
+
or self.code_model.options["combine_operation_files"]
|
|
426
433
|
):
|
|
427
434
|
return f"_operations"
|
|
428
435
|
return f"_{basename}_operations"
|
|
@@ -435,27 +442,27 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
435
442
|
def from_yaml(
|
|
436
443
|
cls,
|
|
437
444
|
yaml_data: Dict[str, Any],
|
|
438
|
-
|
|
445
|
+
code_model: "CodeModel",
|
|
439
446
|
client: "Client",
|
|
440
447
|
):
|
|
441
448
|
name = yaml_data["name"]
|
|
442
|
-
request_builder =
|
|
449
|
+
request_builder = client.lookup_request_builder(id(yaml_data))
|
|
443
450
|
responses = [
|
|
444
|
-
cast(ResponseType, get_response(r,
|
|
451
|
+
cast(ResponseType, get_response(r, code_model))
|
|
445
452
|
for r in yaml_data["responses"]
|
|
446
453
|
]
|
|
447
454
|
exceptions = [
|
|
448
|
-
Response.from_yaml(e,
|
|
455
|
+
Response.from_yaml(e, code_model) for e in yaml_data["exceptions"]
|
|
449
456
|
]
|
|
450
|
-
parameter_list = ParameterList.from_yaml(yaml_data,
|
|
457
|
+
parameter_list = ParameterList.from_yaml(yaml_data, code_model)
|
|
451
458
|
overloads = [
|
|
452
|
-
cls.from_yaml(overload,
|
|
459
|
+
cls.from_yaml(overload, code_model, client)
|
|
453
460
|
for overload in yaml_data.get("overloads", [])
|
|
454
461
|
]
|
|
455
462
|
|
|
456
463
|
return cls(
|
|
457
464
|
yaml_data=yaml_data,
|
|
458
|
-
|
|
465
|
+
code_model=code_model,
|
|
459
466
|
client=client,
|
|
460
467
|
request_builder=request_builder,
|
|
461
468
|
name=name,
|
|
@@ -481,10 +488,10 @@ class Operation(OperationBase[Response]):
|
|
|
481
488
|
if (
|
|
482
489
|
self.has_response_body
|
|
483
490
|
and not self.has_optional_return_type
|
|
484
|
-
and not self.
|
|
491
|
+
and not self.code_model.options["models_mode"]
|
|
485
492
|
):
|
|
486
493
|
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
487
|
-
if self.
|
|
494
|
+
if self.code_model.options["models_mode"] == "dpg":
|
|
488
495
|
relative_path = "..." if async_mode else ".."
|
|
489
496
|
if self.parameters.has_body:
|
|
490
497
|
file_import.add_submodule_import(
|
|
@@ -502,7 +509,7 @@ class Operation(OperationBase[Response]):
|
|
|
502
509
|
|
|
503
510
|
|
|
504
511
|
def get_operation(
|
|
505
|
-
yaml_data: Dict[str, Any],
|
|
512
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
506
513
|
) -> OperationBase:
|
|
507
514
|
if yaml_data["discriminator"] == "lropaging":
|
|
508
515
|
from .lro_paging_operation import LROPagingOperation as OperationCls
|
|
@@ -512,4 +519,4 @@ def get_operation(
|
|
|
512
519
|
from .paging_operation import PagingOperation as OperationCls # type: ignore
|
|
513
520
|
else:
|
|
514
521
|
from . import Operation as OperationCls # type: ignore
|
|
515
|
-
return OperationCls.from_yaml(yaml_data,
|
|
522
|
+
return OperationCls.from_yaml(yaml_data, code_model, client)
|
|
@@ -7,13 +7,13 @@ from typing import Dict, List, Any, TYPE_CHECKING
|
|
|
7
7
|
|
|
8
8
|
from autorest.codegen.models.utils import OrderedSet
|
|
9
9
|
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseModel
|
|
11
11
|
from .operation import OperationBase, get_operation
|
|
12
12
|
from .imports import FileImport, ImportType, TypingSection
|
|
13
13
|
from .utils import add_to_pylint_disable
|
|
14
14
|
|
|
15
15
|
if TYPE_CHECKING:
|
|
16
|
-
from .code_model import
|
|
16
|
+
from .code_model import CodeModel
|
|
17
17
|
from .client import Client
|
|
18
18
|
|
|
19
19
|
|
|
@@ -23,12 +23,12 @@ class OperationGroup(BaseModel):
|
|
|
23
23
|
def __init__(
|
|
24
24
|
self,
|
|
25
25
|
yaml_data: Dict[str, Any],
|
|
26
|
-
|
|
26
|
+
code_model: "CodeModel",
|
|
27
27
|
client: "Client",
|
|
28
28
|
operations: List[OperationBase],
|
|
29
29
|
api_versions: List[str],
|
|
30
30
|
) -> None:
|
|
31
|
-
super().__init__(yaml_data,
|
|
31
|
+
super().__init__(yaml_data, code_model)
|
|
32
32
|
self.client = client
|
|
33
33
|
self.class_name: str = yaml_data["className"]
|
|
34
34
|
self.property_name: str = yaml_data["propertyName"]
|
|
@@ -42,7 +42,7 @@ class OperationGroup(BaseModel):
|
|
|
42
42
|
@property
|
|
43
43
|
def base_class(self) -> str:
|
|
44
44
|
base_classes: List[str] = []
|
|
45
|
-
if self.is_mixin and self.
|
|
45
|
+
if self.is_mixin and self.code_model.need_mixin_abc:
|
|
46
46
|
base_classes.append(f"{self.client.name}MixinABC")
|
|
47
47
|
return ", ".join(base_classes)
|
|
48
48
|
|
|
@@ -84,12 +84,12 @@ class OperationGroup(BaseModel):
|
|
|
84
84
|
)
|
|
85
85
|
# for multiapi
|
|
86
86
|
if (
|
|
87
|
-
self.
|
|
88
|
-
) and self.
|
|
87
|
+
self.code_model.model_types or self.code_model.enums
|
|
88
|
+
) and self.code_model.options["models_mode"] == "msrest":
|
|
89
89
|
file_import.add_submodule_import(
|
|
90
90
|
relative_path, "models", ImportType.LOCAL, alias="_models"
|
|
91
91
|
)
|
|
92
|
-
if self.
|
|
92
|
+
if self.code_model.need_mixin_abc:
|
|
93
93
|
file_import.add_submodule_import(
|
|
94
94
|
".._vendor", f"{self.client.name}MixinABC", ImportType.LOCAL
|
|
95
95
|
)
|
|
@@ -122,11 +122,11 @@ class OperationGroup(BaseModel):
|
|
|
122
122
|
def from_yaml(
|
|
123
123
|
cls,
|
|
124
124
|
yaml_data: Dict[str, Any],
|
|
125
|
-
|
|
125
|
+
code_model: "CodeModel",
|
|
126
126
|
client: "Client",
|
|
127
127
|
) -> "OperationGroup":
|
|
128
128
|
operations = [
|
|
129
|
-
get_operation(o,
|
|
129
|
+
get_operation(o, code_model, client) for o in yaml_data["operations"]
|
|
130
130
|
]
|
|
131
131
|
api_versions: OrderedSet[str] = {}
|
|
132
132
|
for operation in operations:
|
|
@@ -134,7 +134,7 @@ class OperationGroup(BaseModel):
|
|
|
134
134
|
api_versions[api_version] = None
|
|
135
135
|
return cls(
|
|
136
136
|
yaml_data=yaml_data,
|
|
137
|
-
|
|
137
|
+
code_model=code_model,
|
|
138
138
|
client=client,
|
|
139
139
|
operations=operations,
|
|
140
140
|
api_versions=list(api_versions.keys()),
|
|
@@ -17,7 +17,7 @@ from .parameter_list import ParameterList
|
|
|
17
17
|
from .model_type import ModelType
|
|
18
18
|
|
|
19
19
|
if TYPE_CHECKING:
|
|
20
|
-
from .code_model import
|
|
20
|
+
from .code_model import CodeModel
|
|
21
21
|
from .client import Client
|
|
22
22
|
|
|
23
23
|
PagingResponseType = TypeVar(
|
|
@@ -29,7 +29,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
29
29
|
def __init__(
|
|
30
30
|
self,
|
|
31
31
|
yaml_data: Dict[str, Any],
|
|
32
|
-
|
|
32
|
+
code_model: "CodeModel",
|
|
33
33
|
client: "Client",
|
|
34
34
|
name: str,
|
|
35
35
|
request_builder: RequestBuilder,
|
|
@@ -43,7 +43,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
43
43
|
override_success_response_to_200: bool = False,
|
|
44
44
|
) -> None:
|
|
45
45
|
super().__init__(
|
|
46
|
-
|
|
46
|
+
code_model=code_model,
|
|
47
47
|
client=client,
|
|
48
48
|
yaml_data=yaml_data,
|
|
49
49
|
name=name,
|
|
@@ -58,9 +58,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
58
58
|
self.next_request_builder: Optional[
|
|
59
59
|
Union[RequestBuilder, OverloadedRequestBuilder]
|
|
60
60
|
] = (
|
|
61
|
-
get_request_builder(
|
|
62
|
-
self.yaml_data["nextOperation"], namespace_model, client
|
|
63
|
-
)
|
|
61
|
+
get_request_builder(self.yaml_data["nextOperation"], code_model, client)
|
|
64
62
|
if self.yaml_data.get("nextOperation")
|
|
65
63
|
else None
|
|
66
64
|
)
|
|
@@ -90,14 +88,14 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
90
88
|
if not rest_api_name:
|
|
91
89
|
# That's an ok scenario, it just means no next page possible
|
|
92
90
|
return None
|
|
93
|
-
if self.
|
|
91
|
+
if self.code_model.options["models_mode"]:
|
|
94
92
|
return self._get_attr_name(rest_api_name)
|
|
95
93
|
return rest_api_name
|
|
96
94
|
|
|
97
95
|
@property
|
|
98
96
|
def item_name(self) -> str:
|
|
99
97
|
rest_api_name = self.yaml_data["itemName"]
|
|
100
|
-
if self.
|
|
98
|
+
if self.code_model.options["models_mode"]:
|
|
101
99
|
return self._get_attr_name(rest_api_name)
|
|
102
100
|
return rest_api_name
|
|
103
101
|
|
|
@@ -120,7 +118,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
120
118
|
)
|
|
121
119
|
if (
|
|
122
120
|
self.next_request_builder
|
|
123
|
-
and self.
|
|
121
|
+
and self.code_model.options["builders_visibility"] == "embedded"
|
|
124
122
|
and not async_mode
|
|
125
123
|
):
|
|
126
124
|
file_import.merge(self.next_request_builder.imports())
|
|
@@ -135,7 +133,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
135
133
|
return FileImport()
|
|
136
134
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
137
135
|
file_import.merge(super().imports(async_mode, **kwargs))
|
|
138
|
-
if self.
|
|
136
|
+
if self.code_model.options["tracing"] and self.want_tracing:
|
|
139
137
|
file_import.add_submodule_import(
|
|
140
138
|
"azure.core.tracing.decorator",
|
|
141
139
|
"distributed_trace",
|
|
@@ -19,15 +19,15 @@ from typing import (
|
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
from .imports import FileImport, ImportType
|
|
22
|
-
from .
|
|
23
|
-
from .
|
|
22
|
+
from .base import BaseModel
|
|
23
|
+
from .base import BaseType
|
|
24
24
|
from .constant_type import ConstantType
|
|
25
25
|
from .model_type import ModelType
|
|
26
26
|
from .combined_type import CombinedType
|
|
27
27
|
from .utils import add_to_description
|
|
28
28
|
|
|
29
29
|
if TYPE_CHECKING:
|
|
30
|
-
from .code_model import
|
|
30
|
+
from .code_model import CodeModel
|
|
31
31
|
from .request_builder_parameter import RequestBuilderBodyParameter
|
|
32
32
|
|
|
33
33
|
|
|
@@ -61,10 +61,10 @@ class _ParameterBase(
|
|
|
61
61
|
def __init__(
|
|
62
62
|
self,
|
|
63
63
|
yaml_data: Dict[str, Any],
|
|
64
|
-
|
|
64
|
+
code_model: "CodeModel",
|
|
65
65
|
type: BaseType,
|
|
66
66
|
) -> None:
|
|
67
|
-
super().__init__(yaml_data,
|
|
67
|
+
super().__init__(yaml_data, code_model)
|
|
68
68
|
self.rest_api_name: str = yaml_data["restApiName"]
|
|
69
69
|
self.client_name: str = self.yaml_data["clientName"]
|
|
70
70
|
self.optional: bool = self.yaml_data["optional"]
|
|
@@ -149,11 +149,8 @@ class _ParameterBase(
|
|
|
149
149
|
def serialization_type(self) -> str:
|
|
150
150
|
return self.type.serialization_type
|
|
151
151
|
|
|
152
|
-
def
|
|
152
|
+
def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
|
|
153
153
|
file_import = FileImport()
|
|
154
|
-
file_import.merge(
|
|
155
|
-
self.type.imports(is_operation_file=True, async_mode=async_mode, **kwargs)
|
|
156
|
-
)
|
|
157
154
|
if self.optional and self.client_default_value is None:
|
|
158
155
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
159
156
|
if self.added_on:
|
|
@@ -164,6 +161,22 @@ class _ParameterBase(
|
|
|
164
161
|
)
|
|
165
162
|
return file_import
|
|
166
163
|
|
|
164
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
165
|
+
file_import = self._imports_shared(async_mode, **kwargs)
|
|
166
|
+
file_import.merge(
|
|
167
|
+
self.type.imports(is_operation_file=True, async_mode=async_mode, **kwargs)
|
|
168
|
+
)
|
|
169
|
+
return file_import
|
|
170
|
+
|
|
171
|
+
def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
172
|
+
file_import = self._imports_shared(async_mode, **kwargs)
|
|
173
|
+
file_import.merge(
|
|
174
|
+
self.type.imports_for_multiapi(
|
|
175
|
+
is_operation_file=True, async_mode=async_mode, **kwargs
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
return file_import
|
|
179
|
+
|
|
167
180
|
@property
|
|
168
181
|
def method_location(self) -> ParameterMethodLocation:
|
|
169
182
|
raise NotImplementedError("Please implement in children")
|
|
@@ -230,18 +243,18 @@ class BodyParameter(_BodyParameterBase):
|
|
|
230
243
|
|
|
231
244
|
@classmethod
|
|
232
245
|
def from_yaml(
|
|
233
|
-
cls, yaml_data: Dict[str, Any],
|
|
246
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
234
247
|
) -> "BodyParameter":
|
|
235
248
|
return cls(
|
|
236
249
|
yaml_data=yaml_data,
|
|
237
|
-
|
|
238
|
-
type=
|
|
250
|
+
code_model=code_model,
|
|
251
|
+
type=code_model.lookup_type(id(yaml_data["type"])),
|
|
239
252
|
)
|
|
240
253
|
|
|
241
254
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
242
255
|
annotation = super().type_annotation(**kwargs)
|
|
243
256
|
model_seq = BodyParameter.get_model_seq(self.type)
|
|
244
|
-
if self.
|
|
257
|
+
if self.code_model.options["models_mode"] == "dpg" and model_seq >= 0:
|
|
245
258
|
pattern = re.compile(r"Union\[.*\]")
|
|
246
259
|
union_content = (
|
|
247
260
|
annotation[6:-1] if pattern.match(annotation) else annotation
|
|
@@ -254,7 +267,7 @@ class BodyParameter(_BodyParameterBase):
|
|
|
254
267
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
255
268
|
docstring = super().docstring_type(**kwargs)
|
|
256
269
|
model_seq = BodyParameter.get_model_seq(self.type)
|
|
257
|
-
if self.
|
|
270
|
+
if self.code_model.options["models_mode"] == "dpg" and model_seq >= 0:
|
|
258
271
|
items = docstring.split(" or ")
|
|
259
272
|
items.insert(model_seq + 1, "JSON")
|
|
260
273
|
docstring = " or ".join(items)
|
|
@@ -284,11 +297,11 @@ class _MultipartBodyParameter(Generic[EntryBodyParameterType], BodyParameter):
|
|
|
284
297
|
def __init__(
|
|
285
298
|
self,
|
|
286
299
|
yaml_data: Dict[str, Any],
|
|
287
|
-
|
|
300
|
+
code_model: "CodeModel",
|
|
288
301
|
type: BaseType,
|
|
289
302
|
entries: List[EntryBodyParameterType],
|
|
290
303
|
) -> None:
|
|
291
|
-
super().__init__(yaml_data,
|
|
304
|
+
super().__init__(yaml_data, code_model, type)
|
|
292
305
|
self.entries = entries
|
|
293
306
|
|
|
294
307
|
@property
|
|
@@ -305,14 +318,14 @@ class MultipartBodyParameter(
|
|
|
305
318
|
|
|
306
319
|
@classmethod
|
|
307
320
|
def from_yaml(
|
|
308
|
-
cls, yaml_data: Dict[str, Any],
|
|
321
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
309
322
|
) -> "MultipartBodyParameter":
|
|
310
323
|
return cls(
|
|
311
324
|
yaml_data=yaml_data,
|
|
312
|
-
|
|
313
|
-
type=
|
|
325
|
+
code_model=code_model,
|
|
326
|
+
type=code_model.lookup_type(id(yaml_data["type"])),
|
|
314
327
|
entries=[
|
|
315
|
-
BodyParameter.from_yaml(entry,
|
|
328
|
+
BodyParameter.from_yaml(entry, code_model)
|
|
316
329
|
for entry in yaml_data["entries"]
|
|
317
330
|
],
|
|
318
331
|
)
|
|
@@ -324,10 +337,10 @@ class Parameter(_ParameterBase):
|
|
|
324
337
|
def __init__(
|
|
325
338
|
self,
|
|
326
339
|
yaml_data: Dict[str, Any],
|
|
327
|
-
|
|
340
|
+
code_model: "CodeModel",
|
|
328
341
|
type: BaseType,
|
|
329
342
|
) -> None:
|
|
330
|
-
super().__init__(yaml_data,
|
|
343
|
+
super().__init__(yaml_data, code_model, type=type)
|
|
331
344
|
|
|
332
345
|
self.implementation: str = yaml_data["implementation"]
|
|
333
346
|
self.skip_url_encoding: bool = self.yaml_data.get("skipUrlEncoding", False)
|
|
@@ -371,18 +384,18 @@ class Parameter(_ParameterBase):
|
|
|
371
384
|
ParameterLocation.QUERY,
|
|
372
385
|
)
|
|
373
386
|
if (
|
|
374
|
-
self.
|
|
387
|
+
self.code_model.options["only_path_and_body_params_positional"]
|
|
375
388
|
and query_or_header
|
|
376
389
|
):
|
|
377
390
|
return ParameterMethodLocation.KEYWORD_ONLY
|
|
378
391
|
return ParameterMethodLocation.POSITIONAL
|
|
379
392
|
|
|
380
393
|
@classmethod
|
|
381
|
-
def from_yaml(cls, yaml_data: Dict[str, Any],
|
|
394
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel"):
|
|
382
395
|
return cls(
|
|
383
396
|
yaml_data=yaml_data,
|
|
384
|
-
|
|
385
|
-
type=
|
|
397
|
+
code_model=code_model,
|
|
398
|
+
type=code_model.lookup_type(id(yaml_data["type"])),
|
|
386
399
|
)
|
|
387
400
|
|
|
388
401
|
|
|
@@ -398,8 +411,8 @@ class ClientParameter(Parameter):
|
|
|
398
411
|
if self.constant:
|
|
399
412
|
return ParameterMethodLocation.KWARG
|
|
400
413
|
if self.is_host and (
|
|
401
|
-
self.
|
|
402
|
-
or self.
|
|
414
|
+
self.code_model.options["version_tolerant"]
|
|
415
|
+
or self.code_model.options["low_level_client"]
|
|
403
416
|
):
|
|
404
417
|
# this means i am the base url
|
|
405
418
|
return ParameterMethodLocation.KEYWORD_ONLY
|
|
@@ -425,9 +438,9 @@ class ConfigParameter(Parameter):
|
|
|
425
438
|
|
|
426
439
|
|
|
427
440
|
def get_body_parameter(
|
|
428
|
-
yaml_data: Dict[str, Any],
|
|
441
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
429
442
|
) -> Union[BodyParameter, MultipartBodyParameter]:
|
|
430
443
|
"""Creates a regular body parameter or Multipart body parameter"""
|
|
431
444
|
if yaml_data.get("entries"):
|
|
432
|
-
return MultipartBodyParameter.from_yaml(yaml_data,
|
|
433
|
-
return BodyParameter.from_yaml(yaml_data,
|
|
445
|
+
return MultipartBodyParameter.from_yaml(yaml_data, code_model)
|
|
446
|
+
return BodyParameter.from_yaml(yaml_data, code_model)
|