@autorest/python 5.13.0 → 5.16.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 +67 -0
- package/autorest/__init__.py +1 -2
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +239 -105
- package/autorest/codegen/models/__init__.py +29 -18
- package/autorest/codegen/models/base_builder.py +48 -11
- package/autorest/codegen/models/base_model.py +6 -4
- package/autorest/codegen/models/base_schema.py +21 -24
- package/autorest/codegen/models/client.py +70 -20
- package/autorest/codegen/models/code_model.py +144 -129
- package/autorest/codegen/models/constant_schema.py +32 -16
- package/autorest/codegen/models/credential_model.py +55 -0
- package/autorest/codegen/models/credential_schema.py +21 -16
- package/autorest/codegen/models/credential_schema_policy.py +11 -15
- package/autorest/codegen/models/dictionary_schema.py +27 -24
- package/autorest/codegen/models/enum_schema.py +41 -62
- package/autorest/codegen/models/imports.py +72 -41
- package/autorest/codegen/models/list_schema.py +40 -18
- package/autorest/codegen/models/lro_operation.py +61 -25
- package/autorest/codegen/models/lro_paging_operation.py +5 -6
- package/autorest/codegen/models/object_schema.py +113 -59
- package/autorest/codegen/models/operation.py +251 -111
- package/autorest/codegen/models/operation_group.py +67 -32
- package/autorest/codegen/models/paging_operation.py +48 -21
- package/autorest/codegen/models/parameter.py +182 -90
- package/autorest/codegen/models/parameter_list.py +184 -163
- package/autorest/codegen/models/primitive_schemas.py +89 -70
- package/autorest/codegen/models/property.py +49 -31
- package/autorest/codegen/models/request_builder.py +67 -32
- package/autorest/codegen/models/request_builder_parameter.py +54 -23
- package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
- package/autorest/codegen/models/schema_request.py +16 -6
- package/autorest/codegen/models/schema_response.py +35 -17
- package/autorest/codegen/models/utils.py +24 -1
- package/autorest/codegen/serializers/__init__.py +273 -89
- package/autorest/codegen/serializers/builder_serializer.py +711 -333
- package/autorest/codegen/serializers/client_serializer.py +114 -43
- package/autorest/codegen/serializers/general_serializer.py +84 -25
- package/autorest/codegen/serializers/import_serializer.py +93 -31
- package/autorest/codegen/serializers/metadata_serializer.py +73 -24
- package/autorest/codegen/serializers/model_base_serializer.py +42 -14
- package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
- package/autorest/codegen/serializers/model_init_serializer.py +5 -1
- package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
- package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/patch_serializer.py +14 -2
- package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
- package/autorest/codegen/serializers/utils.py +60 -21
- package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
- package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
- package/autorest/codegen/templates/README.md.jinja2 +105 -0
- package/autorest/codegen/templates/config.py.jinja2 +4 -4
- package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
- package/autorest/codegen/templates/enum.py.jinja2 +1 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
- package/autorest/codegen/templates/init.py.jinja2 +9 -6
- package/autorest/codegen/templates/keywords.jinja2 +14 -1
- package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
- package/autorest/codegen/templates/model.py.jinja2 +1 -6
- package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
- package/autorest/codegen/templates/operation.py.jinja2 +8 -11
- package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/patch.py.jinja2 +18 -29
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
- package/autorest/codegen/templates/setup.py.jinja2 +79 -20
- package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +13 -6
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +35 -18
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +18 -23
- package/autorest/multiapi/serializers/import_serializer.py +47 -15
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/namer/__init__.py +2 -4
- package/autorest/namer/name_converter.py +200 -103
- package/autorest/namer/python_mappings.py +10 -22
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/rest.py +0 -42
|
@@ -10,6 +10,7 @@ from collections import defaultdict
|
|
|
10
10
|
from abc import abstractmethod, ABC
|
|
11
11
|
from typing import Any, List, TypeVar, Dict, Union, Optional, cast
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
from ..models import (
|
|
14
15
|
Operation,
|
|
15
16
|
CodeModel,
|
|
@@ -27,79 +28,54 @@ from ..models import (
|
|
|
27
28
|
SchemaResponse,
|
|
28
29
|
IOSchema,
|
|
29
30
|
ParameterStyle,
|
|
30
|
-
ParameterLocation
|
|
31
|
+
ParameterLocation,
|
|
32
|
+
ParameterMethodLocation,
|
|
31
33
|
)
|
|
32
34
|
from . import utils
|
|
33
35
|
|
|
34
36
|
T = TypeVar("T")
|
|
35
37
|
OrderedSet = Dict[T, None]
|
|
36
38
|
|
|
39
|
+
|
|
37
40
|
def _escape_str(input_str: str) -> str:
|
|
38
41
|
replace = input_str.replace("'", "\\'")
|
|
39
42
|
return f'"{replace}"'
|
|
40
43
|
|
|
44
|
+
|
|
41
45
|
def _improve_json_string(template_representation: str) -> Any:
|
|
42
|
-
origin = template_representation.split(
|
|
46
|
+
origin = template_representation.split("\n")
|
|
43
47
|
final = []
|
|
44
48
|
for line in origin:
|
|
45
|
-
idx0 = line.find(
|
|
49
|
+
idx0 = line.find("#")
|
|
46
50
|
idx1 = line.rfind('"')
|
|
47
51
|
modified_line = ""
|
|
48
52
|
if idx0 > -1 and idx1 > -1:
|
|
49
|
-
modified_line = line[:idx0] + line[idx1:] +
|
|
53
|
+
modified_line = line[:idx0] + line[idx1:] + " " + line[idx0:idx1] + "\n"
|
|
50
54
|
else:
|
|
51
|
-
modified_line = line +
|
|
55
|
+
modified_line = line + "\n"
|
|
52
56
|
modified_line = modified_line.replace('"', "").replace("\\", '"')
|
|
53
57
|
final.append(modified_line)
|
|
54
|
-
return
|
|
58
|
+
return "".join(final)
|
|
59
|
+
|
|
55
60
|
|
|
56
61
|
def _json_dumps_template(template_representation: Any) -> Any:
|
|
57
62
|
# only for template use, since it wraps everything in strings
|
|
58
|
-
return _improve_json_string(
|
|
59
|
-
|
|
60
|
-
def _serialize_files_or_data_dict(multipart_parameters: List[Parameter]) -> str:
|
|
61
|
-
# only for template use
|
|
62
|
-
template = {
|
|
63
|
-
f'"{param.serialized_name}"': param.schema.get_files_and_data_template_representation(
|
|
64
|
-
optional=not param.required,
|
|
65
|
-
description=param.description,
|
|
66
|
-
)
|
|
67
|
-
for param in multipart_parameters
|
|
68
|
-
}
|
|
69
|
-
return _json_dumps_template(template)
|
|
70
|
-
|
|
71
|
-
def _get_files_example_template(builder) -> List[str]:
|
|
72
|
-
multipart_params = builder.parameters.multipart
|
|
73
|
-
if multipart_params:
|
|
74
|
-
retval = [
|
|
75
|
-
"# multipart input template you can fill out and use as your `files` input.",
|
|
76
|
-
]
|
|
77
|
-
retval.extend(f"files = {_serialize_files_or_data_dict(multipart_params)}".splitlines())
|
|
78
|
-
return retval
|
|
79
|
-
raise ValueError(
|
|
80
|
-
"You're trying to get a template for your multipart params, but you don't have multipart params"
|
|
63
|
+
return _improve_json_string(
|
|
64
|
+
json.dumps(template_representation, sort_keys=True, indent=4)
|
|
81
65
|
)
|
|
82
66
|
|
|
83
|
-
def _get_data_example_template(builder) -> List[str]:
|
|
84
|
-
data_inputs = builder.parameters.data_inputs
|
|
85
|
-
if data_inputs:
|
|
86
|
-
retval = [
|
|
87
|
-
"# form-encoded input template you can fill out and use as your `data` input."
|
|
88
|
-
]
|
|
89
|
-
retval.extend(f"data = {_serialize_files_or_data_dict(data_inputs)}".splitlines())
|
|
90
|
-
return retval
|
|
91
|
-
raise ValueError(
|
|
92
|
-
"You're trying to get a template for your form-encoded params, but you don't have form-encoded params"
|
|
93
|
-
)
|
|
94
67
|
|
|
95
68
|
def _content_type_error_check(builder) -> List[str]:
|
|
96
69
|
retval = ["else:"]
|
|
97
70
|
retval.append(" raise ValueError(")
|
|
98
|
-
retval.append(
|
|
71
|
+
retval.append(
|
|
72
|
+
" \"The content_type '{}' is not one of the allowed values: \""
|
|
73
|
+
)
|
|
99
74
|
retval.append(f' "{builder.parameters.content_types}".format(content_type)')
|
|
100
75
|
retval.append(" )")
|
|
101
76
|
return retval
|
|
102
77
|
|
|
78
|
+
|
|
103
79
|
def _serialize_files_and_data_body(builder, param_name: str) -> List[str]:
|
|
104
80
|
retval: List[str] = []
|
|
105
81
|
# we have to construct our form data before passing to the request as well
|
|
@@ -110,18 +86,14 @@ def _serialize_files_and_data_body(builder, param_name: str) -> List[str]:
|
|
|
110
86
|
retval.append("}")
|
|
111
87
|
return retval
|
|
112
88
|
|
|
113
|
-
def _pop_parameters_kwarg(
|
|
114
|
-
function_name: str,
|
|
115
|
-
kwarg_name: str,
|
|
116
|
-
) -> str:
|
|
117
|
-
return f'_{function_name}_parameters = kwargs.pop("{kwarg_name}", {{}}) # type: Dict[str, Any]'
|
|
118
89
|
|
|
119
90
|
def _serialize_grouped_body(builder) -> List[str]:
|
|
120
91
|
retval: List[str] = []
|
|
121
92
|
for grouped_parameter in builder.parameters.grouped:
|
|
122
93
|
retval.append(f"{grouped_parameter.serialized_name} = None")
|
|
123
94
|
for grouper_name, grouped_parameters in groupby(
|
|
124
|
-
builder.parameters.grouped,
|
|
95
|
+
builder.parameters.grouped,
|
|
96
|
+
key=lambda a: cast(Parameter, a.grouped_by).serialized_name,
|
|
125
97
|
):
|
|
126
98
|
retval.append(f"if {grouper_name} is not None:")
|
|
127
99
|
for grouped_parameter in grouped_parameters:
|
|
@@ -131,6 +103,7 @@ def _serialize_grouped_body(builder) -> List[str]:
|
|
|
131
103
|
)
|
|
132
104
|
return retval
|
|
133
105
|
|
|
106
|
+
|
|
134
107
|
def _serialize_flattened_body(builder) -> List[str]:
|
|
135
108
|
retval: List[str] = []
|
|
136
109
|
if not builder.parameters.is_flattened:
|
|
@@ -142,8 +115,10 @@ def _serialize_flattened_body(builder) -> List[str]:
|
|
|
142
115
|
lambda parameter: parameter.in_method_code
|
|
143
116
|
)
|
|
144
117
|
parameter_string = ", ".join(
|
|
145
|
-
[
|
|
146
|
-
|
|
118
|
+
[
|
|
119
|
+
f"{param.target_property_name}={param.serialized_name}"
|
|
120
|
+
for param in parameters
|
|
121
|
+
if param.target_property_name
|
|
147
122
|
]
|
|
148
123
|
)
|
|
149
124
|
object_schema = cast(ObjectSchema, builder.parameters.body[0].schema)
|
|
@@ -152,23 +127,26 @@ def _serialize_flattened_body(builder) -> List[str]:
|
|
|
152
127
|
)
|
|
153
128
|
return retval
|
|
154
129
|
|
|
130
|
+
|
|
155
131
|
def _content_type_docstring(builder) -> str:
|
|
156
132
|
content_types = [f'"{c}"' for c in builder.parameters.content_types]
|
|
157
133
|
if len(content_types) == 2:
|
|
158
134
|
possible_values_str = " or ".join(content_types)
|
|
159
135
|
else:
|
|
160
|
-
possible_values_str =
|
|
161
|
-
content_types[: len(content_types) - 1]
|
|
162
|
-
|
|
136
|
+
possible_values_str = (
|
|
137
|
+
", ".join(content_types[: len(content_types) - 1])
|
|
138
|
+
+ f", and {content_types[-1]}"
|
|
139
|
+
)
|
|
163
140
|
default_value = next(
|
|
164
141
|
p for p in builder.parameters.method if p.rest_api_name == "Content-Type"
|
|
165
142
|
).default_value_declaration
|
|
166
143
|
return (
|
|
167
|
-
":keyword content_type: Media type of the body sent to the API. "
|
|
168
|
-
f"
|
|
169
|
-
f"Default value is {default_value}."
|
|
144
|
+
":keyword content_type: Media type of the body sent to the API. "
|
|
145
|
+
+ f"Known values are: {possible_values_str}. "
|
|
146
|
+
+ f"Default value is {default_value}."
|
|
170
147
|
)
|
|
171
148
|
|
|
149
|
+
|
|
172
150
|
class _BuilderSerializerProtocol(ABC):
|
|
173
151
|
@property
|
|
174
152
|
@abstractmethod
|
|
@@ -194,7 +172,9 @@ class _BuilderSerializerProtocol(ABC):
|
|
|
194
172
|
...
|
|
195
173
|
|
|
196
174
|
@abstractmethod
|
|
197
|
-
def _response_type_annotation(
|
|
175
|
+
def _response_type_annotation(
|
|
176
|
+
self, builder, modify_if_head_as_boolean: bool = True
|
|
177
|
+
) -> str:
|
|
198
178
|
"""The mypy type annotation for the response"""
|
|
199
179
|
...
|
|
200
180
|
|
|
@@ -213,7 +193,14 @@ class _BuilderSerializerProtocol(ABC):
|
|
|
213
193
|
...
|
|
214
194
|
|
|
215
195
|
@abstractmethod
|
|
216
|
-
def
|
|
196
|
+
def decorators(self, builder, async_mode: bool) -> List[str]:
|
|
197
|
+
"""Decorators for the method"""
|
|
198
|
+
...
|
|
199
|
+
|
|
200
|
+
@abstractmethod
|
|
201
|
+
def method_signature_and_response_type_annotation(
|
|
202
|
+
self, builder, async_mode: bool, *, want_decorators: Optional[bool] = True
|
|
203
|
+
) -> str:
|
|
217
204
|
"""Combines the method signature + the response type annotation together"""
|
|
218
205
|
...
|
|
219
206
|
|
|
@@ -243,13 +230,6 @@ class _BuilderSerializerProtocol(ABC):
|
|
|
243
230
|
def _has_json_example_template(self, builder) -> bool:
|
|
244
231
|
...
|
|
245
232
|
|
|
246
|
-
@abstractmethod
|
|
247
|
-
def _has_files_example_template(self, builder) -> bool:
|
|
248
|
-
...
|
|
249
|
-
@abstractmethod
|
|
250
|
-
def _has_data_example_template(self, builder) -> bool:
|
|
251
|
-
...
|
|
252
|
-
|
|
253
233
|
@abstractmethod
|
|
254
234
|
def _json_example_param_name(self, builder) -> str:
|
|
255
235
|
...
|
|
@@ -259,57 +239,98 @@ class _BuilderSerializerProtocol(ABC):
|
|
|
259
239
|
...
|
|
260
240
|
|
|
261
241
|
@abstractmethod
|
|
262
|
-
def _get_json_response_template_to_status_codes(
|
|
242
|
+
def _get_json_response_template_to_status_codes(
|
|
243
|
+
self, builder
|
|
244
|
+
) -> Dict[str, List[str]]:
|
|
263
245
|
...
|
|
264
246
|
|
|
265
247
|
@abstractmethod
|
|
266
248
|
def _get_kwargs_to_pop(self, builder) -> List[Parameter]:
|
|
267
249
|
...
|
|
268
250
|
|
|
269
|
-
|
|
251
|
+
|
|
252
|
+
class _BuilderBaseSerializer(
|
|
253
|
+
_BuilderSerializerProtocol
|
|
254
|
+
): # pylint: disable=abstract-method
|
|
270
255
|
def __init__(self, code_model: CodeModel) -> None:
|
|
271
256
|
self.code_model = code_model
|
|
272
257
|
|
|
273
258
|
@property
|
|
274
259
|
def _cls_docstring_rtype(self) -> str:
|
|
275
|
-
return
|
|
260
|
+
return (
|
|
261
|
+
""
|
|
262
|
+
if self.code_model.options["version_tolerant"]
|
|
263
|
+
else " or the result of cls(response)"
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
def decorators(self, builder, async_mode: bool) -> List[str]:
|
|
267
|
+
"""Decorators for the method"""
|
|
268
|
+
retval: List[str] = []
|
|
269
|
+
if self.code_model.options["tracing"] and builder.want_tracing:
|
|
270
|
+
retval.append(f"@distributed_trace{'_async' if async_mode else ''}")
|
|
271
|
+
return retval
|
|
276
272
|
|
|
277
|
-
def _method_signature(
|
|
273
|
+
def _method_signature(
|
|
274
|
+
self, builder: Operation, response_type_annotation: str
|
|
275
|
+
) -> str:
|
|
278
276
|
return utils.serialize_method(
|
|
279
277
|
function_def=self._function_definition,
|
|
280
278
|
method_name=builder.name,
|
|
281
279
|
is_in_class=self._is_in_class,
|
|
282
|
-
method_param_signatures=builder.
|
|
283
|
-
|
|
280
|
+
method_param_signatures=builder.method_signature(
|
|
281
|
+
self._want_inline_type_hints
|
|
282
|
+
),
|
|
283
|
+
ignore_inconsistent_return_statements=(response_type_annotation == "None"),
|
|
284
284
|
)
|
|
285
285
|
|
|
286
286
|
def _response_type_annotation_wrapper(self, builder) -> List[str]:
|
|
287
287
|
return []
|
|
288
288
|
|
|
289
|
-
def method_signature_and_response_type_annotation(
|
|
289
|
+
def method_signature_and_response_type_annotation(
|
|
290
|
+
self, builder, async_mode: bool, *, want_decorators: Optional[bool] = True
|
|
291
|
+
) -> str:
|
|
290
292
|
response_type_annotation = self._response_type_annotation(builder)
|
|
291
293
|
# want pre-wrapped response type. As long as it's None, pylint will get mad about inconsistent return types
|
|
292
294
|
method_signature = self._method_signature(builder, response_type_annotation)
|
|
293
295
|
for wrapper in self._response_type_annotation_wrapper(builder)[::-1]:
|
|
294
296
|
response_type_annotation = f"{wrapper}[{response_type_annotation}]"
|
|
295
|
-
|
|
297
|
+
decorators = self.decorators(builder, async_mode)
|
|
298
|
+
decorators_str = ""
|
|
299
|
+
if decorators and want_decorators:
|
|
300
|
+
decorators_str = "\n".join(decorators) + "\n"
|
|
301
|
+
return (
|
|
302
|
+
decorators_str
|
|
303
|
+
+ self._method_signature_and_response_type_annotation_template(
|
|
304
|
+
method_signature, response_type_annotation
|
|
305
|
+
)
|
|
306
|
+
)
|
|
296
307
|
|
|
297
308
|
def description_and_summary(self, builder) -> List[str]:
|
|
298
309
|
description_list: List[str] = []
|
|
299
|
-
description_list.append(
|
|
310
|
+
description_list.append(
|
|
311
|
+
f"{ builder.summary.strip() if builder.summary else builder.description.strip() }"
|
|
312
|
+
)
|
|
300
313
|
if builder.summary and builder.description:
|
|
301
314
|
description_list.append("")
|
|
302
315
|
description_list.append(builder.description.strip())
|
|
303
316
|
description_list.append("")
|
|
304
317
|
return description_list
|
|
305
318
|
|
|
306
|
-
def param_description(
|
|
319
|
+
def param_description( # pylint: disable=no-self-use
|
|
320
|
+
self, builder: Union[RequestBuilder, Operation]
|
|
321
|
+
) -> List[str]:
|
|
307
322
|
description_list: List[str] = []
|
|
308
|
-
for param in [
|
|
323
|
+
for param in [
|
|
324
|
+
m
|
|
325
|
+
for m in builder.parameters.method
|
|
326
|
+
if m.method_location != ParameterMethodLocation.HIDDEN_KWARG
|
|
327
|
+
]:
|
|
309
328
|
description_list.extend(
|
|
310
329
|
f":{param.description_keyword} { param.serialized_name }: { param.description }".replace(
|
|
311
330
|
"\n", "\n "
|
|
312
|
-
).split(
|
|
331
|
+
).split(
|
|
332
|
+
"\n"
|
|
333
|
+
)
|
|
313
334
|
)
|
|
314
335
|
description_list.append(
|
|
315
336
|
f":{param.docstring_type_keyword} { param.serialized_name }: { param.docstring_type }"
|
|
@@ -317,34 +338,43 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
317
338
|
|
|
318
339
|
if len(builder.parameters.content_types) > 1:
|
|
319
340
|
description_list = [
|
|
320
|
-
_content_type_docstring(builder)
|
|
341
|
+
_content_type_docstring(builder)
|
|
342
|
+
if l.startswith(":keyword content_type:")
|
|
343
|
+
else l
|
|
321
344
|
for l in description_list
|
|
322
345
|
]
|
|
323
|
-
if not any(
|
|
346
|
+
if not any(
|
|
347
|
+
l for l in description_list if l.startswith(":keyword content_type:")
|
|
348
|
+
):
|
|
324
349
|
description_list.append(_content_type_docstring(builder))
|
|
325
350
|
return description_list
|
|
326
351
|
|
|
327
352
|
def param_description_and_response_docstring(self, builder) -> List[str]:
|
|
353
|
+
if builder.abstract:
|
|
354
|
+
return []
|
|
328
355
|
return self.param_description(builder) + self.response_docstring(builder)
|
|
329
356
|
|
|
330
|
-
def _get_json_response_template_to_status_codes(
|
|
357
|
+
def _get_json_response_template_to_status_codes(
|
|
358
|
+
self, builder
|
|
359
|
+
) -> Dict[str, List[str]]:
|
|
331
360
|
# successful status codes of responses that have bodies
|
|
332
361
|
responses = [
|
|
333
362
|
response
|
|
334
363
|
for response in builder.responses
|
|
335
|
-
if any(
|
|
364
|
+
if any(
|
|
365
|
+
code in builder.success_status_code for code in response.status_codes
|
|
366
|
+
)
|
|
336
367
|
and isinstance(
|
|
337
|
-
response.schema,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
ObjectSchema,
|
|
341
|
-
EnumSchema
|
|
342
|
-
))
|
|
368
|
+
response.schema,
|
|
369
|
+
(DictionarySchema, ListSchema, ObjectSchema, EnumSchema),
|
|
370
|
+
)
|
|
343
371
|
]
|
|
344
372
|
retval = defaultdict(list)
|
|
345
373
|
for response in responses:
|
|
346
374
|
status_codes = [str(status_code) for status_code in response.status_codes]
|
|
347
|
-
response_json = _json_dumps_template(
|
|
375
|
+
response_json = _json_dumps_template(
|
|
376
|
+
cast(BaseSchema, response.schema).get_json_template_representation()
|
|
377
|
+
)
|
|
348
378
|
retval[response_json].extend(status_codes)
|
|
349
379
|
return retval
|
|
350
380
|
|
|
@@ -353,12 +383,6 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
353
383
|
if self._has_json_example_template(builder):
|
|
354
384
|
template.append("")
|
|
355
385
|
template += self._get_json_example_template(builder)
|
|
356
|
-
if self._has_files_example_template(builder):
|
|
357
|
-
template.append("")
|
|
358
|
-
template += _get_files_example_template(builder)
|
|
359
|
-
if self._has_data_example_template(builder):
|
|
360
|
-
template.append("")
|
|
361
|
-
template += _get_data_example_template(builder)
|
|
362
386
|
if self._get_json_response_template_to_status_codes(builder):
|
|
363
387
|
template.append("")
|
|
364
388
|
template += self._get_json_response_template(builder)
|
|
@@ -375,7 +399,11 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
375
399
|
discriminator_name = None
|
|
376
400
|
subtype_map = None
|
|
377
401
|
if subtype_map:
|
|
378
|
-
template.append(
|
|
402
|
+
template.append(
|
|
403
|
+
"{} = '{}'".format(
|
|
404
|
+
discriminator_name, "' or '".join(subtype_map.values())
|
|
405
|
+
)
|
|
406
|
+
)
|
|
379
407
|
template.append("")
|
|
380
408
|
|
|
381
409
|
try:
|
|
@@ -388,21 +416,30 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
388
416
|
for s in self.code_model.sorted_schemas
|
|
389
417
|
if s.name in property_with_discriminator.schema.subtype_map.values()
|
|
390
418
|
]
|
|
391
|
-
num_schemas = min(
|
|
419
|
+
num_schemas = min(
|
|
420
|
+
self.code_model.options["polymorphic_examples"],
|
|
421
|
+
len(polymorphic_schemas),
|
|
422
|
+
)
|
|
392
423
|
for i in range(num_schemas):
|
|
393
424
|
schema = polymorphic_schemas[i]
|
|
394
425
|
polymorphic_property = _json_dumps_template(
|
|
395
426
|
schema.get_json_template_representation(),
|
|
396
427
|
)
|
|
397
|
-
template.extend(
|
|
428
|
+
template.extend(
|
|
429
|
+
f"{property_with_discriminator.name} = {polymorphic_property}".splitlines()
|
|
430
|
+
)
|
|
398
431
|
if i != num_schemas - 1:
|
|
399
432
|
template.append("# OR")
|
|
400
433
|
template.append("")
|
|
401
|
-
template.append(
|
|
434
|
+
template.append(
|
|
435
|
+
"# JSON input template you can fill out and use as your body input."
|
|
436
|
+
)
|
|
402
437
|
json_template = _json_dumps_template(
|
|
403
438
|
builder.parameters.json_body.get_json_template_representation(),
|
|
404
439
|
)
|
|
405
|
-
template.extend(
|
|
440
|
+
template.extend(
|
|
441
|
+
f"{self._json_example_param_name(builder)} = {json_template}".splitlines()
|
|
442
|
+
)
|
|
406
443
|
return template
|
|
407
444
|
|
|
408
445
|
@property
|
|
@@ -410,34 +447,34 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
410
447
|
def serializer_name(self) -> str:
|
|
411
448
|
...
|
|
412
449
|
|
|
413
|
-
def _serialize_parameter(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
function_name,
|
|
450
|
+
def _serialize_parameter(self, param: Parameter, kwarg_name: str) -> List[str]:
|
|
451
|
+
function_name = "header" if kwarg_name == "headers" else "query"
|
|
452
|
+
set_parameter = "_{}['{}'] = {}".format(
|
|
453
|
+
kwarg_name,
|
|
418
454
|
param.rest_api_name,
|
|
419
|
-
utils.build_serialize_data_call(param, function_name, self.serializer_name)
|
|
455
|
+
utils.build_serialize_data_call(param, function_name, self.serializer_name),
|
|
420
456
|
)
|
|
421
457
|
if param.required:
|
|
422
458
|
retval = [set_parameter]
|
|
423
459
|
else:
|
|
424
460
|
retval = [
|
|
425
461
|
f"if {param.full_serialized_name} is not None:",
|
|
426
|
-
f" {set_parameter}"
|
|
462
|
+
f" {set_parameter}",
|
|
427
463
|
]
|
|
428
464
|
return retval
|
|
429
465
|
|
|
430
466
|
def _get_json_response_template(self, builder) -> List[str]:
|
|
431
467
|
template = []
|
|
432
|
-
for
|
|
433
|
-
|
|
468
|
+
for (
|
|
469
|
+
response_body,
|
|
470
|
+
status_codes,
|
|
471
|
+
) in self._get_json_response_template_to_status_codes(builder).items():
|
|
472
|
+
template.append(
|
|
473
|
+
"# response body for status code(s): {}".format(", ".join(status_codes))
|
|
474
|
+
)
|
|
434
475
|
template.extend(f"response.json() == {response_body}".splitlines())
|
|
435
476
|
return template
|
|
436
477
|
|
|
437
|
-
|
|
438
|
-
def pop_kwargs_from_signature(self, builder) -> List[str]:
|
|
439
|
-
return utils.pop_kwargs_from_signature(self._get_kwargs_to_pop(builder))
|
|
440
|
-
|
|
441
478
|
def serialize_path(self, builder) -> List[str]:
|
|
442
479
|
return utils.serialize_path(builder.parameters.path, self.serializer_name)
|
|
443
480
|
|
|
@@ -449,7 +486,9 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
449
486
|
############################## REQUEST BUILDERS ##############################
|
|
450
487
|
|
|
451
488
|
|
|
452
|
-
class _RequestBuilderBaseSerializer(
|
|
489
|
+
class _RequestBuilderBaseSerializer(
|
|
490
|
+
_BuilderBaseSerializer
|
|
491
|
+
): # pylint: disable=abstract-method
|
|
453
492
|
def description_and_summary(self, builder) -> List[str]:
|
|
454
493
|
retval = super().description_and_summary(builder)
|
|
455
494
|
retval += [
|
|
@@ -463,7 +502,29 @@ class _RequestBuilderBaseSerializer(_BuilderBaseSerializer): # pylint: disable=
|
|
|
463
502
|
def serializer_name(self) -> str:
|
|
464
503
|
return "_SERIALIZER"
|
|
465
504
|
|
|
505
|
+
@staticmethod
|
|
506
|
+
def declare_non_inputtable_constants(builder) -> List[str]:
|
|
507
|
+
def _get_value(param: Parameter):
|
|
508
|
+
if param.location in [ParameterLocation.Header, ParameterLocation.Query]:
|
|
509
|
+
kwarg_dict = (
|
|
510
|
+
"headers"
|
|
511
|
+
if param.location == ParameterLocation.Header
|
|
512
|
+
else "params"
|
|
513
|
+
)
|
|
514
|
+
return f"_{kwarg_dict}.pop('{param.rest_api_name}', {param.constant_declaration})"
|
|
515
|
+
return f"{param.constant_declaration}"
|
|
516
|
+
|
|
517
|
+
return [
|
|
518
|
+
f"{p.serialized_name} = {_get_value(p)}"
|
|
519
|
+
for p in builder.parameters.constant
|
|
520
|
+
if p.original_parameter is None
|
|
521
|
+
and p.in_method_code
|
|
522
|
+
and not p.in_method_signature
|
|
523
|
+
]
|
|
524
|
+
|
|
466
525
|
def want_example_template(self, builder) -> bool:
|
|
526
|
+
if builder.abstract:
|
|
527
|
+
return False
|
|
467
528
|
if self.code_model.options["builders_visibility"] != "public":
|
|
468
529
|
return False # if we're not exposing rest layer, don't need to generate
|
|
469
530
|
if builder.parameters.has_body:
|
|
@@ -479,7 +540,9 @@ class _RequestBuilderBaseSerializer(_BuilderBaseSerializer): # pylint: disable=
|
|
|
479
540
|
def _is_in_class(self) -> bool:
|
|
480
541
|
return False
|
|
481
542
|
|
|
482
|
-
def _response_type_annotation(
|
|
543
|
+
def _response_type_annotation(
|
|
544
|
+
self, builder, modify_if_head_as_boolean: bool = True
|
|
545
|
+
) -> str:
|
|
483
546
|
return "HttpRequest"
|
|
484
547
|
|
|
485
548
|
def response_docstring(self, builder) -> List[str]:
|
|
@@ -497,76 +560,101 @@ class _RequestBuilderBaseSerializer(_BuilderBaseSerializer): # pylint: disable=
|
|
|
497
560
|
def _has_json_example_template(self, builder) -> bool:
|
|
498
561
|
return "json" in builder.parameters.body_kwarg_names
|
|
499
562
|
|
|
500
|
-
def _has_files_example_template(self, builder) -> bool:
|
|
501
|
-
return "files" in builder.parameters.body_kwarg_names
|
|
502
|
-
|
|
503
|
-
def _has_data_example_template(self, builder) -> bool:
|
|
504
|
-
return "data" in builder.parameters.body_kwarg_names
|
|
505
|
-
|
|
506
563
|
@abstractmethod
|
|
507
564
|
def _body_params_to_pass_to_request_creation(self, builder) -> List[str]:
|
|
508
565
|
...
|
|
509
566
|
|
|
567
|
+
def pop_kwargs_from_signature(self, builder) -> List[str]:
|
|
568
|
+
return utils.pop_kwargs_from_signature(
|
|
569
|
+
self._get_kwargs_to_pop(builder),
|
|
570
|
+
check_kwarg_dict=True,
|
|
571
|
+
pop_headers_kwarg=utils.PopKwargType.CASE_INSENSITIVE
|
|
572
|
+
if bool(builder.parameters.headers)
|
|
573
|
+
else utils.PopKwargType.NO,
|
|
574
|
+
pop_params_kwarg=utils.PopKwargType.CASE_INSENSITIVE
|
|
575
|
+
if bool(builder.parameters.query)
|
|
576
|
+
else utils.PopKwargType.NO,
|
|
577
|
+
)
|
|
578
|
+
|
|
510
579
|
def create_http_request(self, builder) -> List[str]:
|
|
511
580
|
retval = ["return HttpRequest("]
|
|
512
581
|
retval.append(f' method="{builder.method}",')
|
|
513
582
|
retval.append(" url=_url,")
|
|
514
583
|
if builder.parameters.query:
|
|
515
|
-
retval.append(" params=
|
|
584
|
+
retval.append(" params=_params,")
|
|
516
585
|
if builder.parameters.headers:
|
|
517
|
-
retval.append(" headers=
|
|
586
|
+
retval.append(" headers=_headers,")
|
|
518
587
|
if builder.parameters.has_body:
|
|
519
|
-
retval.extend(
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
588
|
+
retval.extend(
|
|
589
|
+
[
|
|
590
|
+
f" {body_kwarg}={body_kwarg},"
|
|
591
|
+
for body_kwarg in self._body_params_to_pass_to_request_creation(
|
|
592
|
+
builder
|
|
593
|
+
)
|
|
594
|
+
]
|
|
595
|
+
)
|
|
523
596
|
retval.append(" **kwargs")
|
|
524
597
|
retval.append(")")
|
|
525
598
|
return retval
|
|
526
599
|
|
|
527
600
|
def serialize_headers(self, builder) -> List[str]:
|
|
528
601
|
retval = ["# Construct headers"]
|
|
529
|
-
retval.append(_pop_parameters_kwarg("header", "headers"))
|
|
530
602
|
for parameter in builder.parameters.headers:
|
|
531
|
-
retval.extend(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
603
|
+
retval.extend(
|
|
604
|
+
self._serialize_parameter(
|
|
605
|
+
parameter,
|
|
606
|
+
kwarg_name="headers",
|
|
607
|
+
)
|
|
608
|
+
)
|
|
535
609
|
return retval
|
|
536
610
|
|
|
537
611
|
def serialize_query(self, builder) -> List[str]:
|
|
538
612
|
retval = ["# Construct parameters"]
|
|
539
|
-
retval.append(_pop_parameters_kwarg("query", "params"))
|
|
540
613
|
for parameter in builder.parameters.query:
|
|
541
|
-
retval.extend(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
614
|
+
retval.extend(
|
|
615
|
+
self._serialize_parameter(
|
|
616
|
+
parameter,
|
|
617
|
+
kwarg_name="params",
|
|
618
|
+
)
|
|
619
|
+
)
|
|
545
620
|
return retval
|
|
546
621
|
|
|
547
622
|
def construct_url(self, builder) -> str:
|
|
548
|
-
if any(
|
|
623
|
+
if any(
|
|
624
|
+
o
|
|
625
|
+
for o in ["low_level_client", "version_tolerant"]
|
|
626
|
+
if self.code_model.options.get(o)
|
|
627
|
+
):
|
|
549
628
|
url_value = _escape_str(builder.url)
|
|
550
629
|
else:
|
|
551
630
|
url_value = f'kwargs.pop("template_url", {_escape_str(builder.url)})'
|
|
552
631
|
return f"_url = {url_value}{' # pylint: disable=line-too-long' if len(url_value) > 114 else ''}"
|
|
553
632
|
|
|
633
|
+
|
|
554
634
|
class RequestBuilderGenericSerializer(_RequestBuilderBaseSerializer):
|
|
555
635
|
@property
|
|
556
636
|
def _want_inline_type_hints(self) -> bool:
|
|
557
637
|
return False
|
|
558
638
|
|
|
559
639
|
@staticmethod
|
|
560
|
-
def _method_signature_and_response_type_annotation_template(
|
|
640
|
+
def _method_signature_and_response_type_annotation_template(
|
|
641
|
+
method_signature: str, response_type_annotation: str
|
|
642
|
+
):
|
|
561
643
|
return utils.method_signature_and_response_type_annotation_template(
|
|
562
|
-
is_python3_file=False,
|
|
644
|
+
is_python3_file=False,
|
|
645
|
+
method_signature=method_signature,
|
|
646
|
+
response_type_annotation=response_type_annotation,
|
|
563
647
|
)
|
|
564
648
|
|
|
565
649
|
def _get_kwargs_to_pop(self, builder):
|
|
566
650
|
return builder.parameters.kwargs_to_pop(is_python3_file=False)
|
|
567
651
|
|
|
568
652
|
def _body_params_to_pass_to_request_creation(self, builder) -> List[str]:
|
|
569
|
-
if
|
|
653
|
+
if any(
|
|
654
|
+
b
|
|
655
|
+
for b in builder.parameters.body
|
|
656
|
+
if b.constant and not (b.is_data_input or b.is_multipart)
|
|
657
|
+
):
|
|
570
658
|
# this means we have a constant body
|
|
571
659
|
# only doing json body in this case
|
|
572
660
|
return ["json"]
|
|
@@ -579,9 +667,13 @@ class RequestBuilderPython3Serializer(_RequestBuilderBaseSerializer):
|
|
|
579
667
|
return True
|
|
580
668
|
|
|
581
669
|
@staticmethod
|
|
582
|
-
def _method_signature_and_response_type_annotation_template(
|
|
670
|
+
def _method_signature_and_response_type_annotation_template(
|
|
671
|
+
method_signature: str, response_type_annotation: str
|
|
672
|
+
):
|
|
583
673
|
return utils.method_signature_and_response_type_annotation_template(
|
|
584
|
-
is_python3_file=True,
|
|
674
|
+
is_python3_file=True,
|
|
675
|
+
method_signature=method_signature,
|
|
676
|
+
response_type_annotation=response_type_annotation,
|
|
585
677
|
)
|
|
586
678
|
|
|
587
679
|
def _get_kwargs_to_pop(self, builder):
|
|
@@ -591,9 +683,11 @@ class RequestBuilderPython3Serializer(_RequestBuilderBaseSerializer):
|
|
|
591
683
|
body_kwargs = list(builder.parameters.body_kwarg_names.keys())
|
|
592
684
|
if body_kwargs:
|
|
593
685
|
return body_kwargs
|
|
594
|
-
if
|
|
595
|
-
|
|
596
|
-
|
|
686
|
+
if any(
|
|
687
|
+
b
|
|
688
|
+
for b in builder.parameters.body
|
|
689
|
+
if b.constant and not (b.is_data_input or b.is_multipart)
|
|
690
|
+
):
|
|
597
691
|
return ["json"]
|
|
598
692
|
return body_kwargs
|
|
599
693
|
|
|
@@ -601,7 +695,9 @@ class RequestBuilderPython3Serializer(_RequestBuilderBaseSerializer):
|
|
|
601
695
|
############################## NORMAL OPERATIONS ##############################
|
|
602
696
|
|
|
603
697
|
|
|
604
|
-
class _OperationBaseSerializer(
|
|
698
|
+
class _OperationBaseSerializer(
|
|
699
|
+
_BuilderBaseSerializer
|
|
700
|
+
): # pylint: disable=abstract-method
|
|
605
701
|
def description_and_summary(self, builder) -> List[str]:
|
|
606
702
|
retval = super().description_and_summary(builder)
|
|
607
703
|
if builder.deprecated:
|
|
@@ -618,7 +714,16 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
618
714
|
def serializer_name(self) -> str:
|
|
619
715
|
return "self._serialize"
|
|
620
716
|
|
|
621
|
-
def
|
|
717
|
+
def decorators(self, builder, async_mode: bool) -> List[str]:
|
|
718
|
+
"""Decorators for the method"""
|
|
719
|
+
super_decorators = super().decorators(builder, async_mode)
|
|
720
|
+
if builder.abstract:
|
|
721
|
+
super_decorators.append("@abc.abstractmethod")
|
|
722
|
+
return super_decorators
|
|
723
|
+
|
|
724
|
+
def _response_docstring_type_wrapper( # pylint: disable=unused-argument, no-self-use
|
|
725
|
+
self, builder
|
|
726
|
+
) -> List[str]:
|
|
622
727
|
return []
|
|
623
728
|
|
|
624
729
|
def param_description(self, builder) -> List[str]: # pylint: disable=no-self-use
|
|
@@ -635,7 +740,9 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
635
740
|
retval = f"{wrapper}[{retval}]"
|
|
636
741
|
return retval
|
|
637
742
|
|
|
638
|
-
def _response_type_annotation(
|
|
743
|
+
def _response_type_annotation(
|
|
744
|
+
self, builder, modify_if_head_as_boolean: bool = True
|
|
745
|
+
) -> str:
|
|
639
746
|
if (
|
|
640
747
|
modify_if_head_as_boolean
|
|
641
748
|
and builder.request_builder.method.lower() == "head"
|
|
@@ -644,7 +751,9 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
644
751
|
return "bool"
|
|
645
752
|
response_body_annotations: OrderedSet[str] = {}
|
|
646
753
|
for response in [r for r in builder.responses if r.has_body]:
|
|
647
|
-
response_body_annotations[
|
|
754
|
+
response_body_annotations[
|
|
755
|
+
response.type_annotation(is_operation_file=True)
|
|
756
|
+
] = None
|
|
648
757
|
response_str = ", ".join(response_body_annotations.keys()) or "None"
|
|
649
758
|
if len(response_body_annotations) > 1:
|
|
650
759
|
response_str = f"Union[{response_str}]"
|
|
@@ -652,16 +761,42 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
652
761
|
response_str = f"Optional[{response_str}]"
|
|
653
762
|
return response_str
|
|
654
763
|
|
|
764
|
+
def pop_kwargs_from_signature(self, builder) -> List[str]:
|
|
765
|
+
kwargs_to_pop = self._get_kwargs_to_pop(builder)
|
|
766
|
+
kwargs = utils.pop_kwargs_from_signature(
|
|
767
|
+
kwargs_to_pop,
|
|
768
|
+
check_kwarg_dict=True,
|
|
769
|
+
pop_headers_kwarg=utils.PopKwargType.CASE_INSENSITIVE
|
|
770
|
+
if builder.has_kwargs_to_pop_with_default(
|
|
771
|
+
kwargs_to_pop, ParameterLocation.Header
|
|
772
|
+
)
|
|
773
|
+
else utils.PopKwargType.SIMPLE,
|
|
774
|
+
pop_params_kwarg=utils.PopKwargType.CASE_INSENSITIVE
|
|
775
|
+
if builder.has_kwargs_to_pop_with_default(
|
|
776
|
+
kwargs_to_pop, ParameterLocation.Query
|
|
777
|
+
)
|
|
778
|
+
else utils.PopKwargType.SIMPLE,
|
|
779
|
+
)
|
|
780
|
+
kwargs.append(
|
|
781
|
+
f"cls = kwargs.pop('cls', None) {self.cls_type_annotation(builder)}"
|
|
782
|
+
)
|
|
783
|
+
return kwargs
|
|
784
|
+
|
|
655
785
|
def cls_type_annotation(self, builder) -> str:
|
|
656
786
|
return f"# type: ClsType[{self._response_type_annotation(builder, modify_if_head_as_boolean=False)}]"
|
|
657
787
|
|
|
658
|
-
def _response_docstring_text_template(
|
|
788
|
+
def _response_docstring_text_template( # pylint: disable=no-self-use, unused-argument
|
|
789
|
+
self, builder
|
|
790
|
+
) -> str:
|
|
659
791
|
cls_str = f",{self._cls_docstring_rtype}" if self._cls_docstring_rtype else ""
|
|
660
792
|
return "{}" + cls_str
|
|
661
793
|
|
|
662
794
|
def response_docstring(self, builder) -> List[str]:
|
|
663
795
|
responses_with_body = [r for r in builder.responses if r.has_body]
|
|
664
|
-
if
|
|
796
|
+
if (
|
|
797
|
+
builder.request_builder.method.lower() == "head"
|
|
798
|
+
and self.code_model.options["head_as_boolean"]
|
|
799
|
+
):
|
|
665
800
|
response_docstring_text = "bool"
|
|
666
801
|
rtype = "bool"
|
|
667
802
|
elif responses_with_body:
|
|
@@ -679,36 +814,46 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
679
814
|
response_docstring_text = "None"
|
|
680
815
|
rtype = "None"
|
|
681
816
|
response_str = f":return: {self._response_docstring_text_template(builder).format(response_docstring_text)}"
|
|
682
|
-
rtype_str =
|
|
683
|
-
|
|
817
|
+
rtype_str = (
|
|
818
|
+
f":rtype: {self._response_docstring_type_template(builder).format(rtype)}"
|
|
819
|
+
)
|
|
820
|
+
return [
|
|
821
|
+
response_str,
|
|
822
|
+
rtype_str,
|
|
823
|
+
":raises: ~azure.core.exceptions.HttpResponseError",
|
|
824
|
+
]
|
|
684
825
|
|
|
685
826
|
def want_example_template(self, builder) -> bool:
|
|
686
|
-
if
|
|
827
|
+
if builder.abstract:
|
|
828
|
+
return False
|
|
829
|
+
if self.code_model.options["models_mode"]:
|
|
687
830
|
return False
|
|
688
831
|
if builder.parameters.has_body:
|
|
689
|
-
if builder.parameters.multipart or builder.parameters.data_inputs:
|
|
690
|
-
return True
|
|
691
832
|
body_params = builder.parameters.body
|
|
692
|
-
return any(
|
|
833
|
+
return any(
|
|
834
|
+
[
|
|
835
|
+
b
|
|
836
|
+
for b in body_params
|
|
837
|
+
if isinstance(
|
|
838
|
+
b.schema, (DictionarySchema, ListSchema, ObjectSchema)
|
|
839
|
+
)
|
|
840
|
+
]
|
|
841
|
+
)
|
|
693
842
|
return bool(self._get_json_response_template_to_status_codes(builder))
|
|
694
843
|
|
|
695
844
|
def _json_example_param_name(self, builder) -> str:
|
|
696
845
|
return builder.parameters.body[0].serialized_name
|
|
697
846
|
|
|
698
847
|
def _has_json_example_template(self, builder) -> bool:
|
|
699
|
-
return
|
|
700
|
-
builder.parameters.has_body and
|
|
701
|
-
not (builder.parameters.multipart or builder.parameters.data_inputs)
|
|
702
|
-
)
|
|
703
|
-
|
|
704
|
-
def _has_files_example_template(self, builder) -> bool:
|
|
705
|
-
return bool(builder.parameters.multipart)
|
|
706
|
-
|
|
707
|
-
def _has_data_example_template(self, builder) -> bool:
|
|
708
|
-
return bool(builder.parameters.data_inputs)
|
|
848
|
+
return builder.parameters.has_body
|
|
709
849
|
|
|
710
850
|
def _serialize_body_call(
|
|
711
|
-
self,
|
|
851
|
+
self,
|
|
852
|
+
builder,
|
|
853
|
+
body_param: Parameter,
|
|
854
|
+
send_xml: bool,
|
|
855
|
+
ser_ctxt: Optional[str],
|
|
856
|
+
ser_ctxt_name: str,
|
|
712
857
|
) -> str:
|
|
713
858
|
body_is_xml = ", is_xml=True" if send_xml else ""
|
|
714
859
|
pass_ser_ctxt = f", {ser_ctxt_name}={ser_ctxt_name}" if ser_ctxt else ""
|
|
@@ -720,15 +865,19 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
720
865
|
)
|
|
721
866
|
return f"_{body_kwarg_to_pass} = {body_param.serialized_name}"
|
|
722
867
|
|
|
723
|
-
def _serialize_body(
|
|
868
|
+
def _serialize_body(
|
|
869
|
+
self, builder, body_param: Parameter, body_kwarg: str
|
|
870
|
+
) -> List[str]:
|
|
724
871
|
retval = []
|
|
725
872
|
send_xml = bool(
|
|
726
|
-
builder.parameters.has_body
|
|
727
|
-
any(["xml" in ct for ct in builder.parameters.content_types])
|
|
728
|
-
not isinstance(body_param.schema, IOSchema)
|
|
873
|
+
builder.parameters.has_body
|
|
874
|
+
and any(["xml" in ct for ct in builder.parameters.content_types])
|
|
875
|
+
and not isinstance(body_param.schema, IOSchema)
|
|
729
876
|
)
|
|
730
877
|
ser_ctxt_name = "serialization_ctxt"
|
|
731
|
-
ser_ctxt =
|
|
878
|
+
ser_ctxt = (
|
|
879
|
+
builder.parameters.body[0].xml_serialization_ctxt if send_xml else None
|
|
880
|
+
)
|
|
732
881
|
if ser_ctxt and self.code_model.options["models_mode"]:
|
|
733
882
|
retval.append(f'{ser_ctxt_name} = {{"xml": {{{ser_ctxt}}}}}')
|
|
734
883
|
serialize_body_call = self._serialize_body_call(
|
|
@@ -752,25 +901,31 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
752
901
|
self, builder, body_param: Parameter, body_kwarg: Parameter
|
|
753
902
|
) -> List[str]:
|
|
754
903
|
retval: List[str] = []
|
|
755
|
-
if
|
|
904
|
+
if (
|
|
905
|
+
body_kwarg.serialized_name == "data"
|
|
906
|
+
or body_kwarg.serialized_name == "files"
|
|
907
|
+
):
|
|
756
908
|
return retval
|
|
757
909
|
try:
|
|
758
910
|
if not body_param.style == ParameterStyle.binary:
|
|
759
|
-
retval.extend(
|
|
911
|
+
retval.extend(
|
|
912
|
+
self._serialize_body(
|
|
913
|
+
builder, body_param, body_kwarg.serialized_name
|
|
914
|
+
)
|
|
915
|
+
)
|
|
760
916
|
return retval
|
|
761
917
|
except AttributeError:
|
|
762
918
|
pass
|
|
763
919
|
retval.append(f"_{body_kwarg.serialized_name} = {body_param.serialized_name}")
|
|
764
920
|
return retval
|
|
765
921
|
|
|
766
|
-
|
|
767
922
|
def _serialize_body_parameters(
|
|
768
|
-
self,
|
|
923
|
+
self,
|
|
924
|
+
builder,
|
|
769
925
|
) -> List[str]:
|
|
770
926
|
retval = []
|
|
771
927
|
body_kwargs = [
|
|
772
|
-
p for p in builder.request_builder.parameters.body
|
|
773
|
-
if p.content_types
|
|
928
|
+
p for p in builder.request_builder.parameters.body if p.content_types
|
|
774
929
|
]
|
|
775
930
|
builder_params = []
|
|
776
931
|
if builder.parameters.has_body:
|
|
@@ -778,23 +933,34 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
778
933
|
if builder.multiple_content_type_parameters.has_body:
|
|
779
934
|
builder_params += builder.multiple_content_type_parameters.body
|
|
780
935
|
if len(body_kwargs) == 1:
|
|
781
|
-
retval.extend(
|
|
936
|
+
retval.extend(
|
|
937
|
+
self._set_body_content_kwarg(
|
|
938
|
+
builder, builder.parameters.body[0], body_kwargs[0]
|
|
939
|
+
)
|
|
940
|
+
)
|
|
782
941
|
else:
|
|
942
|
+
retval.append('content_type = content_type or ""')
|
|
783
943
|
for idx, body_kwarg in enumerate(body_kwargs):
|
|
784
944
|
body_param = next(
|
|
785
|
-
b for b in builder_params
|
|
786
|
-
if body_kwarg in b.body_kwargs
|
|
945
|
+
b for b in builder_params if body_kwarg in b.body_kwargs
|
|
787
946
|
)
|
|
788
947
|
if_statement = "if" if idx == 0 else "elif"
|
|
789
948
|
retval.append(
|
|
790
949
|
f'{if_statement} content_type.split(";")[0] in {body_kwarg.pre_semicolon_content_types}:'
|
|
791
950
|
)
|
|
792
|
-
retval.extend(
|
|
951
|
+
retval.extend(
|
|
952
|
+
[
|
|
953
|
+
" " + line
|
|
954
|
+
for line in self._set_body_content_kwarg(
|
|
955
|
+
builder, body_param, body_kwarg
|
|
956
|
+
)
|
|
957
|
+
]
|
|
958
|
+
)
|
|
793
959
|
retval.extend(_content_type_error_check(builder))
|
|
794
960
|
|
|
795
961
|
return retval
|
|
796
962
|
|
|
797
|
-
def _call_request_builder_helper(
|
|
963
|
+
def _call_request_builder_helper( # pylint: disable=too-many-statements
|
|
798
964
|
self,
|
|
799
965
|
builder,
|
|
800
966
|
request_builder: RequestBuilder,
|
|
@@ -806,7 +972,9 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
806
972
|
# special case for files, bc we hardcode body param to be called 'files' for multipart
|
|
807
973
|
body_params_to_initialize = builder.body_kwargs_to_pass_to_request_builder
|
|
808
974
|
if self.code_model.options["version_tolerant"]:
|
|
809
|
-
body_params_to_initialize = [
|
|
975
|
+
body_params_to_initialize = [
|
|
976
|
+
p for p in body_params_to_initialize if p != "files"
|
|
977
|
+
]
|
|
810
978
|
for k in body_params_to_initialize:
|
|
811
979
|
retval.append(f"_{k} = None")
|
|
812
980
|
if builder.parameters.grouped:
|
|
@@ -828,36 +996,46 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
828
996
|
else:
|
|
829
997
|
builder_group_name = request_builder.builder_group_name
|
|
830
998
|
request_path_name = "rest{}.{}".format(
|
|
831
|
-
("_" + builder_group_name) if builder_group_name else "",
|
|
999
|
+
("_" + builder_group_name) if builder_group_name else "",
|
|
1000
|
+
request_builder.name,
|
|
832
1001
|
)
|
|
833
1002
|
retval.append("")
|
|
834
1003
|
retval.append(f"request = {request_path_name}(")
|
|
835
1004
|
for parameter in request_builder.parameters.method:
|
|
836
1005
|
if (
|
|
837
|
-
parameter.is_body
|
|
838
|
-
not parameter.constant
|
|
839
|
-
parameter.serialized_name
|
|
1006
|
+
parameter.is_body
|
|
1007
|
+
and not parameter.constant
|
|
1008
|
+
and parameter.serialized_name
|
|
1009
|
+
not in builder.body_kwargs_to_pass_to_request_builder
|
|
840
1010
|
):
|
|
841
1011
|
continue
|
|
842
1012
|
if (
|
|
843
|
-
is_next_request
|
|
844
|
-
not bool(builder.next_request_builder)
|
|
845
|
-
not self.code_model.options["reformat_next_link"]
|
|
846
|
-
parameter.location == ParameterLocation.Query
|
|
1013
|
+
is_next_request
|
|
1014
|
+
and not bool(builder.next_request_builder)
|
|
1015
|
+
and not self.code_model.options["reformat_next_link"]
|
|
1016
|
+
and parameter.location == ParameterLocation.Query
|
|
847
1017
|
):
|
|
848
1018
|
# if we don't want to reformat query parameters for next link calls
|
|
849
1019
|
# in paging operations with a single swagger operation defintion,
|
|
850
1020
|
# we skip passing query params when building the next request
|
|
851
1021
|
continue
|
|
852
|
-
high_level_name = cast(
|
|
1022
|
+
high_level_name = cast(
|
|
1023
|
+
RequestBuilderParameter, parameter
|
|
1024
|
+
).name_in_high_level_operation
|
|
853
1025
|
retval.append(f" {parameter.serialized_name}={high_level_name},")
|
|
854
1026
|
if not self.code_model.options["version_tolerant"]:
|
|
1027
|
+
if builder.parameters.multipart:
|
|
1028
|
+
retval.append(f" files=_files,")
|
|
1029
|
+
if builder.parameters.data_inputs:
|
|
1030
|
+
retval.append(f" data=_data,")
|
|
855
1031
|
template_url = template_url or f"self.{builder.name}.metadata['url']"
|
|
856
1032
|
retval.append(f" template_url={template_url},")
|
|
1033
|
+
retval.append(" headers=_headers,")
|
|
1034
|
+
retval.append(" params=_params,")
|
|
857
1035
|
retval.append(f")")
|
|
858
1036
|
if not self.code_model.options["version_tolerant"]:
|
|
859
1037
|
pass_files = ""
|
|
860
|
-
if
|
|
1038
|
+
if builder.parameters.multipart:
|
|
861
1039
|
pass_files = ", _files"
|
|
862
1040
|
retval.append(f"request = _convert_request(request{pass_files})")
|
|
863
1041
|
if builder.parameters.path:
|
|
@@ -866,9 +1044,9 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
866
1044
|
if self.code_model.options["version_tolerant"] and template_url:
|
|
867
1045
|
url_to_format = template_url
|
|
868
1046
|
retval.append(
|
|
869
|
-
"request.url = self._client.format_url({}{})".format(
|
|
1047
|
+
"request.url = self._client.format_url({}{}) # type: ignore".format(
|
|
870
1048
|
url_to_format,
|
|
871
|
-
", **path_format_arguments" if builder.parameters.path else ""
|
|
1049
|
+
", **path_format_arguments" if builder.parameters.path else "",
|
|
872
1050
|
)
|
|
873
1051
|
)
|
|
874
1052
|
return retval
|
|
@@ -892,21 +1070,25 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
892
1070
|
if response.is_stream_response:
|
|
893
1071
|
retval.append(
|
|
894
1072
|
"deserialized = {}".format(
|
|
895
|
-
"response"
|
|
1073
|
+
"response"
|
|
1074
|
+
if self.code_model.options["version_tolerant"]
|
|
896
1075
|
else "response.stream_download(self._client._pipeline)"
|
|
897
1076
|
)
|
|
898
1077
|
)
|
|
899
1078
|
elif response.has_body:
|
|
900
1079
|
if self.code_model.options["models_mode"]:
|
|
901
|
-
retval.append(
|
|
1080
|
+
retval.append(
|
|
1081
|
+
f"deserialized = self._deserialize('{response.serialization_type}', pipeline_response)"
|
|
1082
|
+
)
|
|
902
1083
|
else:
|
|
903
1084
|
is_xml = any(["xml" in ct for ct in response.content_types])
|
|
904
|
-
deserialized_value =
|
|
905
|
-
|
|
1085
|
+
deserialized_value = (
|
|
1086
|
+
"ET.fromstring(response.text())" if is_xml else "response.json()"
|
|
1087
|
+
)
|
|
906
1088
|
retval.append(f"if response.content:")
|
|
907
1089
|
retval.append(f" deserialized = {deserialized_value}")
|
|
908
1090
|
retval.append("else:")
|
|
909
|
-
retval.append(" deserialized = None")
|
|
1091
|
+
retval.append(f" deserialized = None")
|
|
910
1092
|
return retval
|
|
911
1093
|
|
|
912
1094
|
@property
|
|
@@ -916,17 +1098,23 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
916
1098
|
|
|
917
1099
|
def handle_error_response(self, builder) -> List[str]:
|
|
918
1100
|
retval = [f"if response.status_code not in {str(builder.success_status_code)}:"]
|
|
919
|
-
retval.append(
|
|
1101
|
+
retval.append(
|
|
1102
|
+
" map_error(status_code=response.status_code, response=response, error_map=error_map)"
|
|
1103
|
+
)
|
|
920
1104
|
error_model = ""
|
|
921
1105
|
if builder.default_exception and self.code_model.options["models_mode"]:
|
|
922
1106
|
retval.append(
|
|
923
1107
|
f" error = self._deserialize.failsafe_deserialize({builder.default_exception}, pipeline_response)"
|
|
924
1108
|
)
|
|
925
1109
|
error_model = ", model=error"
|
|
926
|
-
retval.append(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
1110
|
+
retval.append(
|
|
1111
|
+
" raise HttpResponseError(response=response{}{})".format(
|
|
1112
|
+
error_model,
|
|
1113
|
+
", error_format=ARMErrorFormat"
|
|
1114
|
+
if self.code_model.options["azure_arm"]
|
|
1115
|
+
else "",
|
|
1116
|
+
)
|
|
1117
|
+
)
|
|
930
1118
|
return retval
|
|
931
1119
|
|
|
932
1120
|
def handle_response(self, builder) -> List[str]:
|
|
@@ -944,25 +1132,40 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
944
1132
|
response = builder.get_response_from_status(status_code)
|
|
945
1133
|
if response.headers or response.has_body:
|
|
946
1134
|
retval.append(f"if response.status_code == {status_code}:")
|
|
947
|
-
retval.extend(
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1135
|
+
retval.extend(
|
|
1136
|
+
[
|
|
1137
|
+
f" {line}"
|
|
1138
|
+
for line in self.response_headers_and_deserialization(
|
|
1139
|
+
response
|
|
1140
|
+
)
|
|
1141
|
+
]
|
|
1142
|
+
)
|
|
951
1143
|
retval.append("")
|
|
952
1144
|
else:
|
|
953
|
-
retval.extend(
|
|
954
|
-
builder.responses[0]
|
|
955
|
-
)
|
|
1145
|
+
retval.extend(
|
|
1146
|
+
self.response_headers_and_deserialization(builder.responses[0])
|
|
1147
|
+
)
|
|
956
1148
|
retval.append("")
|
|
1149
|
+
if builder.has_optional_return_type or self.code_model.options["models_mode"]:
|
|
1150
|
+
deserialized = "deserialized"
|
|
1151
|
+
else:
|
|
1152
|
+
deserialized = (
|
|
1153
|
+
f"cast({self._response_type_annotation(builder)}, deserialized)"
|
|
1154
|
+
)
|
|
957
1155
|
retval.append("if cls:")
|
|
958
|
-
retval.append(
|
|
959
|
-
"
|
|
960
|
-
|
|
961
|
-
|
|
1156
|
+
retval.append(
|
|
1157
|
+
" return cls(pipeline_response, {}, {})".format(
|
|
1158
|
+
deserialized if builder.has_response_body else "None",
|
|
1159
|
+
"response_headers" if builder.any_response_has_headers else "{}",
|
|
1160
|
+
)
|
|
1161
|
+
)
|
|
962
1162
|
if builder.has_response_body:
|
|
963
1163
|
retval.append("")
|
|
964
|
-
retval.append("return deserialized")
|
|
965
|
-
if
|
|
1164
|
+
retval.append(f"return {deserialized}")
|
|
1165
|
+
if (
|
|
1166
|
+
builder.request_builder.method == "HEAD"
|
|
1167
|
+
and self.code_model.options["head_as_boolean"]
|
|
1168
|
+
):
|
|
966
1169
|
retval.append("return 200 <= response.status_code <= 299")
|
|
967
1170
|
return retval
|
|
968
1171
|
|
|
@@ -983,7 +1186,11 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
983
1186
|
and self.code_model.options["models_mode"]
|
|
984
1187
|
):
|
|
985
1188
|
error_model_str = f", model=self._deserialize(_models.{excep.serialization_type}, response)"
|
|
986
|
-
error_format_str =
|
|
1189
|
+
error_format_str = (
|
|
1190
|
+
", error_format=ARMErrorFormat"
|
|
1191
|
+
if self.code_model.options["azure_arm"]
|
|
1192
|
+
else ""
|
|
1193
|
+
)
|
|
987
1194
|
for status_code in excep.status_codes:
|
|
988
1195
|
if status_code == 401:
|
|
989
1196
|
retval.append(
|
|
@@ -1008,9 +1215,11 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
1008
1215
|
f"{error_model_str}{error_format_str}),"
|
|
1009
1216
|
)
|
|
1010
1217
|
else:
|
|
1011
|
-
retval.append(
|
|
1218
|
+
retval.append(
|
|
1219
|
+
" 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError"
|
|
1220
|
+
)
|
|
1012
1221
|
retval.append("}")
|
|
1013
|
-
retval.append("error_map.update(kwargs.pop('error_map', {}))")
|
|
1222
|
+
retval.append("error_map.update(kwargs.pop('error_map', {}) or {})")
|
|
1014
1223
|
return retval
|
|
1015
1224
|
|
|
1016
1225
|
@staticmethod
|
|
@@ -1018,7 +1227,10 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
1018
1227
|
url = _escape_str(builder.request_builder.url)
|
|
1019
1228
|
return f"{builder.python_name}.metadata = {{'url': { url }}} # type: ignore"
|
|
1020
1229
|
|
|
1021
|
-
|
|
1230
|
+
|
|
1231
|
+
class _SyncOperationBaseSerializer(
|
|
1232
|
+
_OperationBaseSerializer
|
|
1233
|
+
): # pylint: disable=abstract-method
|
|
1022
1234
|
@property
|
|
1023
1235
|
def _want_inline_type_hints(self) -> bool:
|
|
1024
1236
|
return False
|
|
@@ -1031,15 +1243,20 @@ class _SyncOperationBaseSerializer(_OperationBaseSerializer): # pylint: disable
|
|
|
1031
1243
|
def _call_method(self) -> str:
|
|
1032
1244
|
return ""
|
|
1033
1245
|
|
|
1246
|
+
|
|
1034
1247
|
class SyncOperationGenericSerializer(_SyncOperationBaseSerializer):
|
|
1035
1248
|
@property
|
|
1036
1249
|
def _want_inline_type_hints(self) -> bool:
|
|
1037
1250
|
return False
|
|
1038
1251
|
|
|
1039
1252
|
@staticmethod
|
|
1040
|
-
def _method_signature_and_response_type_annotation_template(
|
|
1253
|
+
def _method_signature_and_response_type_annotation_template(
|
|
1254
|
+
method_signature: str, response_type_annotation: str
|
|
1255
|
+
):
|
|
1041
1256
|
return utils.method_signature_and_response_type_annotation_template(
|
|
1042
|
-
is_python3_file=False,
|
|
1257
|
+
is_python3_file=False,
|
|
1258
|
+
method_signature=method_signature,
|
|
1259
|
+
response_type_annotation=response_type_annotation,
|
|
1043
1260
|
)
|
|
1044
1261
|
|
|
1045
1262
|
def _get_kwargs_to_pop(self, builder):
|
|
@@ -1052,16 +1269,20 @@ class SyncOperationPython3Serializer(_SyncOperationBaseSerializer):
|
|
|
1052
1269
|
return True
|
|
1053
1270
|
|
|
1054
1271
|
@staticmethod
|
|
1055
|
-
def _method_signature_and_response_type_annotation_template(
|
|
1272
|
+
def _method_signature_and_response_type_annotation_template(
|
|
1273
|
+
method_signature: str, response_type_annotation: str
|
|
1274
|
+
):
|
|
1056
1275
|
return utils.method_signature_and_response_type_annotation_template(
|
|
1057
|
-
is_python3_file=True,
|
|
1276
|
+
is_python3_file=True,
|
|
1277
|
+
method_signature=method_signature,
|
|
1278
|
+
response_type_annotation=response_type_annotation,
|
|
1058
1279
|
)
|
|
1059
1280
|
|
|
1060
1281
|
def _get_kwargs_to_pop(self, builder):
|
|
1061
1282
|
return builder.parameters.kwargs_to_pop(is_python3_file=True)
|
|
1062
1283
|
|
|
1063
|
-
class AsyncOperationSerializer(SyncOperationPython3Serializer):
|
|
1064
1284
|
|
|
1285
|
+
class AsyncOperationSerializer(SyncOperationPython3Serializer):
|
|
1065
1286
|
@property
|
|
1066
1287
|
def _def(self) -> str:
|
|
1067
1288
|
return "async def"
|
|
@@ -1078,55 +1299,66 @@ class AsyncOperationSerializer(SyncOperationPython3Serializer):
|
|
|
1078
1299
|
############################## PAGING OPERATIONS ##############################
|
|
1079
1300
|
|
|
1080
1301
|
|
|
1081
|
-
class _PagingOperationBaseSerializer(
|
|
1082
|
-
|
|
1302
|
+
class _PagingOperationBaseSerializer(
|
|
1303
|
+
_OperationBaseSerializer
|
|
1304
|
+
): # pylint: disable=abstract-method
|
|
1305
|
+
def _response_docstring_text_template(
|
|
1306
|
+
self, builder
|
|
1307
|
+
) -> str: # pylint: disable=no-self-use, unused-argument
|
|
1083
1308
|
if self._cls_docstring_rtype:
|
|
1084
1309
|
return "An iterator like instance of either {}" + self._cls_docstring_rtype
|
|
1085
1310
|
return "An iterator like instance of {}"
|
|
1086
1311
|
|
|
1087
1312
|
def cls_type_annotation(self, builder) -> str:
|
|
1088
|
-
interior = super()._response_type_annotation(
|
|
1313
|
+
interior = super()._response_type_annotation(
|
|
1314
|
+
builder, modify_if_head_as_boolean=False
|
|
1315
|
+
)
|
|
1089
1316
|
return f"# type: ClsType[{interior}]"
|
|
1090
1317
|
|
|
1318
|
+
def decorators(self, builder, async_mode: bool) -> List[str]:
|
|
1319
|
+
"""Decorators for the method"""
|
|
1320
|
+
retval: List[str] = []
|
|
1321
|
+
if self.code_model.options["tracing"] and builder.want_tracing:
|
|
1322
|
+
retval.append("@distributed_trace")
|
|
1323
|
+
if builder.abstract:
|
|
1324
|
+
retval.append("@abc.abstractmethod")
|
|
1325
|
+
return retval
|
|
1326
|
+
|
|
1091
1327
|
def call_next_link_request_builder(self, builder) -> List[str]:
|
|
1092
1328
|
if builder.next_request_builder:
|
|
1093
1329
|
request_builder = builder.next_request_builder
|
|
1094
|
-
template_url =
|
|
1330
|
+
template_url = (
|
|
1331
|
+
None
|
|
1332
|
+
if self.code_model.options["version_tolerant"]
|
|
1333
|
+
else f"'{request_builder.url}'"
|
|
1334
|
+
)
|
|
1095
1335
|
else:
|
|
1096
1336
|
request_builder = builder.request_builder
|
|
1097
1337
|
template_url = "next_link"
|
|
1098
1338
|
|
|
1099
1339
|
request_builder = builder.next_request_builder or builder.request_builder
|
|
1100
1340
|
return self._call_request_builder_helper(
|
|
1101
|
-
builder,
|
|
1102
|
-
request_builder,
|
|
1103
|
-
template_url=template_url,
|
|
1104
|
-
is_next_request=True
|
|
1341
|
+
builder, request_builder, template_url=template_url, is_next_request=True
|
|
1105
1342
|
)
|
|
1106
1343
|
|
|
1107
1344
|
def _prepare_request_callback(self, builder) -> List[str]:
|
|
1108
1345
|
retval = ["def prepare_request(next_link=None):"]
|
|
1109
1346
|
retval.append(" if not next_link:")
|
|
1110
|
-
retval.extend(
|
|
1111
|
-
f" {line}"
|
|
1112
|
-
|
|
1113
|
-
])
|
|
1347
|
+
retval.extend(
|
|
1348
|
+
[f" {line}" for line in self.call_request_builder(builder)]
|
|
1349
|
+
)
|
|
1114
1350
|
retval.append("")
|
|
1115
1351
|
retval.append(" else:")
|
|
1116
|
-
retval.extend(
|
|
1117
|
-
f" {line}"
|
|
1118
|
-
|
|
1119
|
-
])
|
|
1352
|
+
retval.extend(
|
|
1353
|
+
[f" {line}" for line in self.call_next_link_request_builder(builder)]
|
|
1354
|
+
)
|
|
1120
1355
|
if not builder.next_request_builder and builder.parameters.path:
|
|
1121
1356
|
retval.append("")
|
|
1122
|
-
retval.extend([
|
|
1123
|
-
f" {line}"
|
|
1124
|
-
for line in self.serialize_path(builder)
|
|
1125
|
-
])
|
|
1357
|
+
retval.extend([f" {line}" for line in self.serialize_path(builder)])
|
|
1126
1358
|
if not builder.next_request_builder:
|
|
1127
1359
|
retval.append(' request.method = "GET"')
|
|
1128
1360
|
else:
|
|
1129
|
-
retval.append(
|
|
1361
|
+
retval.append("")
|
|
1130
1362
|
retval.append(" return request")
|
|
1131
1363
|
return retval
|
|
1132
1364
|
|
|
@@ -1145,12 +1377,16 @@ class _PagingOperationBaseSerializer(_OperationBaseSerializer): # pylint: disab
|
|
|
1145
1377
|
response = builder.responses[0]
|
|
1146
1378
|
deserialized = (
|
|
1147
1379
|
f'self._deserialize("{response.serialization_type}", pipeline_response)'
|
|
1148
|
-
if self.code_model.options["models_mode"]
|
|
1149
|
-
"pipeline_response.http_response.json()"
|
|
1380
|
+
if self.code_model.options["models_mode"]
|
|
1381
|
+
else "pipeline_response.http_response.json()"
|
|
1150
1382
|
)
|
|
1151
1383
|
retval.append(f" deserialized = {deserialized}")
|
|
1152
1384
|
item_name = builder.item_name(self.code_model)
|
|
1153
|
-
list_of_elem =
|
|
1385
|
+
list_of_elem = (
|
|
1386
|
+
f".{item_name}"
|
|
1387
|
+
if self.code_model.options["models_mode"]
|
|
1388
|
+
else f'["{item_name}"]'
|
|
1389
|
+
)
|
|
1154
1390
|
retval.append(f" list_of_elem = deserialized{list_of_elem}")
|
|
1155
1391
|
retval.append(" if cls:")
|
|
1156
1392
|
retval.append(" list_of_elem = cls(list_of_elem)")
|
|
@@ -1162,30 +1398,31 @@ class _PagingOperationBaseSerializer(_OperationBaseSerializer): # pylint: disab
|
|
|
1162
1398
|
next_link_property = f"deserialized.{next_link_name} or None"
|
|
1163
1399
|
else:
|
|
1164
1400
|
next_link_property = f'deserialized.get("{next_link_name}", None)'
|
|
1165
|
-
retval.append(
|
|
1401
|
+
retval.append(
|
|
1402
|
+
f" return {next_link_property}, {self._list_type_returned_to_users}(list_of_elem)"
|
|
1403
|
+
)
|
|
1166
1404
|
return retval
|
|
1167
1405
|
|
|
1168
1406
|
def _get_next_callback(self, builder) -> List[str]:
|
|
1169
1407
|
retval = [f"{self._def} get_next(next_link=None):"]
|
|
1170
1408
|
retval.append(" request = prepare_request(next_link)")
|
|
1171
1409
|
retval.append("")
|
|
1172
|
-
retval.append(
|
|
1410
|
+
retval.append(
|
|
1411
|
+
f" pipeline_response = {self._call_method}self._client._pipeline.run( # pylint: disable=protected-access"
|
|
1412
|
+
)
|
|
1173
1413
|
retval.append(" request,")
|
|
1174
1414
|
retval.append(f" stream={builder.is_stream_response},")
|
|
1175
1415
|
retval.append(" **kwargs")
|
|
1176
1416
|
retval.append(" )")
|
|
1177
1417
|
retval.append(" response = pipeline_response.http_response")
|
|
1178
1418
|
retval.append("")
|
|
1179
|
-
retval.extend([
|
|
1180
|
-
f" {line}"
|
|
1181
|
-
for line in self.handle_error_response(builder)
|
|
1182
|
-
])
|
|
1419
|
+
retval.extend([f" {line}" for line in self.handle_error_response(builder)])
|
|
1183
1420
|
retval.append("")
|
|
1184
1421
|
retval.append(" return pipeline_response")
|
|
1185
1422
|
return retval
|
|
1186
1423
|
|
|
1187
1424
|
def set_up_params_for_pager(self, builder) -> List[str]:
|
|
1188
|
-
retval = [
|
|
1425
|
+
retval = []
|
|
1189
1426
|
retval.extend(self.error_map(builder))
|
|
1190
1427
|
retval.extend(self._prepare_request_callback(builder))
|
|
1191
1428
|
retval.append("")
|
|
@@ -1194,8 +1431,13 @@ class _PagingOperationBaseSerializer(_OperationBaseSerializer): # pylint: disab
|
|
|
1194
1431
|
retval.extend(self._get_next_callback(builder))
|
|
1195
1432
|
return retval
|
|
1196
1433
|
|
|
1197
|
-
|
|
1198
|
-
|
|
1434
|
+
|
|
1435
|
+
class _SyncPagingOperationBaseSerializer(
|
|
1436
|
+
_PagingOperationBaseSerializer, _SyncOperationBaseSerializer
|
|
1437
|
+
): # pylint: disable=abstract-method
|
|
1438
|
+
def _response_docstring_type_wrapper(
|
|
1439
|
+
self, builder
|
|
1440
|
+
) -> List[str]: # pylint: no-self-use
|
|
1199
1441
|
return [f"~{builder.get_pager_path(async_mode=False)}"]
|
|
1200
1442
|
|
|
1201
1443
|
def _response_type_annotation_wrapper(self, builder) -> List[str]:
|
|
@@ -1209,14 +1451,25 @@ class _SyncPagingOperationBaseSerializer(_PagingOperationBaseSerializer, _SyncOp
|
|
|
1209
1451
|
def _pager(builder) -> str:
|
|
1210
1452
|
return builder.get_pager(async_mode=False)
|
|
1211
1453
|
|
|
1212
|
-
|
|
1454
|
+
|
|
1455
|
+
class SyncPagingOperationGenericSerializer(
|
|
1456
|
+
_SyncPagingOperationBaseSerializer, SyncOperationGenericSerializer
|
|
1457
|
+
):
|
|
1213
1458
|
pass
|
|
1214
1459
|
|
|
1215
|
-
|
|
1460
|
+
|
|
1461
|
+
class SyncPagingOperationPython3Serializer(
|
|
1462
|
+
_SyncPagingOperationBaseSerializer, SyncOperationPython3Serializer
|
|
1463
|
+
):
|
|
1216
1464
|
pass
|
|
1217
1465
|
|
|
1218
|
-
|
|
1219
|
-
|
|
1466
|
+
|
|
1467
|
+
class AsyncPagingOperationSerializer(
|
|
1468
|
+
_PagingOperationBaseSerializer, AsyncOperationSerializer
|
|
1469
|
+
):
|
|
1470
|
+
def _response_docstring_type_wrapper(
|
|
1471
|
+
self, builder
|
|
1472
|
+
) -> List[str]: # pylint: no-self-use
|
|
1220
1473
|
return [f"~{builder.get_pager_path(async_mode=True)}"]
|
|
1221
1474
|
|
|
1222
1475
|
@property
|
|
@@ -1238,7 +1491,9 @@ class AsyncPagingOperationSerializer(_PagingOperationBaseSerializer, AsyncOperat
|
|
|
1238
1491
|
############################## LRO OPERATIONS ##############################
|
|
1239
1492
|
|
|
1240
1493
|
|
|
1241
|
-
class _LROOperationBaseSerializer(
|
|
1494
|
+
class _LROOperationBaseSerializer(
|
|
1495
|
+
_OperationBaseSerializer
|
|
1496
|
+
): # pylint: disable=abstract-method
|
|
1242
1497
|
def cls_type_annotation(self, builder) -> str:
|
|
1243
1498
|
return f"# type: ClsType[{super()._response_type_annotation(builder, modify_if_head_as_boolean=False)}]"
|
|
1244
1499
|
|
|
@@ -1261,13 +1516,17 @@ class _LROOperationBaseSerializer(_OperationBaseSerializer): # pylint: disable=
|
|
|
1261
1516
|
|
|
1262
1517
|
def param_description(self, builder) -> List[str]:
|
|
1263
1518
|
retval = super().param_description(builder)
|
|
1264
|
-
retval.append(
|
|
1519
|
+
retval.append(
|
|
1520
|
+
":keyword str continuation_token: A continuation token to restart a poller from a saved state."
|
|
1521
|
+
)
|
|
1265
1522
|
retval.append(
|
|
1266
1523
|
f":keyword polling: By default, your polling method will be {self._default_polling_method(builder)}. "
|
|
1267
1524
|
"Pass in False for this operation to not poll, or pass in your own initialized polling object for a"
|
|
1268
1525
|
" personal polling strategy."
|
|
1269
1526
|
)
|
|
1270
|
-
retval.append(
|
|
1527
|
+
retval.append(
|
|
1528
|
+
f":paramtype polling: bool or ~azure.core.polling.{self._polling_method_type}"
|
|
1529
|
+
)
|
|
1271
1530
|
retval.append(
|
|
1272
1531
|
":keyword int polling_interval: Default waiting time between two polls for LRO operations "
|
|
1273
1532
|
"if no Retry-After header is present."
|
|
@@ -1275,20 +1534,29 @@ class _LROOperationBaseSerializer(_OperationBaseSerializer): # pylint: disable=
|
|
|
1275
1534
|
return retval
|
|
1276
1535
|
|
|
1277
1536
|
def initial_call(self, builder) -> List[str]:
|
|
1278
|
-
retval = [
|
|
1279
|
-
|
|
1537
|
+
retval = [
|
|
1538
|
+
f"polling = kwargs.pop('polling', True) # type: Union[bool, {self._polling_method_type}]"
|
|
1539
|
+
]
|
|
1280
1540
|
retval.append("lro_delay = kwargs.pop(")
|
|
1281
1541
|
retval.append(" 'polling_interval',")
|
|
1282
1542
|
retval.append(" self._config.polling_interval")
|
|
1283
1543
|
retval.append(")")
|
|
1284
|
-
retval.append(
|
|
1544
|
+
retval.append(
|
|
1545
|
+
"cont_token = kwargs.pop('continuation_token', None) # type: Optional[str]"
|
|
1546
|
+
)
|
|
1285
1547
|
retval.append("if cont_token is None:")
|
|
1286
|
-
retval.append(
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1548
|
+
retval.append(
|
|
1549
|
+
f" raw_result = {self._call_method}self.{builder.initial_operation.name}( # type: ignore"
|
|
1550
|
+
)
|
|
1551
|
+
retval.extend(
|
|
1552
|
+
[
|
|
1553
|
+
f" {parameter.serialized_name}={parameter.serialized_name},"
|
|
1554
|
+
for parameter in builder.parameters.method
|
|
1555
|
+
]
|
|
1556
|
+
)
|
|
1291
1557
|
retval.append(" cls=lambda x,y,z: x,")
|
|
1558
|
+
retval.append(" headers=_headers,")
|
|
1559
|
+
retval.append(" params=_params,")
|
|
1292
1560
|
retval.append(" **kwargs")
|
|
1293
1561
|
retval.append(" )")
|
|
1294
1562
|
retval.append("kwargs.pop('error_map', None)")
|
|
@@ -1297,20 +1565,31 @@ class _LROOperationBaseSerializer(_OperationBaseSerializer): # pylint: disable=
|
|
|
1297
1565
|
def return_lro_poller(self, builder) -> List[str]:
|
|
1298
1566
|
retval = []
|
|
1299
1567
|
lro_options_str = (
|
|
1300
|
-
"
|
|
1301
|
-
|
|
1568
|
+
"lro_options={'final-state-via': '"
|
|
1569
|
+
+ builder.lro_options["final-state-via"]
|
|
1570
|
+
+ "'},"
|
|
1571
|
+
if builder.lro_options
|
|
1572
|
+
else ""
|
|
1302
1573
|
)
|
|
1303
1574
|
path_format_arguments_str = ""
|
|
1304
1575
|
if builder.parameters.path:
|
|
1305
|
-
path_format_arguments_str = "
|
|
1576
|
+
path_format_arguments_str = "path_format_arguments=path_format_arguments,"
|
|
1306
1577
|
retval.extend(self.serialize_path(builder))
|
|
1307
1578
|
retval.append("")
|
|
1308
|
-
retval.
|
|
1309
|
-
|
|
1310
|
-
|
|
1579
|
+
retval.extend(
|
|
1580
|
+
[
|
|
1581
|
+
"if polling is True:",
|
|
1582
|
+
f" polling_method = cast({self._polling_method_type}, {self._default_polling_method(builder)}(",
|
|
1583
|
+
" lro_delay,",
|
|
1584
|
+
f" {lro_options_str}",
|
|
1585
|
+
f" {path_format_arguments_str}",
|
|
1586
|
+
" **kwargs",
|
|
1587
|
+
f")) # type: {self._polling_method_type}",
|
|
1588
|
+
]
|
|
1311
1589
|
)
|
|
1312
1590
|
retval.append(
|
|
1313
|
-
f"elif polling is False: polling_method = {self.
|
|
1591
|
+
f"elif polling is False: polling_method = cast({self._polling_method_type}, "
|
|
1592
|
+
f"{self._default_no_polling_method(builder)}())"
|
|
1314
1593
|
)
|
|
1315
1594
|
retval.append("else: polling_method = polling")
|
|
1316
1595
|
retval.append("if cont_token:")
|
|
@@ -1331,36 +1610,58 @@ class _LROOperationBaseSerializer(_OperationBaseSerializer): # pylint: disable=
|
|
|
1331
1610
|
if builder.lro_response:
|
|
1332
1611
|
if builder.lro_response.has_headers:
|
|
1333
1612
|
retval.append(" response_headers = {}")
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1613
|
+
if (
|
|
1614
|
+
not self.code_model.options["models_mode"]
|
|
1615
|
+
or builder.lro_response.has_headers
|
|
1616
|
+
):
|
|
1617
|
+
retval.append(" response = pipeline_response.http_response")
|
|
1618
|
+
retval.extend(
|
|
1619
|
+
[
|
|
1620
|
+
f" {line}"
|
|
1621
|
+
for line in self.response_headers_and_deserialization(
|
|
1622
|
+
builder.lro_response
|
|
1623
|
+
)
|
|
1624
|
+
]
|
|
1625
|
+
)
|
|
1339
1626
|
retval.append(" if cls:")
|
|
1340
|
-
retval.append(
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1627
|
+
retval.append(
|
|
1628
|
+
" return cls(pipeline_response, {}, {})".format(
|
|
1629
|
+
"deserialized"
|
|
1630
|
+
if builder.lro_response and builder.lro_response.has_body
|
|
1631
|
+
else "None",
|
|
1632
|
+
"response_headers"
|
|
1633
|
+
if builder.lro_response and builder.lro_response.has_headers
|
|
1634
|
+
else "{}",
|
|
1635
|
+
)
|
|
1636
|
+
)
|
|
1344
1637
|
if builder.lro_response and builder.lro_response.has_body:
|
|
1345
1638
|
retval.append(" return deserialized")
|
|
1346
1639
|
return retval
|
|
1347
1640
|
|
|
1348
1641
|
|
|
1349
|
-
class _SyncLROOperationBaseSerializer(
|
|
1350
|
-
|
|
1642
|
+
class _SyncLROOperationBaseSerializer(
|
|
1643
|
+
_LROOperationBaseSerializer, _SyncOperationBaseSerializer
|
|
1644
|
+
): # pylint: disable=abstract-method
|
|
1645
|
+
def _response_docstring_text_template(
|
|
1646
|
+
self, builder
|
|
1647
|
+
) -> str: # pylint: disable=no-self-use
|
|
1351
1648
|
lro_section = f"An instance of {builder.get_poller(async_mode=False)} "
|
|
1352
1649
|
if self._cls_docstring_rtype:
|
|
1353
1650
|
return lro_section + "that returns either {}" + self._cls_docstring_rtype
|
|
1354
1651
|
return lro_section + "that returns {}"
|
|
1355
1652
|
|
|
1356
|
-
def _response_docstring_type_wrapper(
|
|
1653
|
+
def _response_docstring_type_wrapper(
|
|
1654
|
+
self, builder
|
|
1655
|
+
) -> List[str]: # pylint: no-self-use
|
|
1357
1656
|
return [f"~{builder.get_poller_path(async_mode=False)}"]
|
|
1358
1657
|
|
|
1359
1658
|
def _response_type_annotation_wrapper(self, builder) -> List[str]:
|
|
1360
1659
|
return [builder.get_poller(async_mode=False)]
|
|
1361
1660
|
|
|
1362
1661
|
def _default_polling_method(self, builder) -> str:
|
|
1363
|
-
return builder.get_default_polling_method(
|
|
1662
|
+
return builder.get_default_polling_method(
|
|
1663
|
+
async_mode=False, azure_arm=self.code_model.options["azure_arm"]
|
|
1664
|
+
)
|
|
1364
1665
|
|
|
1365
1666
|
def _default_no_polling_method(self, builder) -> str:
|
|
1366
1667
|
return builder.get_default_no_polling_method(async_mode=False)
|
|
@@ -1372,28 +1673,42 @@ class _SyncLROOperationBaseSerializer(_LROOperationBaseSerializer, _SyncOperatio
|
|
|
1372
1673
|
def _poller(self, builder) -> str:
|
|
1373
1674
|
return builder.get_poller(async_mode=False)
|
|
1374
1675
|
|
|
1375
|
-
|
|
1676
|
+
|
|
1677
|
+
class SyncLROOperationGenericSerializer(
|
|
1678
|
+
_SyncLROOperationBaseSerializer, SyncOperationGenericSerializer
|
|
1679
|
+
):
|
|
1376
1680
|
pass
|
|
1377
1681
|
|
|
1378
|
-
|
|
1682
|
+
|
|
1683
|
+
class SyncLROOperationPython3Serializer(
|
|
1684
|
+
_SyncLROOperationBaseSerializer, SyncOperationPython3Serializer
|
|
1685
|
+
):
|
|
1379
1686
|
pass
|
|
1380
1687
|
|
|
1381
|
-
class AsyncLROOperationSerializer(_LROOperationBaseSerializer, AsyncOperationSerializer):
|
|
1382
1688
|
|
|
1383
|
-
|
|
1689
|
+
class AsyncLROOperationSerializer(
|
|
1690
|
+
_LROOperationBaseSerializer, AsyncOperationSerializer
|
|
1691
|
+
):
|
|
1692
|
+
def _response_docstring_text_template(
|
|
1693
|
+
self, builder
|
|
1694
|
+
) -> str: # pylint: disable=no-self-use
|
|
1384
1695
|
lro_section = f"An instance of {builder.get_poller(async_mode=True)} "
|
|
1385
1696
|
if self._cls_docstring_rtype:
|
|
1386
1697
|
return lro_section + "that returns either {}" + self._cls_docstring_rtype
|
|
1387
1698
|
return lro_section + "that returns {}"
|
|
1388
1699
|
|
|
1389
|
-
def _response_docstring_type_wrapper(
|
|
1700
|
+
def _response_docstring_type_wrapper(
|
|
1701
|
+
self, builder
|
|
1702
|
+
) -> List[str]: # pylint: no-self-use
|
|
1390
1703
|
return [f"~{builder.get_poller_path(async_mode=True)}"]
|
|
1391
1704
|
|
|
1392
1705
|
def _response_type_annotation_wrapper(self, builder) -> List[str]:
|
|
1393
1706
|
return [builder.get_poller(async_mode=True)]
|
|
1394
1707
|
|
|
1395
1708
|
def _default_polling_method(self, builder) -> str:
|
|
1396
|
-
return builder.get_default_polling_method(
|
|
1709
|
+
return builder.get_default_polling_method(
|
|
1710
|
+
async_mode=True, azure_arm=self.code_model.options["azure_arm"]
|
|
1711
|
+
)
|
|
1397
1712
|
|
|
1398
1713
|
def _default_no_polling_method(self, builder) -> str:
|
|
1399
1714
|
return builder.get_default_no_polling_method(async_mode=True)
|
|
@@ -1408,8 +1723,10 @@ class AsyncLROOperationSerializer(_LROOperationBaseSerializer, AsyncOperationSer
|
|
|
1408
1723
|
|
|
1409
1724
|
############################## LRO PAGING OPERATIONS ##############################
|
|
1410
1725
|
|
|
1411
|
-
class _LROPagingOperationBaseSerializer(_LROOperationBaseSerializer, _PagingOperationBaseSerializer): # pylint: disable=abstract-method
|
|
1412
1726
|
|
|
1727
|
+
class _LROPagingOperationBaseSerializer(
|
|
1728
|
+
_LROOperationBaseSerializer, _PagingOperationBaseSerializer
|
|
1729
|
+
): # pylint: disable=abstract-method
|
|
1413
1730
|
def get_long_running_output(self, builder) -> List[str]:
|
|
1414
1731
|
retval = ["def get_long_running_output(pipeline_response):"]
|
|
1415
1732
|
retval.append(f" {self._def} internal_get_next(next_link=None):")
|
|
@@ -1422,38 +1739,64 @@ class _LROPagingOperationBaseSerializer(_LROOperationBaseSerializer, _PagingOper
|
|
|
1422
1739
|
retval.append(" )")
|
|
1423
1740
|
return retval
|
|
1424
1741
|
|
|
1742
|
+
def decorators(self, builder, async_mode: bool) -> List[str]:
|
|
1743
|
+
"""Decorators for the method"""
|
|
1744
|
+
return _LROOperationBaseSerializer.decorators(self, builder, async_mode)
|
|
1745
|
+
|
|
1425
1746
|
|
|
1426
1747
|
class _SyncLROPagingOperationBaseSerializer( # pylint: disable=abstract-method
|
|
1427
|
-
_SyncLROOperationBaseSerializer,
|
|
1748
|
+
_SyncLROOperationBaseSerializer,
|
|
1749
|
+
_SyncPagingOperationBaseSerializer,
|
|
1750
|
+
_LROPagingOperationBaseSerializer,
|
|
1428
1751
|
):
|
|
1429
|
-
|
|
1430
1752
|
def _response_docstring_type_wrapper(self, builder) -> List[str]:
|
|
1431
1753
|
return _SyncLROOperationBaseSerializer._response_docstring_type_wrapper(
|
|
1432
1754
|
self, builder
|
|
1433
|
-
) + _SyncPagingOperationBaseSerializer._response_docstring_type_wrapper(
|
|
1755
|
+
) + _SyncPagingOperationBaseSerializer._response_docstring_type_wrapper(
|
|
1756
|
+
self, builder
|
|
1757
|
+
)
|
|
1434
1758
|
|
|
1435
1759
|
def _response_type_annotation_wrapper(self, builder) -> List[str]:
|
|
1436
|
-
return _SyncLROOperationBaseSerializer._response_type_annotation_wrapper(
|
|
1437
|
-
builder
|
|
1438
|
-
]
|
|
1760
|
+
return _SyncLROOperationBaseSerializer._response_type_annotation_wrapper(
|
|
1761
|
+
self, builder
|
|
1762
|
+
) + [builder.get_pager(async_mode=False)]
|
|
1439
1763
|
|
|
1440
1764
|
def _response_docstring_text_template(self, builder) -> str:
|
|
1441
|
-
lro_doc = _SyncLROOperationBaseSerializer._response_docstring_text_template(
|
|
1442
|
-
|
|
1765
|
+
lro_doc = _SyncLROOperationBaseSerializer._response_docstring_text_template(
|
|
1766
|
+
self, builder
|
|
1767
|
+
)
|
|
1768
|
+
paging_doc = (
|
|
1769
|
+
_SyncPagingOperationBaseSerializer._response_docstring_text_template(
|
|
1770
|
+
self, builder
|
|
1771
|
+
)
|
|
1772
|
+
)
|
|
1443
1773
|
paging_doc = paging_doc.replace(paging_doc[0], paging_doc[0].lower(), 1)
|
|
1444
|
-
return
|
|
1774
|
+
return (
|
|
1775
|
+
lro_doc.format(paging_doc)
|
|
1776
|
+
.replace(self._cls_docstring_rtype, "", 1)
|
|
1777
|
+
.replace("either ", "", 1)
|
|
1778
|
+
)
|
|
1445
1779
|
|
|
1446
1780
|
def cls_type_annotation(self, builder) -> str:
|
|
1447
1781
|
return f"# type: ClsType[{self._response_type_annotation(builder, modify_if_head_as_boolean=False)}]"
|
|
1448
1782
|
|
|
1449
|
-
|
|
1783
|
+
|
|
1784
|
+
class SyncLROPagingOperationGenericSerializer(
|
|
1785
|
+
_SyncLROPagingOperationBaseSerializer, SyncOperationGenericSerializer
|
|
1786
|
+
):
|
|
1450
1787
|
pass
|
|
1451
1788
|
|
|
1452
|
-
|
|
1789
|
+
|
|
1790
|
+
class SyncLROPagingOperationPython3Serializer(
|
|
1791
|
+
_SyncLROPagingOperationBaseSerializer, SyncOperationPython3Serializer
|
|
1792
|
+
):
|
|
1453
1793
|
pass
|
|
1454
1794
|
|
|
1795
|
+
|
|
1455
1796
|
class AsyncLROPagingOperationSerializer(
|
|
1456
|
-
_LROPagingOperationBaseSerializer,
|
|
1797
|
+
_LROPagingOperationBaseSerializer,
|
|
1798
|
+
AsyncLROOperationSerializer,
|
|
1799
|
+
AsyncPagingOperationSerializer,
|
|
1457
1800
|
):
|
|
1458
1801
|
@property
|
|
1459
1802
|
def _function_definition(self) -> str:
|
|
@@ -1462,18 +1805,30 @@ class AsyncLROPagingOperationSerializer(
|
|
|
1462
1805
|
def _response_docstring_type_wrapper(self, builder) -> List[str]:
|
|
1463
1806
|
return AsyncLROOperationSerializer._response_docstring_type_wrapper(
|
|
1464
1807
|
self, builder
|
|
1465
|
-
) + AsyncPagingOperationSerializer._response_docstring_type_wrapper(
|
|
1808
|
+
) + AsyncPagingOperationSerializer._response_docstring_type_wrapper(
|
|
1809
|
+
self, builder
|
|
1810
|
+
)
|
|
1466
1811
|
|
|
1467
|
-
def _response_type_annotation_wrapper(
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1812
|
+
def _response_type_annotation_wrapper(
|
|
1813
|
+
self, builder: LROPagingOperation
|
|
1814
|
+
) -> List[str]:
|
|
1815
|
+
return AsyncLROOperationSerializer._response_type_annotation_wrapper(
|
|
1816
|
+
self, builder
|
|
1817
|
+
) + [builder.get_pager(async_mode=True)]
|
|
1471
1818
|
|
|
1472
1819
|
def _response_docstring_text_template(self, builder) -> str:
|
|
1473
|
-
lro_doc = AsyncLROOperationSerializer._response_docstring_text_template(
|
|
1474
|
-
|
|
1820
|
+
lro_doc = AsyncLROOperationSerializer._response_docstring_text_template(
|
|
1821
|
+
self, builder
|
|
1822
|
+
)
|
|
1823
|
+
paging_doc = AsyncPagingOperationSerializer._response_docstring_text_template(
|
|
1824
|
+
self, builder
|
|
1825
|
+
)
|
|
1475
1826
|
paging_doc = paging_doc.replace(paging_doc[0], paging_doc[0].lower(), 1)
|
|
1476
|
-
return
|
|
1827
|
+
return (
|
|
1828
|
+
lro_doc.format(paging_doc)
|
|
1829
|
+
.replace(self._cls_docstring_rtype, "", 1)
|
|
1830
|
+
.replace("either ", "", 1)
|
|
1831
|
+
)
|
|
1477
1832
|
|
|
1478
1833
|
|
|
1479
1834
|
def get_operation_serializer(
|
|
@@ -1485,32 +1840,55 @@ def get_operation_serializer(
|
|
|
1485
1840
|
retcls = _OperationBaseSerializer
|
|
1486
1841
|
if isinstance(builder, LROPagingOperation):
|
|
1487
1842
|
retcls = (
|
|
1488
|
-
AsyncLROPagingOperationSerializer
|
|
1843
|
+
AsyncLROPagingOperationSerializer
|
|
1844
|
+
if async_mode
|
|
1489
1845
|
else (
|
|
1490
|
-
SyncLROPagingOperationPython3Serializer
|
|
1846
|
+
SyncLROPagingOperationPython3Serializer
|
|
1847
|
+
if is_python3_file
|
|
1491
1848
|
else SyncLROPagingOperationGenericSerializer
|
|
1492
1849
|
)
|
|
1493
1850
|
)
|
|
1494
1851
|
return retcls(code_model)
|
|
1495
1852
|
if isinstance(builder, LROOperation):
|
|
1496
1853
|
retcls = (
|
|
1497
|
-
AsyncLROOperationSerializer
|
|
1498
|
-
|
|
1854
|
+
AsyncLROOperationSerializer
|
|
1855
|
+
if async_mode
|
|
1856
|
+
else (
|
|
1857
|
+
SyncLROOperationPython3Serializer
|
|
1858
|
+
if is_python3_file
|
|
1859
|
+
else SyncLROOperationGenericSerializer
|
|
1860
|
+
)
|
|
1499
1861
|
)
|
|
1500
1862
|
return retcls(code_model)
|
|
1501
1863
|
if isinstance(builder, PagingOperation):
|
|
1502
1864
|
retcls = (
|
|
1503
|
-
AsyncPagingOperationSerializer
|
|
1504
|
-
|
|
1865
|
+
AsyncPagingOperationSerializer
|
|
1866
|
+
if async_mode
|
|
1867
|
+
else (
|
|
1868
|
+
SyncPagingOperationPython3Serializer
|
|
1869
|
+
if is_python3_file
|
|
1870
|
+
else SyncPagingOperationGenericSerializer
|
|
1871
|
+
)
|
|
1505
1872
|
)
|
|
1506
1873
|
return retcls(code_model)
|
|
1507
1874
|
retcls = (
|
|
1508
|
-
AsyncOperationSerializer
|
|
1509
|
-
|
|
1875
|
+
AsyncOperationSerializer
|
|
1876
|
+
if async_mode
|
|
1877
|
+
else (
|
|
1878
|
+
SyncOperationPython3Serializer
|
|
1879
|
+
if is_python3_file
|
|
1880
|
+
else SyncOperationGenericSerializer
|
|
1881
|
+
)
|
|
1510
1882
|
)
|
|
1511
1883
|
return retcls(code_model)
|
|
1512
1884
|
|
|
1513
1885
|
|
|
1514
|
-
def get_request_builder_serializer(
|
|
1515
|
-
|
|
1886
|
+
def get_request_builder_serializer(
|
|
1887
|
+
code_model, is_python3_file: bool
|
|
1888
|
+
) -> _RequestBuilderBaseSerializer:
|
|
1889
|
+
retcls = (
|
|
1890
|
+
RequestBuilderPython3Serializer
|
|
1891
|
+
if is_python3_file
|
|
1892
|
+
else RequestBuilderGenericSerializer
|
|
1893
|
+
)
|
|
1516
1894
|
return retcls(code_model)
|