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