@autorest/python 6.4.15 → 6.5.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/models/credential_types.py +13 -3
- package/autorest/codegen/serializers/__init__.py +30 -6
- package/autorest/codegen/serializers/sample_serializer.py +21 -7
- package/autorest/codegen/serializers/utils.py +13 -0
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +1 -1
- package/autorest/m4reformatter/__init__.py +7 -0
- package/package.json +1 -1
|
@@ -73,19 +73,29 @@ class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
|
|
|
73
73
|
|
|
74
74
|
class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
75
75
|
def __init__(
|
|
76
|
-
self,
|
|
76
|
+
self,
|
|
77
|
+
yaml_data: Dict[str, Any],
|
|
78
|
+
code_model: "CodeModel",
|
|
79
|
+
key: str,
|
|
80
|
+
scheme: Optional[str] = None,
|
|
77
81
|
) -> None:
|
|
78
82
|
super().__init__(yaml_data, code_model)
|
|
79
83
|
self.key = key
|
|
84
|
+
self.scheme = scheme
|
|
80
85
|
|
|
81
86
|
def call(self, async_mode: bool) -> str:
|
|
82
|
-
|
|
87
|
+
params = f'"{self.key}", '
|
|
88
|
+
if self.scheme:
|
|
89
|
+
params += f'prefix="{self.scheme}", '
|
|
90
|
+
return f"policies.AzureKeyCredentialPolicy(self.credential, {params}**kwargs)"
|
|
83
91
|
|
|
84
92
|
@classmethod
|
|
85
93
|
def from_yaml(
|
|
86
94
|
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
87
95
|
) -> "AzureKeyCredentialPolicyType":
|
|
88
|
-
return cls(
|
|
96
|
+
return cls(
|
|
97
|
+
yaml_data, code_model, yaml_data["key"], yaml_data.get("scheme", None)
|
|
98
|
+
)
|
|
89
99
|
|
|
90
100
|
|
|
91
101
|
CredentialPolicyType = TypeVar(
|
|
@@ -29,7 +29,11 @@ from .patch_serializer import PatchSerializer
|
|
|
29
29
|
from .sample_serializer import SampleSerializer
|
|
30
30
|
from .types_serializer import TypesSerializer
|
|
31
31
|
from ..._utils import to_snake_case
|
|
32
|
-
from .utils import
|
|
32
|
+
from .utils import (
|
|
33
|
+
extract_sample_name,
|
|
34
|
+
get_namespace_from_package_name,
|
|
35
|
+
get_namespace_config,
|
|
36
|
+
)
|
|
33
37
|
|
|
34
38
|
_LOGGER = logging.getLogger(__name__)
|
|
35
39
|
|
|
@@ -547,18 +551,35 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
547
551
|
namespace_path / Path("_metadata.json"), metadata_serializer.serialize()
|
|
548
552
|
)
|
|
549
553
|
|
|
554
|
+
@property
|
|
555
|
+
def _namespace_from_package_name(self) -> str:
|
|
556
|
+
return get_namespace_from_package_name(self.code_model.options["package_name"])
|
|
557
|
+
|
|
550
558
|
def _name_space(self) -> str:
|
|
551
|
-
if self.code_model.namespace.count(
|
|
552
|
-
|
|
553
|
-
).count("
|
|
559
|
+
if self.code_model.namespace.count(
|
|
560
|
+
"."
|
|
561
|
+
) >= self._namespace_from_package_name.count("."):
|
|
554
562
|
return self.code_model.namespace
|
|
555
563
|
|
|
556
|
-
return self.
|
|
564
|
+
return self._namespace_from_package_name
|
|
557
565
|
|
|
558
566
|
# find root folder where "setup.py" is
|
|
559
567
|
def _package_root_folder(self, namespace_path: Path) -> Path:
|
|
560
568
|
return namespace_path / Path("../" * (self._name_space().count(".") + 1))
|
|
561
569
|
|
|
570
|
+
@property
|
|
571
|
+
def _additional_folder(self) -> Path:
|
|
572
|
+
namespace_config = get_namespace_config(
|
|
573
|
+
self.code_model.namespace, self.code_model.options["multiapi"]
|
|
574
|
+
)
|
|
575
|
+
num_of_namespace = namespace_config.count(".") + 1
|
|
576
|
+
num_of_package_namespace = self._namespace_from_package_name.count(".") + 1
|
|
577
|
+
if num_of_namespace > num_of_package_namespace:
|
|
578
|
+
return Path(
|
|
579
|
+
"/".join(namespace_config.split(".")[num_of_package_namespace:])
|
|
580
|
+
)
|
|
581
|
+
return Path("")
|
|
582
|
+
|
|
562
583
|
def _serialize_and_write_sample(self, env: Environment, namespace_path: Path):
|
|
563
584
|
out_path = self._package_root_folder(namespace_path) / Path("generated_samples")
|
|
564
585
|
for client in self.code_model.clients:
|
|
@@ -578,7 +599,10 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
578
599
|
file_name = to_snake_case(extract_sample_name(file)) + ".py"
|
|
579
600
|
try:
|
|
580
601
|
self.write_file(
|
|
581
|
-
out_path
|
|
602
|
+
out_path
|
|
603
|
+
/ self._additional_folder
|
|
604
|
+
/ _sample_output_path(file)
|
|
605
|
+
/ file_name,
|
|
582
606
|
SampleSerializer(
|
|
583
607
|
code_model=self.code_model,
|
|
584
608
|
env=env,
|
|
@@ -16,6 +16,8 @@ from autorest.codegen.models.operation_group import OperationGroup
|
|
|
16
16
|
from autorest.codegen.models.parameter import Parameter, BodyParameter
|
|
17
17
|
from autorest.codegen.serializers.import_serializer import FileImportSerializer
|
|
18
18
|
from ..models import CodeModel
|
|
19
|
+
from .utils import get_namespace_config, get_namespace_from_package_name
|
|
20
|
+
from ..._utils import to_snake_case
|
|
19
21
|
|
|
20
22
|
_LOGGER = logging.getLogger(__name__)
|
|
21
23
|
|
|
@@ -36,12 +38,24 @@ class SampleSerializer:
|
|
|
36
38
|
self.operation = operation
|
|
37
39
|
self.sample = sample
|
|
38
40
|
self.file_name = file_name
|
|
41
|
+
self.sample_params = {
|
|
42
|
+
to_snake_case(k): v for k, v in sample.get("parameters", {}).items()
|
|
43
|
+
}
|
|
39
44
|
|
|
40
45
|
def _imports(self) -> FileImportSerializer:
|
|
41
46
|
imports = FileImport()
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
)
|
|
47
|
+
namespace_from_package_name = get_namespace_from_package_name(
|
|
48
|
+
self.code_model.options["package_name"]
|
|
49
|
+
)
|
|
50
|
+
namespace_config = get_namespace_config(
|
|
51
|
+
self.code_model.namespace, self.code_model.options["multiapi"]
|
|
52
|
+
)
|
|
53
|
+
namespace = namespace_from_package_name or namespace_config
|
|
54
|
+
# mainly for "azure-mgmt-rdbms"
|
|
55
|
+
if not self.code_model.options["multiapi"] and namespace_config.count(
|
|
56
|
+
"."
|
|
57
|
+
) > namespace_from_package_name.count("."):
|
|
58
|
+
namespace = namespace_config
|
|
45
59
|
client = self.code_model.clients[0]
|
|
46
60
|
imports.add_submodule_import(namespace, client.name, ImportType.THIRDPARTY)
|
|
47
61
|
credential_type = getattr(client.credential, "type", None)
|
|
@@ -58,7 +72,7 @@ class SampleSerializer:
|
|
|
58
72
|
if (
|
|
59
73
|
not param.client_default_value
|
|
60
74
|
and not param.optional
|
|
61
|
-
and param.
|
|
75
|
+
and param.client_name in self.sample_params
|
|
62
76
|
):
|
|
63
77
|
imports.merge(param.type.imports_for_sample())
|
|
64
78
|
return FileImportSerializer(imports, True)
|
|
@@ -82,7 +96,7 @@ class SampleSerializer:
|
|
|
82
96
|
client_params = {
|
|
83
97
|
p.client_name: special_param.get(
|
|
84
98
|
p.client_name,
|
|
85
|
-
f'"{self.
|
|
99
|
+
f'"{self.sample_params.get(p.client_name) or p.client_name.upper()}"',
|
|
86
100
|
)
|
|
87
101
|
for p in params_positional
|
|
88
102
|
}
|
|
@@ -107,8 +121,8 @@ class SampleSerializer:
|
|
|
107
121
|
failure_info = "fail to find required param named {}"
|
|
108
122
|
operation_params = {}
|
|
109
123
|
for param in params_positional:
|
|
110
|
-
name = param.
|
|
111
|
-
param_value = self.
|
|
124
|
+
name = param.client_name
|
|
125
|
+
param_value = self.sample_params.get(name)
|
|
112
126
|
if not param.optional:
|
|
113
127
|
if not param_value:
|
|
114
128
|
raise Exception(failure_info.format(name))
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Optional
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
|
|
8
9
|
|
|
@@ -17,3 +18,15 @@ def method_signature_and_response_type_annotation_template(
|
|
|
17
18
|
def extract_sample_name(file_path: str) -> str:
|
|
18
19
|
file = file_path.split("specification")[-1]
|
|
19
20
|
return Path(file).parts[-1].replace(".json", "")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def strip_end(namespace: str) -> str:
|
|
24
|
+
return ".".join(namespace.split(".")[:-1])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_namespace_config(namespace: str, multiapi: bool) -> str:
|
|
28
|
+
return strip_end(namespace) if multiapi else namespace
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_namespace_from_package_name(package_name: Optional[str]) -> str:
|
|
32
|
+
return (package_name or "").replace("-", ".")
|
|
@@ -128,6 +128,7 @@ def update_property(
|
|
|
128
128
|
op["language"]["default"]["name"].lstrip("_") # TODO: patching m4
|
|
129
129
|
for op in yaml_data.get("originalParameter", [])
|
|
130
130
|
],
|
|
131
|
+
"clientDefaultValue": yaml_data.get("clientDefaultValue"),
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
|
|
@@ -498,6 +499,9 @@ class M4Reformatter(
|
|
|
498
499
|
overload = self.update_overload(
|
|
499
500
|
group_name, yaml_data, body_type, content_types=content_types
|
|
500
501
|
)
|
|
502
|
+
overload["internal"] = yaml_data.get("extensions", {}).get(
|
|
503
|
+
"x-ms-internal", False
|
|
504
|
+
)
|
|
501
505
|
for parameter in overload["parameters"]:
|
|
502
506
|
if parameter["wireName"].lower() == "content-type":
|
|
503
507
|
parameter["clientDefaultValue"] = overload["bodyParameter"][
|
|
@@ -579,6 +583,9 @@ class M4Reformatter(
|
|
|
579
583
|
)
|
|
580
584
|
content_types = None
|
|
581
585
|
operation = self._update_operation_helper(group_name, yaml_data, body_parameter)
|
|
586
|
+
operation["internal"] = yaml_data.get("extensions", {}).get(
|
|
587
|
+
"x-ms-internal", False
|
|
588
|
+
)
|
|
582
589
|
operation["overloads"] = self.update_overloads(
|
|
583
590
|
group_name, yaml_data, body_parameter, content_types=content_types
|
|
584
591
|
)
|