@autorest/python 5.18.0 → 6.0.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/ChangeLog.md +58 -13
- package/README.md +9 -0
- package/autorest/codegen/__init__.py +24 -30
- package/autorest/codegen/models/base_builder.py +17 -6
- package/autorest/codegen/models/client.py +9 -6
- package/autorest/codegen/models/code_model.py +20 -14
- package/autorest/codegen/models/imports.py +57 -2
- package/autorest/codegen/models/lro_operation.py +4 -6
- package/autorest/codegen/models/lro_paging_operation.py +3 -9
- package/autorest/codegen/models/model_type.py +1 -6
- package/autorest/codegen/models/operation.py +47 -79
- package/autorest/codegen/models/operation_group.py +10 -9
- package/autorest/codegen/models/paging_operation.py +19 -7
- package/autorest/codegen/models/parameter.py +3 -7
- package/autorest/codegen/models/parameter_list.py +20 -36
- package/autorest/codegen/models/request_builder.py +31 -42
- package/autorest/codegen/serializers/__init__.py +12 -50
- package/autorest/codegen/serializers/builder_serializer.py +53 -40
- package/autorest/codegen/serializers/client_serializer.py +22 -31
- package/autorest/codegen/serializers/general_serializer.py +12 -12
- package/autorest/codegen/serializers/import_serializer.py +11 -22
- package/autorest/codegen/serializers/metadata_serializer.py +0 -2
- package/autorest/codegen/serializers/{model_base_serializer.py → model_serializer.py} +57 -43
- package/autorest/codegen/serializers/operation_groups_serializer.py +3 -7
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -23
- package/autorest/codegen/serializers/patch_serializer.py +1 -3
- package/autorest/codegen/serializers/request_builders_serializer.py +2 -5
- package/autorest/codegen/serializers/utils.py +1 -4
- package/autorest/codegen/templates/client.py.jinja2 +6 -3
- package/autorest/codegen/templates/config.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +5 -12
- package/autorest/codegen/templates/operation_group.py.jinja2 +16 -3
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -8
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -1
- package/autorest/codegen/templates/patch.py.jinja2 +1 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +0 -7
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -4
- package/autorest/codegen/templates/rest_init.py.jinja2 +3 -8
- package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
- package/autorest/codegen/templates/setup.py.jinja2 +4 -0
- package/autorest/codegen/templates/vendor.py.jinja2 +10 -0
- package/autorest/m4reformatter/__init__.py +9 -3
- package/autorest/multiapi/models/client.py +12 -2
- package/autorest/multiapi/serializers/__init__.py +17 -8
- package/autorest/multiapi/serializers/import_serializer.py +4 -8
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/preprocess/__init__.py +24 -4
- package/package.json +2 -2
- package/autorest/codegen/serializers/model_generic_serializer.py +0 -32
- package/autorest/codegen/serializers/model_python3_serializer.py +0 -72
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from abc import abstractmethod
|
|
7
6
|
from typing import cast, List
|
|
8
7
|
from jinja2 import Environment
|
|
9
8
|
from ..models import ModelType, CodeModel, Property
|
|
10
|
-
from ..models.imports import FileImport,
|
|
9
|
+
from ..models.imports import FileImport, TypingSection, MsrestImportType
|
|
11
10
|
from .import_serializer import FileImportSerializer
|
|
12
11
|
|
|
13
12
|
|
|
@@ -27,31 +26,33 @@ def _documentation_string(
|
|
|
27
26
|
return retval
|
|
28
27
|
|
|
29
28
|
|
|
30
|
-
class
|
|
31
|
-
def __init__(
|
|
32
|
-
self, code_model: CodeModel, env: Environment, is_python3_file: bool
|
|
33
|
-
) -> None:
|
|
29
|
+
class ModelSerializer:
|
|
30
|
+
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
34
31
|
self.code_model = code_model
|
|
35
32
|
self.env = env
|
|
36
|
-
self.is_python3_file = is_python3_file
|
|
37
33
|
|
|
38
34
|
def serialize(self) -> str:
|
|
39
35
|
# Generate the models
|
|
40
36
|
template = self.env.get_template("model_container.py.jinja2")
|
|
41
37
|
return template.render(
|
|
42
38
|
code_model=self.code_model,
|
|
43
|
-
imports=FileImportSerializer(
|
|
44
|
-
self.imports(), is_python3_file=self.is_python3_file
|
|
45
|
-
),
|
|
39
|
+
imports=FileImportSerializer(self.imports()),
|
|
46
40
|
str=str,
|
|
47
41
|
serializer=self,
|
|
48
42
|
)
|
|
49
43
|
|
|
50
44
|
def imports(self) -> FileImport:
|
|
51
45
|
file_import = FileImport()
|
|
52
|
-
file_import.
|
|
46
|
+
file_import.add_msrest_import(
|
|
47
|
+
self.code_model, "..", MsrestImportType.Module, TypingSection.REGULAR
|
|
48
|
+
)
|
|
53
49
|
for model in self.code_model.model_types:
|
|
54
50
|
file_import.merge(model.imports(is_operation_file=False))
|
|
51
|
+
init_line_parameters = [
|
|
52
|
+
p for p in model.properties if not p.readonly and not p.is_discriminator
|
|
53
|
+
]
|
|
54
|
+
for param in init_line_parameters:
|
|
55
|
+
file_import.merge(param.imports())
|
|
55
56
|
return file_import
|
|
56
57
|
|
|
57
58
|
@staticmethod
|
|
@@ -71,9 +72,12 @@ class ModelBaseSerializer:
|
|
|
71
72
|
properties_to_initialize = model.properties
|
|
72
73
|
return properties_to_initialize
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
def declare_model(self, model: ModelType) -> str:
|
|
76
|
+
basename = (
|
|
77
|
+
"msrest.serialization.Model"
|
|
78
|
+
if self.code_model.options["client_side_validation"]
|
|
79
|
+
else "_serialization.Model"
|
|
80
|
+
)
|
|
77
81
|
if model.parents:
|
|
78
82
|
basename = ", ".join([cast(ModelType, m).name for m in model.parents])
|
|
79
83
|
return f"class {model.name}({basename}):{model.pylint_disable}"
|
|
@@ -87,18 +91,12 @@ class ModelBaseSerializer:
|
|
|
87
91
|
def variable_documentation_string(prop: Property) -> List[str]:
|
|
88
92
|
return _documentation_string(prop, "ivar", "vartype")
|
|
89
93
|
|
|
90
|
-
@abstractmethod
|
|
91
|
-
def super_call_template(self, model: ModelType) -> str:
|
|
92
|
-
...
|
|
93
|
-
|
|
94
94
|
def super_call(self, model: ModelType):
|
|
95
|
-
return self.
|
|
96
|
-
self.properties_to_pass_to_super(model)
|
|
97
|
-
)
|
|
95
|
+
return f"super().__init__({self.properties_to_pass_to_super(model)})"
|
|
98
96
|
|
|
99
97
|
def initialize_properties(self, model: ModelType) -> List[str]:
|
|
100
98
|
init_args = []
|
|
101
|
-
for prop in
|
|
99
|
+
for prop in self.get_properties_to_initialize(model):
|
|
102
100
|
if prop.is_discriminator:
|
|
103
101
|
discriminator_value = (
|
|
104
102
|
f"'{model.discriminator_value}'"
|
|
@@ -115,13 +113,17 @@ class ModelBaseSerializer:
|
|
|
115
113
|
elif prop.readonly:
|
|
116
114
|
init_args.append(f"self.{prop.client_name} = None")
|
|
117
115
|
elif not prop.constant:
|
|
118
|
-
init_args.append(self.
|
|
116
|
+
init_args.append(f"self.{prop.client_name} = {prop.client_name}")
|
|
119
117
|
return init_args
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
@staticmethod
|
|
120
|
+
def initialize_standard_property(prop: Property):
|
|
122
121
|
if not (prop.optional or prop.client_default_value is not None):
|
|
123
|
-
return
|
|
124
|
-
return
|
|
122
|
+
return f"{prop.client_name}: {prop.type_annotation()},{prop.pylint_disable}"
|
|
123
|
+
return (
|
|
124
|
+
f"{prop.client_name}: {prop.type_annotation()} = "
|
|
125
|
+
f"{prop.client_default_value_declaration},{prop.pylint_disable}"
|
|
126
|
+
)
|
|
125
127
|
|
|
126
128
|
@staticmethod
|
|
127
129
|
def discriminator_docstring(model: ModelType) -> str:
|
|
@@ -130,22 +132,34 @@ class ModelBaseSerializer:
|
|
|
130
132
|
f"Known sub-classes are: {', '.join(v.name for v in model.discriminated_subtypes.values())}"
|
|
131
133
|
)
|
|
132
134
|
|
|
133
|
-
@abstractmethod
|
|
134
135
|
def init_line(self, model: ModelType) -> List[str]:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
init_properties_declaration = []
|
|
137
|
+
init_line_parameters = [
|
|
138
|
+
p
|
|
139
|
+
for p in model.properties
|
|
140
|
+
if not p.readonly and not p.is_discriminator and not p.constant
|
|
141
|
+
]
|
|
142
|
+
init_line_parameters.sort(key=lambda x: x.optional)
|
|
143
|
+
if init_line_parameters:
|
|
144
|
+
init_properties_declaration.append("*,")
|
|
145
|
+
for param in init_line_parameters:
|
|
146
|
+
init_properties_declaration.append(self.initialize_standard_property(param))
|
|
147
|
+
|
|
148
|
+
return init_properties_declaration
|
|
140
149
|
|
|
141
|
-
@
|
|
142
|
-
def
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
@staticmethod
|
|
151
|
+
def properties_to_pass_to_super(model: ModelType) -> str:
|
|
152
|
+
properties_to_pass_to_super = []
|
|
153
|
+
for parent in model.parents:
|
|
154
|
+
for prop in model.properties:
|
|
155
|
+
if (
|
|
156
|
+
prop in parent.properties
|
|
157
|
+
and not prop.is_discriminator
|
|
158
|
+
and not prop.constant
|
|
159
|
+
and not prop.readonly
|
|
160
|
+
):
|
|
161
|
+
properties_to_pass_to_super.append(
|
|
162
|
+
f"{prop.client_name}={prop.client_name}"
|
|
163
|
+
)
|
|
164
|
+
properties_to_pass_to_super.append("**kwargs")
|
|
165
|
+
return ", ".join(properties_to_pass_to_super)
|
|
@@ -22,13 +22,11 @@ class OperationGroupsSerializer:
|
|
|
22
22
|
code_model: CodeModel,
|
|
23
23
|
env: Environment,
|
|
24
24
|
async_mode: bool,
|
|
25
|
-
is_python3_file: bool,
|
|
26
25
|
operation_group: Optional[OperationGroup] = None,
|
|
27
26
|
) -> None:
|
|
28
27
|
self.code_model = code_model
|
|
29
28
|
self.env = env
|
|
30
29
|
self.async_mode = async_mode
|
|
31
|
-
self.is_python3_file = is_python3_file
|
|
32
30
|
self.operation_group = operation_group
|
|
33
31
|
|
|
34
32
|
def serialize(self) -> str:
|
|
@@ -42,7 +40,6 @@ class OperationGroupsSerializer:
|
|
|
42
40
|
imports.merge(
|
|
43
41
|
operation_group.imports(
|
|
44
42
|
async_mode=self.async_mode,
|
|
45
|
-
is_python3_file=self.is_python3_file,
|
|
46
43
|
)
|
|
47
44
|
)
|
|
48
45
|
|
|
@@ -54,20 +51,19 @@ class OperationGroupsSerializer:
|
|
|
54
51
|
operation_groups=operation_groups,
|
|
55
52
|
imports=FileImportSerializer(
|
|
56
53
|
imports,
|
|
57
|
-
is_python3_file=self.is_python3_file,
|
|
58
54
|
async_mode=self.async_mode,
|
|
59
55
|
),
|
|
60
56
|
async_mode=self.async_mode,
|
|
61
|
-
is_python3_file=self.is_python3_file,
|
|
62
57
|
get_operation_serializer=functools.partial(
|
|
63
58
|
get_operation_serializer,
|
|
64
59
|
code_model=self.code_model,
|
|
65
60
|
async_mode=self.async_mode,
|
|
66
|
-
is_python3_file=self.is_python3_file,
|
|
67
61
|
),
|
|
68
62
|
request_builder_serializer=RequestBuilderSerializer(
|
|
69
63
|
self.code_model,
|
|
70
64
|
async_mode=False,
|
|
71
|
-
is_python3_file=self.is_python3_file,
|
|
72
65
|
),
|
|
66
|
+
request_builders=[
|
|
67
|
+
rb for rb in self.code_model.request_builders if not rb.abstract
|
|
68
|
+
],
|
|
73
69
|
)
|
|
@@ -18,40 +18,19 @@ class OperationsInitSerializer:
|
|
|
18
18
|
self.env = env
|
|
19
19
|
self.async_mode = async_mode
|
|
20
20
|
|
|
21
|
-
def
|
|
21
|
+
def operation_group_imports(self) -> List[str]:
|
|
22
22
|
def _get_filename(operation_group: OperationGroup) -> str:
|
|
23
|
-
|
|
23
|
+
return (
|
|
24
24
|
"_operations"
|
|
25
25
|
if self.code_model.options["combine_operation_files"]
|
|
26
26
|
else operation_group.filename
|
|
27
27
|
)
|
|
28
|
-
return prefix + filename_suffix
|
|
29
28
|
|
|
30
29
|
return [
|
|
31
30
|
f"from .{_get_filename(og)} import {og.class_name}"
|
|
32
31
|
for og in self.code_model.operation_groups
|
|
33
32
|
]
|
|
34
33
|
|
|
35
|
-
def operation_group_imports(self) -> List[str]:
|
|
36
|
-
typed_py3_files = self.code_model.options["add_python3_operation_files"]
|
|
37
|
-
py3_only = self.code_model.options["python3_only"]
|
|
38
|
-
if typed_py3_files and not py3_only and not self.async_mode:
|
|
39
|
-
retval: List[str] = ["try:"]
|
|
40
|
-
retval.extend(
|
|
41
|
-
[
|
|
42
|
-
f" {line}"
|
|
43
|
-
for line in self._operation_group_imports_helper(
|
|
44
|
-
filename_suffix="_py3"
|
|
45
|
-
)
|
|
46
|
-
]
|
|
47
|
-
)
|
|
48
|
-
retval.append("except (SyntaxError, ImportError):")
|
|
49
|
-
retval.extend(
|
|
50
|
-
[f" {line}" for line in self._operation_group_imports_helper()]
|
|
51
|
-
)
|
|
52
|
-
return retval
|
|
53
|
-
return self._operation_group_imports_helper()
|
|
54
|
-
|
|
55
34
|
def serialize(self) -> str:
|
|
56
35
|
operation_group_init_template = self.env.get_template(
|
|
57
36
|
"operations_folder_init.py.jinja2"
|
|
@@ -19,9 +19,7 @@ class PatchSerializer:
|
|
|
19
19
|
imports.add_submodule_import(
|
|
20
20
|
"typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
21
21
|
)
|
|
22
|
-
is_python3_file = self.code_model.options["python3_only"]
|
|
23
22
|
return template.render(
|
|
24
23
|
code_model=self.code_model,
|
|
25
|
-
imports=FileImportSerializer(imports
|
|
26
|
-
is_python3_file=is_python3_file,
|
|
24
|
+
imports=FileImportSerializer(imports),
|
|
27
25
|
)
|
|
@@ -18,13 +18,11 @@ class RequestBuildersSerializer:
|
|
|
18
18
|
code_model: CodeModel,
|
|
19
19
|
env: Environment,
|
|
20
20
|
request_builders: List[RequestBuilderType],
|
|
21
|
-
is_python3_file: bool,
|
|
22
21
|
) -> None:
|
|
23
22
|
self.code_model = code_model
|
|
24
23
|
self.env = env
|
|
25
24
|
self.request_builders = request_builders
|
|
26
25
|
self.group_name = request_builders[0].group_name
|
|
27
|
-
self.is_python3_file = is_python3_file
|
|
28
26
|
|
|
29
27
|
@property
|
|
30
28
|
def imports(self) -> FileImport:
|
|
@@ -46,12 +44,11 @@ class RequestBuildersSerializer:
|
|
|
46
44
|
|
|
47
45
|
return template.render(
|
|
48
46
|
code_model=self.code_model,
|
|
49
|
-
request_builders=self.request_builders,
|
|
47
|
+
request_builders=[rb for rb in self.request_builders if not rb.abstract],
|
|
50
48
|
imports=FileImportSerializer(
|
|
51
49
|
self.imports,
|
|
52
|
-
is_python3_file=True,
|
|
53
50
|
),
|
|
54
51
|
request_builder_serializer=RequestBuilderSerializer(
|
|
55
|
-
self.code_model, async_mode=False
|
|
52
|
+
self.code_model, async_mode=False
|
|
56
53
|
),
|
|
57
54
|
)
|
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
def method_signature_and_response_type_annotation_template(
|
|
9
9
|
*,
|
|
10
|
-
is_python3_file: bool,
|
|
11
10
|
method_signature: str,
|
|
12
11
|
response_type_annotation: str,
|
|
13
12
|
) -> str:
|
|
14
|
-
|
|
15
|
-
return f"{method_signature} -> {response_type_annotation}:"
|
|
16
|
-
return f"{method_signature}:\n # type: (...) -> {response_type_annotation}"
|
|
13
|
+
return f"{method_signature} -> {response_type_annotation}:"
|
|
@@ -6,13 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
{{ imports }}
|
|
8
8
|
|
|
9
|
-
{{ serializer.class_definition
|
|
9
|
+
{{ serializer.class_definition }}
|
|
10
10
|
"""{{ op_tools.wrap_string(code_model.client.description, "\n") | indent }}
|
|
11
11
|
|
|
12
12
|
{{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
|
|
13
13
|
{{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
|
|
14
|
-
{% if
|
|
15
|
-
|
|
14
|
+
{% if serializer.should_init_super %}
|
|
15
|
+
super().__init__()
|
|
16
|
+
{% endif %}
|
|
17
|
+
{% if code_model.client.parameters.kwargs_to_pop %}
|
|
18
|
+
{{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
|
|
16
19
|
{% endif %}
|
|
17
20
|
{% if code_model.client.has_parameterized_host %}
|
|
18
21
|
{{ serializer.host_variable_name }} = {{ keywords.escape_str(code_model.client.url) }}
|
|
@@ -22,8 +22,8 @@ class {{ code_model.client.name }}Configuration(Configuration): # pylint: disab
|
|
|
22
22
|
{{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
|
|
23
23
|
{{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
|
|
24
24
|
super({{ code_model.client.name }}Configuration, self).__init__(**kwargs)
|
|
25
|
-
{% if code_model.config.parameters.kwargs_to_pop
|
|
26
|
-
{{ op_tools.serialize(serializer.pop_kwargs_from_signature(
|
|
25
|
+
{% if code_model.config.parameters.kwargs_to_pop %}
|
|
26
|
+
{{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
|
|
27
27
|
{% endif %}
|
|
28
28
|
{% if serializer.check_required_parameters() %}
|
|
29
29
|
{{ op_tools.serialize(serializer.check_required_parameters()) | indent(8) -}}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"sync": {
|
|
21
21
|
{% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
|
|
22
22
|
{{ gp.client_name | tojson }}: {
|
|
23
|
-
"signature": {{ gp.method_signature(
|
|
23
|
+
"signature": {{ gp.method_signature(async_mode=False) | tojson }},
|
|
24
24
|
"description": {{ gp.description | tojson }},
|
|
25
25
|
"docstring_type": {{ gp.docstring_type(async_mode=False) | tojson }},
|
|
26
26
|
"required": {{ (not gp.optional) | tojson }}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"async": {
|
|
31
31
|
{% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
|
|
32
32
|
{{ gp.client_name | tojson }}: {
|
|
33
|
-
"signature": {{ (gp.method_signature(
|
|
33
|
+
"signature": {{ (gp.method_signature(async_mode=True)) | tojson }},
|
|
34
34
|
"description": {{ gp.description | tojson }},
|
|
35
35
|
"docstring_type": {{ gp.docstring_type(async_mode=True) | tojson }},
|
|
36
36
|
"required": {{ (not gp.optional) | tojson }}
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
{% if not client.has_parameterized_host %}
|
|
55
55
|
"base_url": {
|
|
56
|
-
"signature": {{ client.parameters.host.method_signature(
|
|
56
|
+
"signature": {{ client.parameters.host.method_signature(async_mode=False) | tojson }},
|
|
57
57
|
"description": "Service URL",
|
|
58
58
|
"docstring_type": "str",
|
|
59
59
|
"required": false
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
{% if not client.has_parameterized_host %}
|
|
77
77
|
"base_url": {
|
|
78
|
-
"signature": {{ client.parameters.host.method_signature(
|
|
78
|
+
"signature": {{ client.parameters.host.method_signature(async_mode=True) | tojson }},
|
|
79
79
|
"description": "Service URL",
|
|
80
80
|
"docstring_type": "str",
|
|
81
81
|
"required": false
|
|
@@ -3,21 +3,14 @@
|
|
|
3
3
|
{{ code_model.options['license_header'] }}
|
|
4
4
|
{% macro iterate_models_py3() %}
|
|
5
5
|
{% for schema in schemas %}
|
|
6
|
-
from .{{ code_model.
|
|
6
|
+
from .{{ code_model.models_filename }} import {{ schema }}
|
|
7
7
|
{% endfor %}
|
|
8
8
|
{% endmacro %}
|
|
9
|
-
|
|
10
9
|
{% if schemas %}
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{{ iterate_models_py3() | indent-}}
|
|
16
|
-
except (SyntaxError, ImportError):
|
|
17
|
-
{% for schema in schemas %}
|
|
18
|
-
from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
|
|
19
|
-
{% endfor %}
|
|
20
|
-
{% endif %}
|
|
10
|
+
|
|
11
|
+
{% for schema in schemas %}
|
|
12
|
+
from .{{ code_model.models_filename }} import {{ schema }}
|
|
13
|
+
{% endfor %}
|
|
21
14
|
{% endif %}
|
|
22
15
|
{% if enums %}
|
|
23
16
|
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
{% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
|
|
2
|
-
{% set base_class = ("(" + operation_group.base_class
|
|
2
|
+
{% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
|
|
3
|
+
{% macro check_abstract_methods() %}
|
|
4
|
+
{% if operation_group.has_abstract_operations %}
|
|
5
|
+
raise_if_not_implemented(self.__class__, [
|
|
6
|
+
{% for operation in operation_group.operations if operation.abstract %}
|
|
7
|
+
'{{operation.name}}',
|
|
8
|
+
{% endfor %}
|
|
9
|
+
])
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% endmacro %}
|
|
3
12
|
class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
|
|
4
13
|
{% if not operation_group.is_mixin %}
|
|
5
14
|
"""
|
|
@@ -11,7 +20,7 @@ class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
|
|
|
11
20
|
:attr:`{{ operation_group.property_name }}` attribute.
|
|
12
21
|
"""
|
|
13
22
|
|
|
14
|
-
{% if code_model.public_model_types and code_model.options["models_mode"]
|
|
23
|
+
{% if code_model.public_model_types and code_model.options["models_mode"]%}
|
|
15
24
|
models = _models
|
|
16
25
|
|
|
17
26
|
{% endif %}
|
|
@@ -21,9 +30,13 @@ class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
|
|
|
21
30
|
self._config = input_args.pop(0) if input_args else kwargs.pop("config")
|
|
22
31
|
self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
|
|
23
32
|
self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
|
|
33
|
+
{{ check_abstract_methods() }}
|
|
34
|
+
{% elif operation_group.has_abstract_operations %}
|
|
24
35
|
|
|
36
|
+
def __init__(self){{ return_none_type_annotation }}:
|
|
37
|
+
{{ check_abstract_methods() }}
|
|
25
38
|
{% endif %}
|
|
26
|
-
{% for operation in operation_group.operations %}
|
|
39
|
+
{% for operation in operation_group.operations if not operation.abstract %}
|
|
27
40
|
|
|
28
41
|
{% set request_builder = operation.request_builder %}
|
|
29
42
|
{% set operation_serializer = get_operation_serializer(operation) %}
|
|
@@ -7,19 +7,13 @@
|
|
|
7
7
|
{{ imports }}
|
|
8
8
|
|
|
9
9
|
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
|
|
10
|
-
{{ op_tools.declare_serializer(code_model) }}
|
|
11
|
-
{%- if not is_python3_file %}
|
|
12
|
-
# fmt: off
|
|
13
|
-
{% endif %}
|
|
10
|
+
{{ op_tools.declare_serializer(code_model, request_builders) }}
|
|
14
11
|
{% for operation_group in operation_groups %}
|
|
15
|
-
{% for request_builder in
|
|
12
|
+
{% for request_builder in request_builders | selectattr("group_name", "equalto", operation_group.property_name) | rejectattr("is_overload") %}
|
|
16
13
|
|
|
17
14
|
{% include "request_builder.py.jinja2" %}
|
|
18
15
|
{% endfor %}
|
|
19
16
|
{% endfor %}
|
|
20
|
-
{% if not is_python3_file %}
|
|
21
|
-
# fmt: on
|
|
22
|
-
{% endif %}
|
|
23
17
|
{% endif %}
|
|
24
18
|
{% for operation_group in operation_groups %}
|
|
25
19
|
{% include "operation_group.py.jinja2" %}
|
|
@@ -50,11 +50,13 @@ Example:
|
|
|
50
50
|
{% endif %}
|
|
51
51
|
{% endfor %}{% endmacro %}
|
|
52
52
|
|
|
53
|
-
{% macro declare_serializer(code_model) %}
|
|
53
|
+
{% macro declare_serializer(code_model, request_builders) %}
|
|
54
|
+
{% if request_builders %}
|
|
54
55
|
_SERIALIZER = Serializer()
|
|
55
56
|
{% if not code_model.options["client_side_validation"] %}
|
|
56
57
|
_SERIALIZER.client_side_validation = False
|
|
57
58
|
{% endif %}
|
|
59
|
+
{% endif %}
|
|
58
60
|
{% endmacro %}
|
|
59
61
|
|
|
60
62
|
{% macro generate_overloads(operation_serializer, operation) %}
|
|
@@ -8,8 +8,7 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python
|
|
|
8
8
|
"""
|
|
9
9
|
{{ imports }}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
__all__{{ type_annotation if is_python3_file else "" }} = []{{ "" if is_python3_file else (" # type" + type_annotation) }} # Add all objects you want publicly available to users at this package level
|
|
11
|
+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
|
|
13
12
|
|
|
14
13
|
def patch_sdk():
|
|
15
14
|
"""Do not remove from this file.
|
|
@@ -5,12 +5,6 @@
|
|
|
5
5
|
{{ op_tools.description(request_builder, request_builder_serializer) | indent }}
|
|
6
6
|
{% endif %}
|
|
7
7
|
{% if not request_builder.is_overload %}
|
|
8
|
-
{% if request_builder.abstract %}
|
|
9
|
-
raise NotImplementedError(
|
|
10
|
-
"You need to write a custom operation for '{{ request_builder.name }}'. "
|
|
11
|
-
"Please refer to https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
|
|
12
|
-
)
|
|
13
|
-
{% else %}
|
|
14
8
|
{% if request_builder_serializer.pop_kwargs_from_signature(request_builder) %}
|
|
15
9
|
{{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
|
|
16
10
|
{%- endif -%}
|
|
@@ -31,5 +25,4 @@
|
|
|
31
25
|
{{ op_tools.serialize(request_builder_serializer.serialize_headers(request_builder)) | indent }}
|
|
32
26
|
{% endif %}
|
|
33
27
|
{{ op_tools.serialize(request_builder_serializer.create_http_request(request_builder)) | indent }}
|
|
34
|
-
{% endif %}
|
|
35
28
|
{% endif %}
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
{{ code_model.options['license_header'] }}
|
|
4
4
|
{{ imports }}
|
|
5
5
|
|
|
6
|
-
{{ op_tools.declare_serializer(code_model) }}
|
|
7
|
-
{% if not is_python3_file %}
|
|
8
|
-
# fmt: off
|
|
9
|
-
{% endif %}
|
|
6
|
+
{{ op_tools.declare_serializer(code_model, request_builders) }}
|
|
10
7
|
{% for request_builder in request_builders %}
|
|
11
8
|
|
|
12
9
|
{% include "request_builder.py.jinja2" %}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
{{ code_model.options['license_header'] }}
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{% endfor %}
|
|
8
|
-
except (SyntaxError, ImportError):
|
|
9
|
-
{% for request_builder in request_builders %}
|
|
10
|
-
from ._request_builders import {{ request_builder.name }} # type: ignore
|
|
11
|
-
{% endfor %}
|
|
4
|
+
{% for request_builder in request_builders %}
|
|
5
|
+
from ._request_builders import {{ request_builder.name }}
|
|
6
|
+
{% endfor %}
|
|
12
7
|
|
|
13
8
|
__all__ = [
|
|
14
9
|
{% for request_builder in request_builders %}
|