@autorest/python 6.2.12 → 6.2.15
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 +7 -5
- package/autorest/_utils.py +7 -1
- package/autorest/black/__init__.py +6 -1
- package/autorest/codegen/__init__.py +1 -1
- package/autorest/codegen/models/base.py +4 -13
- package/autorest/codegen/models/client.py +9 -11
- package/autorest/codegen/models/code_model.py +2 -2
- package/autorest/codegen/models/credential_types.py +7 -14
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/imports.py +3 -3
- package/autorest/codegen/models/lro_operation.py +5 -5
- package/autorest/codegen/models/model_type.py +11 -8
- package/autorest/codegen/models/operation.py +8 -8
- package/autorest/codegen/models/operation_group.py +3 -1
- package/autorest/codegen/models/paging_operation.py +2 -2
- package/autorest/codegen/models/parameter.py +27 -6
- package/autorest/codegen/models/parameter_list.py +1 -9
- package/autorest/codegen/models/primitive_types.py +1 -1
- package/autorest/codegen/models/property.py +15 -3
- package/autorest/codegen/models/response.py +2 -2
- package/autorest/codegen/serializers/__init__.py +2 -2
- package/autorest/codegen/serializers/builder_serializer.py +55 -25
- package/autorest/codegen/serializers/client_serializer.py +6 -4
- package/autorest/codegen/serializers/general_serializer.py +7 -2
- package/autorest/codegen/serializers/model_serializer.py +14 -4
- package/autorest/codegen/serializers/sample_serializer.py +2 -6
- package/autorest/codegen/templates/config.py.jinja2 +25 -6
- package/autorest/codegen/templates/enum.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +18 -9
- package/autorest/codegen/templates/model_base.py.jinja2 +74 -63
- package/autorest/codegen/templates/model_dpg.py.jinja2 +6 -4
- package/autorest/codegen/templates/serialization.py.jinja2 +17 -15
- package/autorest/codegen/templates/vendor.py.jinja2 +3 -2
- package/autorest/jsonrpc/localapi.py +3 -3
- package/autorest/jsonrpc/server.py +3 -3
- package/autorest/m2r/__init__.py +1 -1
- package/autorest/m4reformatter/__init__.py +12 -2
- package/autorest/multiapi/models/__init__.py +2 -0
- package/autorest/multiapi/models/code_model.py +13 -0
- package/autorest/multiapi/models/global_parameter.py +1 -0
- package/autorest/multiapi/models/imports.py +3 -3
- package/autorest/multiapi/serializers/__init__.py +30 -3
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +8 -12
- package/autorest/postprocess/get_all.py +3 -1
- package/autorest/postprocess/venvtools.py +5 -4
- package/autorest/preprocess/__init__.py +16 -4
- package/autorest/preprocess/python_mappings.py +1 -0
- package/index.js +0 -0
- package/package.json +2 -1
- package/requirements.txt +6 -6
- package/setup.py +0 -1
- package/venvtools.py +2 -3
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import Any, Optional, Union
|
|
7
|
+
from typing import Any, Optional, Union, List
|
|
8
8
|
from jinja2 import PackageLoader, Environment
|
|
9
9
|
|
|
10
10
|
from .import_serializer import FileImportSerializer
|
|
11
11
|
|
|
12
12
|
from ...jsonrpc import AutorestAPI
|
|
13
|
-
from ..models import CodeModel
|
|
13
|
+
from ..models import CodeModel, GlobalParameter
|
|
14
14
|
from ... import ReaderAndWriter, ReaderAndWriterAutorest
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
@@ -26,6 +26,15 @@ _FILE_TO_TEMPLATE = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
def _method_signature_helper(
|
|
30
|
+
parameters: List[GlobalParameter], async_mode: bool
|
|
31
|
+
) -> List[str]:
|
|
32
|
+
return [
|
|
33
|
+
p.signature(async_mode)
|
|
34
|
+
for p in sorted(parameters, key=lambda p: p.required, reverse=True)
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
29
38
|
def _get_file_path(filename: str, async_mode: bool) -> Path:
|
|
30
39
|
filename += ".py"
|
|
31
40
|
if async_mode:
|
|
@@ -48,8 +57,26 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
48
57
|
def _serialize_helper(self, code_model: CodeModel, async_mode: bool) -> None:
|
|
49
58
|
def _render_template(file: str, **kwargs: Any) -> str:
|
|
50
59
|
template = self.env.get_template(_FILE_TO_TEMPLATE[file])
|
|
60
|
+
all_params = (
|
|
61
|
+
code_model.global_parameters.parameters
|
|
62
|
+
+ code_model.global_parameters.service_client_specific_global_parameters
|
|
63
|
+
)
|
|
64
|
+
positional_params = [
|
|
65
|
+
p for p in all_params if p.method_location == "positional"
|
|
66
|
+
]
|
|
67
|
+
keyword_only_params = [
|
|
68
|
+
p for p in all_params if p.method_location == "keywordOnly"
|
|
69
|
+
]
|
|
51
70
|
return template.render(
|
|
52
|
-
code_model=code_model,
|
|
71
|
+
code_model=code_model,
|
|
72
|
+
async_mode=async_mode,
|
|
73
|
+
positional_params=_method_signature_helper(
|
|
74
|
+
positional_params, async_mode
|
|
75
|
+
),
|
|
76
|
+
keyword_only_params=_method_signature_helper(
|
|
77
|
+
keyword_only_params, async_mode
|
|
78
|
+
),
|
|
79
|
+
**kwargs
|
|
53
80
|
)
|
|
54
81
|
|
|
55
82
|
# serialize init file
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
{% macro method_signature() %}
|
|
2
2
|
def __init__(
|
|
3
3
|
self,
|
|
4
|
-
{% for
|
|
5
|
-
|
|
6
|
-
{{ parameter.signature(async_mode) }}
|
|
7
|
-
{% endif %}
|
|
8
|
-
{% endfor %}
|
|
9
|
-
{% for parameter in code_model.global_parameters.parameters %}
|
|
10
|
-
{% if not parameter.required %}
|
|
11
|
-
{{ parameter.signature(async_mode) }}
|
|
12
|
-
{% endif %}
|
|
4
|
+
{% for pos in positional_params %}
|
|
5
|
+
{{ pos }}
|
|
13
6
|
{% endfor %}
|
|
14
|
-
{%
|
|
15
|
-
|
|
7
|
+
{% if keyword_only_params %}
|
|
8
|
+
*,
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% for ko in keyword_only_params %}
|
|
11
|
+
{{ ko }}
|
|
16
12
|
{% endfor %}
|
|
17
13
|
**kwargs: Any
|
|
18
14
|
){{" -> None" if async_mode else "" }}:{% endmacro %}
|
|
@@ -92,7 +88,7 @@ class {{ code_model.client.name }}({% if code_model.operation_mixin_group.mixin_
|
|
|
92
88
|
raise ValueError("API version {} is not available".format(api_version))
|
|
93
89
|
{% endif %}
|
|
94
90
|
self._config = {{ code_model.client.name }}Configuration({{ code_model.global_parameters.call }}{{ ", " if code_model.global_parameters.call }}**kwargs)
|
|
95
|
-
self._client = {{ async_prefix }}{{ code_model.client.pipeline_client }}(base_url=
|
|
91
|
+
self._client = {{ async_prefix }}{{ code_model.client.pipeline_client }}(base_url={{ code_model.host_variable_name }}, config=self._config, **kwargs)
|
|
96
92
|
super({{ code_model.client.name }}, self).__init__(
|
|
97
93
|
api_version=api_version,
|
|
98
94
|
profile=profile
|
|
@@ -15,5 +15,7 @@ def main(namespace):
|
|
|
15
15
|
if __name__ == "__main__":
|
|
16
16
|
patched = ",".join(main(sys.argv[1]))
|
|
17
17
|
output_folder = sys.argv[2]
|
|
18
|
-
with open(
|
|
18
|
+
with open(
|
|
19
|
+
f"{output_folder}/.temp_folder/patched.txt", "w", encoding="utf-8-sig"
|
|
20
|
+
) as f:
|
|
19
21
|
f.write(patched)
|
|
@@ -48,7 +48,7 @@ def create(
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
def python_run( # pylint: disable=inconsistent-return-statements
|
|
51
|
-
venv_context, module, command, directory=_ROOT_DIR
|
|
51
|
+
venv_context, module, command, directory=_ROOT_DIR
|
|
52
52
|
) -> Optional[str]:
|
|
53
53
|
try:
|
|
54
54
|
cmd_line = [
|
|
@@ -64,10 +64,11 @@ def python_run( # pylint: disable=inconsistent-return-statements
|
|
|
64
64
|
stdout=False,
|
|
65
65
|
)
|
|
66
66
|
if module == "get_all":
|
|
67
|
-
with open(
|
|
67
|
+
with open(
|
|
68
|
+
f"{command[1]}/.temp_folder/patched.txt", "r", encoding="utf-8-sig"
|
|
69
|
+
) as f:
|
|
68
70
|
return f.read()
|
|
69
71
|
except subprocess.CalledProcessError as err:
|
|
70
72
|
print(err)
|
|
71
|
-
|
|
72
|
-
sys.exit(1)
|
|
73
|
+
sys.exit(1)
|
|
73
74
|
return None
|
|
@@ -60,13 +60,21 @@ def update_overload_section(
|
|
|
60
60
|
overload_h["type"] = original_h["type"]
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def add_overload(
|
|
63
|
+
def add_overload(
|
|
64
|
+
yaml_data: Dict[str, Any], body_type: Dict[str, Any], for_flatten_params=False
|
|
65
|
+
):
|
|
64
66
|
overload = copy.deepcopy(yaml_data)
|
|
65
67
|
overload["isOverload"] = True
|
|
66
68
|
overload["bodyParameter"]["type"] = body_type
|
|
67
69
|
|
|
68
70
|
overload["overloads"] = []
|
|
69
71
|
|
|
72
|
+
if for_flatten_params:
|
|
73
|
+
overload["bodyParameter"]["flattened"] = True
|
|
74
|
+
else:
|
|
75
|
+
overload["parameters"] = [
|
|
76
|
+
p for p in overload["parameters"] if not p.get("inFlattenedBody")
|
|
77
|
+
]
|
|
70
78
|
# for yaml sync, we need to make sure all of the responses, parameters, and exceptions' types have the same yaml id
|
|
71
79
|
for overload_p, original_p in zip(overload["parameters"], yaml_data["parameters"]):
|
|
72
80
|
overload_p["type"] = original_p["type"]
|
|
@@ -107,6 +115,10 @@ def add_overloads_for_body_param(yaml_data: Dict[str, Any]) -> None:
|
|
|
107
115
|
):
|
|
108
116
|
continue
|
|
109
117
|
yaml_data["overloads"].append(add_overload(yaml_data, body_type))
|
|
118
|
+
if body_type.get("type") == "model" and body_type.get("base") == "json":
|
|
119
|
+
yaml_data["overloads"].append(
|
|
120
|
+
add_overload(yaml_data, body_type, for_flatten_params=True)
|
|
121
|
+
)
|
|
110
122
|
content_type_param = next(
|
|
111
123
|
p for p in yaml_data["parameters"] if p["restApiName"].lower() == "content-type"
|
|
112
124
|
)
|
|
@@ -162,9 +174,9 @@ def update_parameter(yaml_data: Dict[str, Any]) -> None:
|
|
|
162
174
|
if yaml_data.get("propertyToParameterName"):
|
|
163
175
|
# need to create a new one with padded keys and values
|
|
164
176
|
yaml_data["propertyToParameterName"] = {
|
|
165
|
-
pad_reserved_words(prop, PadType.PROPERTY)
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
pad_reserved_words(prop, PadType.PROPERTY): pad_reserved_words(
|
|
178
|
+
param_name, PadType.PARAMETER
|
|
179
|
+
)
|
|
168
180
|
for prop, param_name in yaml_data["propertyToParameterName"].items()
|
|
169
181
|
}
|
|
170
182
|
|
package/index.js
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.15",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
|
+
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/Azure/autorest.python/tree/autorestv3"
|
package/requirements.txt
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
black==22.
|
|
1
|
+
black==22.12.0
|
|
2
2
|
click==8.1.3
|
|
3
|
-
docutils==0.
|
|
3
|
+
docutils==0.19
|
|
4
4
|
Jinja2==3.1.2
|
|
5
|
-
json-rpc==1.
|
|
6
|
-
m2r2==0.3.
|
|
5
|
+
json-rpc==1.14.0
|
|
6
|
+
m2r2==0.3.3
|
|
7
7
|
MarkupSafe==2.1.1
|
|
8
8
|
mistune==0.8.4
|
|
9
9
|
mypy-extensions==0.4.3
|
|
10
|
-
pathspec==0.
|
|
11
|
-
platformdirs==2.
|
|
10
|
+
pathspec==0.10.3
|
|
11
|
+
platformdirs==2.6.2
|
|
12
12
|
PyYAML==6.0
|
|
13
13
|
tomli==2.0.1
|
package/setup.py
CHANGED
package/venvtools.py
CHANGED
|
@@ -56,7 +56,7 @@ def create_venv_with_package(packages):
|
|
|
56
56
|
subprocess.check_call(pip_call + packages)
|
|
57
57
|
yield myenv
|
|
58
58
|
|
|
59
|
-
def python_run(venv_context, module, command=None, *, additional_dir="."
|
|
59
|
+
def python_run(venv_context, module, command=None, *, additional_dir="."):
|
|
60
60
|
try:
|
|
61
61
|
cmd_line= [
|
|
62
62
|
venv_context.env_exe,
|
|
@@ -70,5 +70,4 @@ def python_run(venv_context, module, command=None, *, additional_dir=".", error_
|
|
|
70
70
|
)
|
|
71
71
|
except subprocess.CalledProcessError as err:
|
|
72
72
|
print(err)
|
|
73
|
-
|
|
74
|
-
sys.exit(1)
|
|
73
|
+
sys.exit(1)
|