@autorest/python 6.13.15 → 6.13.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/__init__.py +4 -12
- package/autorest/_utils.py +5 -20
- package/autorest/black/__init__.py +1 -3
- package/autorest/codegen/__init__.py +29 -96
- package/autorest/codegen/models/__init__.py +1 -3
- package/autorest/codegen/models/base.py +2 -6
- package/autorest/codegen/models/base_builder.py +2 -6
- package/autorest/codegen/models/client.py +24 -86
- package/autorest/codegen/models/code_model.py +13 -53
- package/autorest/codegen/models/combined_type.py +3 -9
- package/autorest/codegen/models/constant_type.py +4 -14
- package/autorest/codegen/models/credential_types.py +11 -35
- package/autorest/codegen/models/dictionary_type.py +4 -12
- package/autorest/codegen/models/enum_type.py +10 -31
- package/autorest/codegen/models/imports.py +15 -41
- package/autorest/codegen/models/list_type.py +7 -23
- package/autorest/codegen/models/lro_operation.py +6 -18
- package/autorest/codegen/models/lro_paging_operation.py +1 -3
- package/autorest/codegen/models/model_type.py +21 -73
- package/autorest/codegen/models/operation.py +41 -139
- package/autorest/codegen/models/operation_group.py +21 -60
- package/autorest/codegen/models/paging_operation.py +13 -43
- package/autorest/codegen/models/parameter.py +16 -54
- package/autorest/codegen/models/parameter_list.py +27 -103
- package/autorest/codegen/models/primitive_types.py +15 -49
- package/autorest/codegen/models/property.py +8 -28
- package/autorest/codegen/models/request_builder.py +11 -39
- package/autorest/codegen/models/request_builder_parameter.py +4 -13
- package/autorest/codegen/models/response.py +16 -57
- package/autorest/codegen/serializers/__init__.py +46 -150
- package/autorest/codegen/serializers/builder_serializer.py +113 -402
- package/autorest/codegen/serializers/client_serializer.py +26 -78
- package/autorest/codegen/serializers/enum_serializer.py +1 -3
- package/autorest/codegen/serializers/general_serializer.py +6 -22
- package/autorest/codegen/serializers/import_serializer.py +13 -40
- package/autorest/codegen/serializers/metadata_serializer.py +7 -21
- package/autorest/codegen/serializers/model_init_serializer.py +1 -5
- package/autorest/codegen/serializers/model_serializer.py +15 -56
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -3
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -8
- package/autorest/codegen/serializers/parameter_serializer.py +8 -26
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -3
- package/autorest/codegen/serializers/sample_serializer.py +13 -39
- package/autorest/codegen/serializers/test_serializer.py +10 -30
- package/autorest/codegen/serializers/types_serializer.py +1 -3
- package/autorest/codegen/templates/enum.py.jinja2 +2 -2
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/model_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/model_dpg.py.jinja2 +3 -3
- package/autorest/codegen/templates/model_msrest.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +1 -3
- package/autorest/jsonrpc/server.py +3 -9
- package/autorest/jsonrpc/stdstream.py +4 -12
- package/autorest/m2r/__init__.py +2 -6
- package/autorest/m4reformatter/__init__.py +72 -237
- package/autorest/multiapi/__init__.py +4 -11
- package/autorest/multiapi/models/client.py +7 -21
- package/autorest/multiapi/models/code_model.py +9 -28
- package/autorest/multiapi/models/config.py +1 -3
- package/autorest/multiapi/models/global_parameters.py +6 -16
- package/autorest/multiapi/models/imports.py +5 -9
- package/autorest/multiapi/models/operation_mixin_group.py +5 -17
- package/autorest/multiapi/serializers/__init__.py +10 -31
- package/autorest/multiapi/serializers/import_serializer.py +8 -24
- package/autorest/multiapi/utils.py +2 -6
- package/autorest/multiclient/__init__.py +1 -3
- package/autorest/postprocess/__init__.py +9 -29
- package/autorest/postprocess/get_all.py +1 -3
- package/autorest/postprocess/venvtools.py +1 -3
- package/autorest/preprocess/__init__.py +40 -126
- package/install.py +2 -0
- package/package.json +1 -1
- package/prepare.py +3 -1
- package/requirements.txt +1 -1
- package/run_cadl.py +1 -3
- package/setup.py +25 -25
- package/start.py +2 -0
- package/venvtools.py +15 -10
|
@@ -86,9 +86,7 @@ def _escape_str(input_str: str) -> str:
|
|
|
86
86
|
def _get_polymorphic_subtype_template(polymorphic_subtype: ModelType) -> List[str]:
|
|
87
87
|
retval: List[str] = []
|
|
88
88
|
retval.append("")
|
|
89
|
-
retval.append(
|
|
90
|
-
f'# JSON input template for discriminator value "{polymorphic_subtype.discriminator_value}":'
|
|
91
|
-
)
|
|
89
|
+
retval.append(f'# JSON input template for discriminator value "{polymorphic_subtype.discriminator_value}":')
|
|
92
90
|
subtype_template = utils.json_dumps_template(
|
|
93
91
|
polymorphic_subtype.get_json_template_representation(),
|
|
94
92
|
)
|
|
@@ -99,18 +97,14 @@ def _get_polymorphic_subtype_template(polymorphic_subtype: ModelType) -> List[st
|
|
|
99
97
|
if not polymorphic_subtype:
|
|
100
98
|
return None
|
|
101
99
|
try:
|
|
102
|
-
return next(
|
|
103
|
-
p for p in polymorphic_subtype.parents if p.discriminated_subtypes
|
|
104
|
-
)
|
|
100
|
+
return next(p for p in polymorphic_subtype.parents if p.discriminated_subtypes)
|
|
105
101
|
except StopIteration:
|
|
106
102
|
return None
|
|
107
103
|
|
|
108
104
|
polymorphic_parent = _get_polymorphic_parent(polymorphic_subtype)
|
|
109
105
|
while _get_polymorphic_parent(polymorphic_parent):
|
|
110
106
|
polymorphic_parent = _get_polymorphic_parent(polymorphic_parent)
|
|
111
|
-
retval.extend(
|
|
112
|
-
f"{cast(ModelType, polymorphic_parent).snake_case_name} = {subtype_template}".splitlines()
|
|
113
|
-
)
|
|
107
|
+
retval.extend(f"{cast(ModelType, polymorphic_parent).snake_case_name} = {subtype_template}".splitlines())
|
|
114
108
|
return retval
|
|
115
109
|
|
|
116
110
|
|
|
@@ -133,55 +127,37 @@ def _serialize_grouped_body(builder: BuilderType) -> List[str]:
|
|
|
133
127
|
def _serialize_flattened_body(body_parameter: BodyParameter) -> List[str]:
|
|
134
128
|
retval: List[str] = []
|
|
135
129
|
if not body_parameter.property_to_parameter_name:
|
|
136
|
-
raise ValueError(
|
|
137
|
-
"This method can't be called if the operation doesn't need parameter flattening"
|
|
138
|
-
)
|
|
130
|
+
raise ValueError("This method can't be called if the operation doesn't need parameter flattening")
|
|
139
131
|
|
|
140
132
|
parameter_string = ", ".join(
|
|
141
133
|
f"{property_name}={parameter_name}"
|
|
142
134
|
for property_name, parameter_name in body_parameter.property_to_parameter_name.items()
|
|
143
135
|
)
|
|
144
136
|
model_type = cast(ModelType, body_parameter.type)
|
|
145
|
-
retval.append(
|
|
146
|
-
f"{body_parameter.client_name} = _models.{model_type.name}({parameter_string})"
|
|
147
|
-
)
|
|
137
|
+
retval.append(f"{body_parameter.client_name} = _models.{model_type.name}({parameter_string})")
|
|
148
138
|
return retval
|
|
149
139
|
|
|
150
140
|
|
|
151
|
-
def _serialize_json_model_body(
|
|
152
|
-
body_parameter: BodyParameter, parameters: List[ParameterType]
|
|
153
|
-
) -> List[str]:
|
|
141
|
+
def _serialize_json_model_body(body_parameter: BodyParameter, parameters: List[ParameterType]) -> List[str]:
|
|
154
142
|
retval: List[str] = []
|
|
155
143
|
if not body_parameter.property_to_parameter_name:
|
|
156
|
-
raise ValueError(
|
|
157
|
-
"This method can't be called if the operation doesn't need parameter flattening"
|
|
158
|
-
)
|
|
144
|
+
raise ValueError("This method can't be called if the operation doesn't need parameter flattening")
|
|
159
145
|
|
|
160
146
|
retval.append(f"if {body_parameter.client_name} is _Unset:")
|
|
161
147
|
for p in parameters:
|
|
162
|
-
if
|
|
163
|
-
p.client_default_value is None
|
|
164
|
-
and not p.optional
|
|
165
|
-
and p.default_to_unset_sentinel
|
|
166
|
-
):
|
|
148
|
+
if p.client_default_value is None and not p.optional and p.default_to_unset_sentinel:
|
|
167
149
|
retval.append(f" if {p.client_name} is _Unset:")
|
|
168
|
-
retval.append(
|
|
169
|
-
f" raise TypeError('missing required argument: {p.client_name}')"
|
|
170
|
-
)
|
|
150
|
+
retval.append(f" raise TypeError('missing required argument: {p.client_name}')")
|
|
171
151
|
parameter_string = ", \n".join(
|
|
172
152
|
f'"{property_name}": {parameter_name}'
|
|
173
153
|
for property_name, parameter_name in body_parameter.property_to_parameter_name.items()
|
|
174
154
|
)
|
|
175
155
|
model_type = cast(ModelType, body_parameter.type)
|
|
176
|
-
if isinstance(model_type, CombinedType) and model_type.target_model_subtype(
|
|
177
|
-
(JSONModelType,)
|
|
178
|
-
):
|
|
156
|
+
if isinstance(model_type, CombinedType) and model_type.target_model_subtype((JSONModelType,)):
|
|
179
157
|
model_type = model_type.target_model_subtype((JSONModelType,))
|
|
180
158
|
retval.append(f" {body_parameter.client_name} = {{{parameter_string}}}")
|
|
181
159
|
retval.append(f" {body_parameter.client_name} = {{")
|
|
182
|
-
retval.append(
|
|
183
|
-
f" k: v for k, v in {body_parameter.client_name}.items() if v is not None"
|
|
184
|
-
)
|
|
160
|
+
retval.append(f" k: v for k, v in {body_parameter.client_name}.items() if v is not None")
|
|
185
161
|
retval.append(" }")
|
|
186
162
|
return retval
|
|
187
163
|
|
|
@@ -286,27 +262,20 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
286
262
|
def method_signature_and_response_type_annotation(
|
|
287
263
|
self, builder: BuilderType, *, want_decorators: Optional[bool] = True
|
|
288
264
|
) -> str:
|
|
289
|
-
response_type_annotation = builder.response_type_annotation(
|
|
290
|
-
async_mode=self.async_mode
|
|
291
|
-
)
|
|
265
|
+
response_type_annotation = builder.response_type_annotation(async_mode=self.async_mode)
|
|
292
266
|
method_signature = self._method_signature(builder)
|
|
293
267
|
decorators = self.decorators(builder)
|
|
294
268
|
decorators_str = ""
|
|
295
269
|
if decorators and want_decorators:
|
|
296
270
|
decorators_str = "\n".join(decorators) + "\n"
|
|
297
|
-
return (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
method_signature=method_signature,
|
|
301
|
-
response_type_annotation=response_type_annotation,
|
|
302
|
-
)
|
|
271
|
+
return decorators_str + utils.method_signature_and_response_type_annotation_template(
|
|
272
|
+
method_signature=method_signature,
|
|
273
|
+
response_type_annotation=response_type_annotation,
|
|
303
274
|
)
|
|
304
275
|
|
|
305
276
|
def description_and_summary(self, builder: BuilderType) -> List[str]:
|
|
306
277
|
description_list: List[str] = []
|
|
307
|
-
description_list.append(
|
|
308
|
-
f"{builder.summary.strip() if builder.summary else builder.description.strip()}"
|
|
309
|
-
)
|
|
278
|
+
description_list.append(f"{builder.summary.strip() if builder.summary else builder.description.strip()}")
|
|
310
279
|
if builder.summary and builder.description:
|
|
311
280
|
description_list.append("")
|
|
312
281
|
description_list.append(builder.description.strip())
|
|
@@ -336,23 +305,17 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
336
305
|
):
|
|
337
306
|
continue
|
|
338
307
|
description_list.extend(
|
|
339
|
-
f":{param.description_keyword} {param.client_name}: {param.description}".replace(
|
|
340
|
-
"\n", "\n "
|
|
341
|
-
).split(
|
|
308
|
+
f":{param.description_keyword} {param.client_name}: {param.description}".replace("\n", "\n ").split(
|
|
342
309
|
"\n"
|
|
343
310
|
)
|
|
344
311
|
)
|
|
345
312
|
docstring_type = param.docstring_type(
|
|
346
313
|
async_mode=self.async_mode,
|
|
347
314
|
)
|
|
348
|
-
description_list.append(
|
|
349
|
-
f":{param.docstring_type_keyword} {param.client_name}: {docstring_type}"
|
|
350
|
-
)
|
|
315
|
+
description_list.append(f":{param.docstring_type_keyword} {param.client_name}: {docstring_type}")
|
|
351
316
|
return description_list
|
|
352
317
|
|
|
353
|
-
def param_description_and_response_docstring(
|
|
354
|
-
self, builder: BuilderType
|
|
355
|
-
) -> List[str]:
|
|
318
|
+
def param_description_and_response_docstring(self, builder: BuilderType) -> List[str]:
|
|
356
319
|
if builder.abstract:
|
|
357
320
|
return []
|
|
358
321
|
return self.param_description(builder) + self.response_docstring(builder)
|
|
@@ -363,17 +326,12 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
363
326
|
|
|
364
327
|
def _json_input_example_template(self, builder: BuilderType) -> List[str]:
|
|
365
328
|
template: List[str] = []
|
|
366
|
-
if
|
|
367
|
-
not builder.parameters.has_body
|
|
368
|
-
or builder.parameters.body_parameter.flattened
|
|
369
|
-
):
|
|
329
|
+
if not builder.parameters.has_body or builder.parameters.body_parameter.flattened:
|
|
370
330
|
# No input template if now body parameter
|
|
371
331
|
return template
|
|
372
332
|
|
|
373
333
|
body_param = builder.parameters.body_parameter
|
|
374
|
-
if not isinstance(
|
|
375
|
-
body_param.type, (ListType, DictionaryType, ModelType, CombinedType)
|
|
376
|
-
):
|
|
334
|
+
if not isinstance(body_param.type, (ListType, DictionaryType, ModelType, CombinedType)):
|
|
377
335
|
return template
|
|
378
336
|
|
|
379
337
|
if (
|
|
@@ -387,9 +345,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
387
345
|
|
|
388
346
|
json_type = body_param.type
|
|
389
347
|
if isinstance(body_param.type, CombinedType):
|
|
390
|
-
target_model_type = body_param.type.target_model_subtype(
|
|
391
|
-
(JSONModelType, DPGModelType)
|
|
392
|
-
)
|
|
348
|
+
target_model_type = body_param.type.target_model_subtype((JSONModelType, DPGModelType))
|
|
393
349
|
if target_model_type is None:
|
|
394
350
|
return template
|
|
395
351
|
json_type = target_model_type
|
|
@@ -398,9 +354,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
398
354
|
json_type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
399
355
|
if polymorphic_subtypes:
|
|
400
356
|
# we just assume one kind of polymorphic body for input
|
|
401
|
-
discriminator_name = cast(
|
|
402
|
-
Property, polymorphic_subtypes[0].discriminator
|
|
403
|
-
).wire_name
|
|
357
|
+
discriminator_name = cast(Property, polymorphic_subtypes[0].discriminator).wire_name
|
|
404
358
|
template.append(
|
|
405
359
|
"# The input is polymorphic. The following are possible polymorphic "
|
|
406
360
|
f'inputs based off discriminator "{discriminator_name}":'
|
|
@@ -411,25 +365,17 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
411
365
|
len(polymorphic_subtypes),
|
|
412
366
|
)
|
|
413
367
|
):
|
|
414
|
-
template.extend(
|
|
415
|
-
_get_polymorphic_subtype_template(polymorphic_subtypes[idx])
|
|
416
|
-
)
|
|
368
|
+
template.extend(_get_polymorphic_subtype_template(polymorphic_subtypes[idx]))
|
|
417
369
|
template.append("")
|
|
418
|
-
template.append(
|
|
419
|
-
"# JSON input template you can fill out and use as your body input."
|
|
420
|
-
)
|
|
370
|
+
template.append("# JSON input template you can fill out and use as your body input.")
|
|
421
371
|
json_template = utils.json_dumps_template(
|
|
422
372
|
json_type.get_json_template_representation(),
|
|
423
373
|
)
|
|
424
|
-
template.extend(
|
|
425
|
-
f"{builder.parameters.body_parameter.client_name} = {json_template}".splitlines()
|
|
426
|
-
)
|
|
374
|
+
template.extend(f"{builder.parameters.body_parameter.client_name} = {json_template}".splitlines())
|
|
427
375
|
return template
|
|
428
376
|
|
|
429
377
|
def serialize_path(self, builder: BuilderType) -> List[str]:
|
|
430
|
-
return self.parameter_serializer.serialize_path(
|
|
431
|
-
builder.parameters.path, self.serializer_name
|
|
432
|
-
)
|
|
378
|
+
return self.parameter_serializer.serialize_path(builder.parameters.path, self.serializer_name)
|
|
433
379
|
|
|
434
380
|
@property
|
|
435
381
|
def pipeline_name(self) -> str:
|
|
@@ -439,9 +385,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
439
385
|
############################## REQUEST BUILDERS ##############################
|
|
440
386
|
|
|
441
387
|
|
|
442
|
-
class RequestBuilderSerializer(
|
|
443
|
-
_BuilderBaseSerializer[RequestBuilderType]
|
|
444
|
-
): # pylint: disable=abstract-method
|
|
388
|
+
class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]): # pylint: disable=abstract-method
|
|
445
389
|
def description_and_summary(self, builder: RequestBuilderType) -> List[str]:
|
|
446
390
|
retval = super().description_and_summary(builder)
|
|
447
391
|
retval += [
|
|
@@ -467,21 +411,11 @@ class RequestBuilderSerializer(
|
|
|
467
411
|
def declare_non_inputtable_constants(builder: RequestBuilderType) -> List[str]:
|
|
468
412
|
def _get_value(param):
|
|
469
413
|
if param.location in [ParameterLocation.HEADER, ParameterLocation.QUERY]:
|
|
470
|
-
kwarg_dict =
|
|
471
|
-
|
|
472
|
-
if param.location == ParameterLocation.HEADER
|
|
473
|
-
else "params"
|
|
474
|
-
)
|
|
475
|
-
return (
|
|
476
|
-
f"_{kwarg_dict}.pop('{param.wire_name}', {param.get_declaration()})"
|
|
477
|
-
)
|
|
414
|
+
kwarg_dict = "headers" if param.location == ParameterLocation.HEADER else "params"
|
|
415
|
+
return f"_{kwarg_dict}.pop('{param.wire_name}', {param.get_declaration()})"
|
|
478
416
|
return f"{param.get_declaration()}"
|
|
479
417
|
|
|
480
|
-
return [
|
|
481
|
-
f"{p.client_name} = {_get_value(p)}"
|
|
482
|
-
for p in builder.parameters.constant
|
|
483
|
-
if not p.in_method_signature
|
|
484
|
-
]
|
|
418
|
+
return [f"{p.client_name} = {_get_value(p)}" for p in builder.parameters.constant if not p.in_method_signature]
|
|
485
419
|
|
|
486
420
|
@property
|
|
487
421
|
def _function_def(self) -> str:
|
|
@@ -505,16 +439,8 @@ class RequestBuilderSerializer(
|
|
|
505
439
|
return self.parameter_serializer.pop_kwargs_from_signature(
|
|
506
440
|
builder.parameters.kwargs_to_pop,
|
|
507
441
|
check_kwarg_dict=True,
|
|
508
|
-
pop_headers_kwarg=(
|
|
509
|
-
|
|
510
|
-
if bool(builder.parameters.headers)
|
|
511
|
-
else PopKwargType.NO
|
|
512
|
-
),
|
|
513
|
-
pop_params_kwarg=(
|
|
514
|
-
PopKwargType.CASE_INSENSITIVE
|
|
515
|
-
if bool(builder.parameters.query)
|
|
516
|
-
else PopKwargType.NO
|
|
517
|
-
),
|
|
442
|
+
pop_headers_kwarg=(PopKwargType.CASE_INSENSITIVE if bool(builder.parameters.headers) else PopKwargType.NO),
|
|
443
|
+
pop_params_kwarg=(PopKwargType.CASE_INSENSITIVE if bool(builder.parameters.query) else PopKwargType.NO),
|
|
518
444
|
)
|
|
519
445
|
|
|
520
446
|
@staticmethod
|
|
@@ -526,15 +452,9 @@ class RequestBuilderSerializer(
|
|
|
526
452
|
retval.append(" params=_params,")
|
|
527
453
|
if builder.parameters.headers:
|
|
528
454
|
retval.append(" headers=_headers,")
|
|
529
|
-
if
|
|
530
|
-
builder.parameters.has_body
|
|
531
|
-
and builder.parameters.body_parameter.in_method_signature
|
|
532
|
-
):
|
|
455
|
+
if builder.parameters.has_body and builder.parameters.body_parameter.in_method_signature:
|
|
533
456
|
body_param = builder.parameters.body_parameter
|
|
534
|
-
if
|
|
535
|
-
body_param.constant
|
|
536
|
-
or body_param.method_location != ParameterMethodLocation.KWARG
|
|
537
|
-
):
|
|
457
|
+
if body_param.constant or body_param.method_location != ParameterMethodLocation.KWARG:
|
|
538
458
|
# we only need to pass it through if it's not a kwarg or it's a popped kwarg
|
|
539
459
|
retval.append(
|
|
540
460
|
f" {builder.parameters.body_parameter.client_name}="
|
|
@@ -576,11 +496,7 @@ class RequestBuilderSerializer(
|
|
|
576
496
|
return retval
|
|
577
497
|
|
|
578
498
|
def construct_url(self, builder: RequestBuilderType) -> str:
|
|
579
|
-
if any(
|
|
580
|
-
o
|
|
581
|
-
for o in ["low_level_client", "version_tolerant"]
|
|
582
|
-
if self.code_model.options.get(o)
|
|
583
|
-
):
|
|
499
|
+
if any(o for o in ["low_level_client", "version_tolerant"] if self.code_model.options.get(o)):
|
|
584
500
|
url_value = _escape_str(builder.url)
|
|
585
501
|
else:
|
|
586
502
|
url_value = f'kwargs.pop("template_url", {_escape_str(builder.url)})'
|
|
@@ -590,9 +506,7 @@ class RequestBuilderSerializer(
|
|
|
590
506
|
############################## NORMAL OPERATIONS ##############################
|
|
591
507
|
|
|
592
508
|
|
|
593
|
-
class _OperationSerializer(
|
|
594
|
-
_BuilderBaseSerializer[OperationType]
|
|
595
|
-
): # pylint: disable=abstract-method
|
|
509
|
+
class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: disable=abstract-method
|
|
596
510
|
def description_and_summary(self, builder: OperationType) -> List[str]:
|
|
597
511
|
retval = super().description_and_summary(builder)
|
|
598
512
|
if builder.deprecated:
|
|
@@ -620,9 +534,7 @@ class _OperationSerializer(
|
|
|
620
534
|
response.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
621
535
|
if polymorphic_subtypes:
|
|
622
536
|
# we just assume one kind of polymorphic body for input
|
|
623
|
-
discriminator_name = cast(
|
|
624
|
-
Property, polymorphic_subtypes[0].discriminator
|
|
625
|
-
).wire_name
|
|
537
|
+
discriminator_name = cast(Property, polymorphic_subtypes[0].discriminator).wire_name
|
|
626
538
|
retval.append("")
|
|
627
539
|
retval.append(
|
|
628
540
|
"# The response is polymorphic. The following are possible polymorphic "
|
|
@@ -634,9 +546,7 @@ class _OperationSerializer(
|
|
|
634
546
|
len(polymorphic_subtypes),
|
|
635
547
|
)
|
|
636
548
|
):
|
|
637
|
-
retval.extend(
|
|
638
|
-
_get_polymorphic_subtype_template(polymorphic_subtypes[idx])
|
|
639
|
-
)
|
|
549
|
+
retval.extend(_get_polymorphic_subtype_template(polymorphic_subtypes[idx]))
|
|
640
550
|
|
|
641
551
|
if _get_json_response_template_to_status_codes(builder):
|
|
642
552
|
retval.append("")
|
|
@@ -644,14 +554,8 @@ class _OperationSerializer(
|
|
|
644
554
|
response_body,
|
|
645
555
|
status_codes,
|
|
646
556
|
) in _get_json_response_template_to_status_codes(builder).items():
|
|
647
|
-
retval.append(
|
|
648
|
-
|
|
649
|
-
", ".join(status_codes)
|
|
650
|
-
)
|
|
651
|
-
)
|
|
652
|
-
retval.extend(
|
|
653
|
-
f"{self._json_response_template_name} == {response_body}".splitlines()
|
|
654
|
-
)
|
|
557
|
+
retval.append("# response body for status code(s): {}".format(", ".join(status_codes)))
|
|
558
|
+
retval.extend(f"{self._json_response_template_name} == {response_body}".splitlines())
|
|
655
559
|
return retval
|
|
656
560
|
|
|
657
561
|
def make_pipeline_call(self, builder: OperationType) -> List[str]:
|
|
@@ -697,16 +601,12 @@ class _OperationSerializer(
|
|
|
697
601
|
check_kwarg_dict=True,
|
|
698
602
|
pop_headers_kwarg=(
|
|
699
603
|
PopKwargType.CASE_INSENSITIVE
|
|
700
|
-
if builder.has_kwargs_to_pop_with_default(
|
|
701
|
-
kwargs_to_pop, ParameterLocation.HEADER # type: ignore
|
|
702
|
-
)
|
|
604
|
+
if builder.has_kwargs_to_pop_with_default(kwargs_to_pop, ParameterLocation.HEADER) # type: ignore
|
|
703
605
|
else PopKwargType.SIMPLE
|
|
704
606
|
),
|
|
705
607
|
pop_params_kwarg=(
|
|
706
608
|
PopKwargType.CASE_INSENSITIVE
|
|
707
|
-
if builder.has_kwargs_to_pop_with_default(
|
|
708
|
-
kwargs_to_pop, ParameterLocation.QUERY # type: ignore
|
|
709
|
-
)
|
|
609
|
+
if builder.has_kwargs_to_pop_with_default(kwargs_to_pop, ParameterLocation.QUERY) # type: ignore
|
|
710
610
|
else PopKwargType.SIMPLE
|
|
711
611
|
),
|
|
712
612
|
check_client_input=not self.code_model.options["multiapi"],
|
|
@@ -719,18 +619,12 @@ class _OperationSerializer(
|
|
|
719
619
|
pylint_disable = ""
|
|
720
620
|
if any(x.startswith("_") for x in cls_annotation.split(".")):
|
|
721
621
|
pylint_disable = " # pylint: disable=protected-access"
|
|
722
|
-
kwargs.append(
|
|
723
|
-
f"cls: {cls_annotation} = kwargs.pop({pylint_disable}\n 'cls', None\n)"
|
|
724
|
-
)
|
|
622
|
+
kwargs.append(f"cls: {cls_annotation} = kwargs.pop({pylint_disable}\n 'cls', None\n)")
|
|
725
623
|
return kwargs
|
|
726
624
|
|
|
727
625
|
def response_docstring(self, builder: OperationType) -> List[str]:
|
|
728
|
-
response_str = (
|
|
729
|
-
|
|
730
|
-
)
|
|
731
|
-
rtype_str = (
|
|
732
|
-
f":rtype: {builder.response_docstring_type(async_mode=self.async_mode)}"
|
|
733
|
-
)
|
|
626
|
+
response_str = f":return: {builder.response_docstring_text(async_mode=self.async_mode)}"
|
|
627
|
+
rtype_str = f":rtype: {builder.response_docstring_type(async_mode=self.async_mode)}"
|
|
734
628
|
return [
|
|
735
629
|
response_str,
|
|
736
630
|
rtype_str,
|
|
@@ -753,14 +647,8 @@ class _OperationSerializer(
|
|
|
753
647
|
else body_param.type
|
|
754
648
|
),
|
|
755
649
|
)
|
|
756
|
-
file_fields = [
|
|
757
|
-
|
|
758
|
-
]
|
|
759
|
-
data_fields = [
|
|
760
|
-
p.wire_name
|
|
761
|
-
for p in model_type.properties
|
|
762
|
-
if not p.is_multipart_file_input
|
|
763
|
-
]
|
|
650
|
+
file_fields = [p.wire_name for p in model_type.properties if p.is_multipart_file_input]
|
|
651
|
+
data_fields = [p.wire_name for p in model_type.properties if not p.is_multipart_file_input]
|
|
764
652
|
retval.extend(
|
|
765
653
|
[
|
|
766
654
|
"_body = (",
|
|
@@ -777,19 +665,13 @@ class _OperationSerializer(
|
|
|
777
665
|
|
|
778
666
|
body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name
|
|
779
667
|
send_xml = builder.parameters.body_parameter.type.is_xml
|
|
780
|
-
xml_serialization_ctxt =
|
|
781
|
-
body_param.type.xml_serialization_ctxt if send_xml else None
|
|
782
|
-
)
|
|
668
|
+
xml_serialization_ctxt = body_param.type.xml_serialization_ctxt if send_xml else None
|
|
783
669
|
ser_ctxt_name = "serialization_ctxt"
|
|
784
670
|
if xml_serialization_ctxt and self.code_model.options["models_mode"]:
|
|
785
671
|
retval.append(f'{ser_ctxt_name} = {{"xml": {{{xml_serialization_ctxt}}}}}')
|
|
786
672
|
if self.code_model.options["models_mode"] == "msrest":
|
|
787
|
-
is_xml_cmd = _xml_config(
|
|
788
|
-
|
|
789
|
-
)
|
|
790
|
-
serialization_ctxt_cmd = (
|
|
791
|
-
f", {ser_ctxt_name}={ser_ctxt_name}" if xml_serialization_ctxt else ""
|
|
792
|
-
)
|
|
673
|
+
is_xml_cmd = _xml_config(send_xml, builder.parameters.body_parameter.content_types)
|
|
674
|
+
serialization_ctxt_cmd = f", {ser_ctxt_name}={ser_ctxt_name}" if xml_serialization_ctxt else ""
|
|
793
675
|
create_body_call = (
|
|
794
676
|
f"_{body_kwarg_name} = self._serialize.body({body_param.client_name}, "
|
|
795
677
|
f"'{body_param.type.serialization_type}'{is_xml_cmd}{serialization_ctxt_cmd})"
|
|
@@ -832,17 +714,12 @@ class _OperationSerializer(
|
|
|
832
714
|
body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name
|
|
833
715
|
body_param_type = body_param.type
|
|
834
716
|
if isinstance(body_param_type, BinaryType) or (
|
|
835
|
-
isinstance(body_param.type, ByteArraySchema)
|
|
836
|
-
and body_param.default_content_type != "application/json"
|
|
717
|
+
isinstance(body_param.type, ByteArraySchema) and body_param.default_content_type != "application/json"
|
|
837
718
|
):
|
|
838
719
|
retval.append(f"_{body_kwarg_name} = {body_param.client_name}")
|
|
839
720
|
if (
|
|
840
721
|
not body_param.default_content_type
|
|
841
|
-
and not next(
|
|
842
|
-
p
|
|
843
|
-
for p in builder.parameters
|
|
844
|
-
if p.wire_name.lower() == "content-type"
|
|
845
|
-
).optional
|
|
722
|
+
and not next(p for p in builder.parameters if p.wire_name.lower() == "content-type").optional
|
|
846
723
|
):
|
|
847
724
|
content_types = "'" + "', '".join(body_param.content_types) + "'"
|
|
848
725
|
retval.extend(
|
|
@@ -856,30 +733,17 @@ class _OperationSerializer(
|
|
|
856
733
|
retval.extend(self._serialize_body_parameter(builder))
|
|
857
734
|
return retval
|
|
858
735
|
|
|
859
|
-
def _initialize_overloads(
|
|
860
|
-
self, builder: OperationType, is_paging: bool = False
|
|
861
|
-
) -> List[str]:
|
|
736
|
+
def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) -> List[str]:
|
|
862
737
|
retval: List[str] = []
|
|
863
738
|
# For paging, we put body parameter in local place outside `prepare_request`
|
|
864
739
|
if is_paging:
|
|
865
740
|
return retval
|
|
866
|
-
same_content_type = (
|
|
867
|
-
len(
|
|
868
|
-
set(
|
|
869
|
-
o.parameters.body_parameter.default_content_type
|
|
870
|
-
for o in builder.overloads
|
|
871
|
-
)
|
|
872
|
-
)
|
|
873
|
-
== 1
|
|
874
|
-
)
|
|
741
|
+
same_content_type = len(set(o.parameters.body_parameter.default_content_type for o in builder.overloads)) == 1
|
|
875
742
|
if same_content_type:
|
|
876
|
-
default_content_type = builder.overloads[
|
|
877
|
-
0
|
|
878
|
-
].parameters.body_parameter.default_content_type
|
|
743
|
+
default_content_type = builder.overloads[0].parameters.body_parameter.default_content_type
|
|
879
744
|
retval.append(f'content_type = content_type or "{default_content_type}"')
|
|
880
745
|
client_names = [
|
|
881
|
-
overload.request_builder.parameters.body_parameter.client_name
|
|
882
|
-
for overload in builder.overloads
|
|
746
|
+
overload.request_builder.parameters.body_parameter.client_name for overload in builder.overloads
|
|
883
747
|
]
|
|
884
748
|
for v in sorted(set(client_names), key=client_names.index):
|
|
885
749
|
retval.append(f"_{v} = None")
|
|
@@ -887,43 +751,20 @@ class _OperationSerializer(
|
|
|
887
751
|
# if there is a binary overload, we do a binary check first.
|
|
888
752
|
binary_overload = cast(
|
|
889
753
|
OperationType,
|
|
890
|
-
next(
|
|
891
|
-
(
|
|
892
|
-
o
|
|
893
|
-
for o in builder.overloads
|
|
894
|
-
if isinstance(o.parameters.body_parameter.type, BinaryType)
|
|
895
|
-
)
|
|
896
|
-
),
|
|
754
|
+
next((o for o in builder.overloads if isinstance(o.parameters.body_parameter.type, BinaryType))),
|
|
897
755
|
)
|
|
898
756
|
binary_body_param = binary_overload.parameters.body_parameter
|
|
899
|
-
retval.append(
|
|
900
|
-
f"if {binary_body_param.type.instance_check_template.format(binary_body_param.client_name)}:"
|
|
901
|
-
)
|
|
757
|
+
retval.append(f"if {binary_body_param.type.instance_check_template.format(binary_body_param.client_name)}:")
|
|
902
758
|
if binary_body_param.default_content_type and not same_content_type:
|
|
903
|
-
retval.append(
|
|
904
|
-
|
|
905
|
-
)
|
|
906
|
-
retval.extend(
|
|
907
|
-
f" {l}" for l in self._create_body_parameter(binary_overload)
|
|
908
|
-
)
|
|
759
|
+
retval.append(f' content_type = content_type or "{binary_body_param.default_content_type}"')
|
|
760
|
+
retval.extend(f" {l}" for l in self._create_body_parameter(binary_overload))
|
|
909
761
|
retval.append("else:")
|
|
910
762
|
other_overload = cast(
|
|
911
763
|
OperationType,
|
|
912
|
-
next(
|
|
913
|
-
(
|
|
914
|
-
o
|
|
915
|
-
for o in builder.overloads
|
|
916
|
-
if not isinstance(o.parameters.body_parameter.type, BinaryType)
|
|
917
|
-
)
|
|
918
|
-
),
|
|
919
|
-
)
|
|
920
|
-
retval.extend(
|
|
921
|
-
f" {l}" for l in self._create_body_parameter(other_overload)
|
|
764
|
+
next((o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType))),
|
|
922
765
|
)
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
and not same_content_type
|
|
926
|
-
):
|
|
766
|
+
retval.extend(f" {l}" for l in self._create_body_parameter(other_overload))
|
|
767
|
+
if other_overload.parameters.body_parameter.default_content_type and not same_content_type:
|
|
927
768
|
retval.append(
|
|
928
769
|
" content_type = content_type or "
|
|
929
770
|
f'"{other_overload.parameters.body_parameter.default_content_type}"'
|
|
@@ -936,13 +777,8 @@ class _OperationSerializer(
|
|
|
936
777
|
f"{if_statement} {body_param.type.instance_check_template.format(body_param.client_name)}:"
|
|
937
778
|
)
|
|
938
779
|
if body_param.default_content_type and not same_content_type:
|
|
939
|
-
retval.append(
|
|
940
|
-
|
|
941
|
-
)
|
|
942
|
-
retval.extend(
|
|
943
|
-
f" {l}"
|
|
944
|
-
for l in self._create_body_parameter(cast(OperationType, overload))
|
|
945
|
-
)
|
|
780
|
+
retval.append(f' content_type = content_type or "{body_param.default_content_type}"')
|
|
781
|
+
retval.extend(f" {l}" for l in self._create_body_parameter(cast(OperationType, overload)))
|
|
946
782
|
return retval
|
|
947
783
|
|
|
948
784
|
def _create_request_builder_call(
|
|
@@ -978,11 +814,7 @@ class _OperationSerializer(
|
|
|
978
814
|
type_ignore = (
|
|
979
815
|
parameter.grouped_by
|
|
980
816
|
and parameter.client_default_value is not None
|
|
981
|
-
and next(
|
|
982
|
-
p
|
|
983
|
-
for p in builder.parameters
|
|
984
|
-
if p.grouper and p.client_name == parameter.grouped_by
|
|
985
|
-
).optional
|
|
817
|
+
and next(p for p in builder.parameters if p.grouper and p.client_name == parameter.grouped_by).optional
|
|
986
818
|
)
|
|
987
819
|
retval.append(
|
|
988
820
|
f" {parameter.client_name}={parameter.name_in_high_level_operation},"
|
|
@@ -998,38 +830,25 @@ class _OperationSerializer(
|
|
|
998
830
|
elif request_builder.overloads:
|
|
999
831
|
seen_body_params = set()
|
|
1000
832
|
for overload in request_builder.overloads:
|
|
1001
|
-
body_param = cast(
|
|
1002
|
-
RequestBuilderBodyParameter, overload.parameters.body_parameter
|
|
1003
|
-
)
|
|
833
|
+
body_param = cast(RequestBuilderBodyParameter, overload.parameters.body_parameter)
|
|
1004
834
|
if body_param.client_name in seen_body_params:
|
|
1005
835
|
continue
|
|
1006
836
|
seen_body_params.add(body_param.client_name)
|
|
1007
837
|
|
|
1008
|
-
retval.append(
|
|
1009
|
-
f" {body_param.client_name}={body_param.name_in_high_level_operation},"
|
|
1010
|
-
)
|
|
838
|
+
retval.append(f" {body_param.client_name}={body_param.name_in_high_level_operation},")
|
|
1011
839
|
elif request_builder.parameters.has_body:
|
|
1012
|
-
body_param = cast(
|
|
1013
|
-
|
|
1014
|
-
)
|
|
1015
|
-
retval.append(
|
|
1016
|
-
f" {body_param.client_name}={body_param.name_in_high_level_operation},"
|
|
1017
|
-
)
|
|
840
|
+
body_param = cast(RequestBuilderBodyParameter, request_builder.parameters.body_parameter)
|
|
841
|
+
retval.append(f" {body_param.client_name}={body_param.name_in_high_level_operation},")
|
|
1018
842
|
retval.append(" headers=_headers,")
|
|
1019
843
|
retval.append(" params=_params,")
|
|
1020
844
|
retval.append(")")
|
|
1021
845
|
return retval
|
|
1022
846
|
|
|
1023
|
-
def _postprocess_http_request(
|
|
1024
|
-
self, builder: OperationType, template_url: Optional[str] = None
|
|
1025
|
-
) -> List[str]:
|
|
847
|
+
def _postprocess_http_request(self, builder: OperationType, template_url: Optional[str] = None) -> List[str]:
|
|
1026
848
|
retval: List[str] = []
|
|
1027
849
|
if not self.code_model.options["version_tolerant"]:
|
|
1028
850
|
pass_files = ""
|
|
1029
|
-
if
|
|
1030
|
-
builder.parameters.has_body
|
|
1031
|
-
and builder.parameters.body_parameter.client_name == "files"
|
|
1032
|
-
):
|
|
851
|
+
if builder.parameters.has_body and builder.parameters.body_parameter.client_name == "files":
|
|
1033
852
|
pass_files = ", _files"
|
|
1034
853
|
retval.append(f"_request = _convert_request(_request{pass_files})")
|
|
1035
854
|
if builder.parameters.path:
|
|
@@ -1061,11 +880,7 @@ class _OperationSerializer(
|
|
|
1061
880
|
# unflatten before passing to request builder as well
|
|
1062
881
|
retval.extend(_serialize_flattened_body(builder.parameters.body_parameter))
|
|
1063
882
|
if is_json_model_type(builder.parameters):
|
|
1064
|
-
retval.extend(
|
|
1065
|
-
_serialize_json_model_body(
|
|
1066
|
-
builder.parameters.body_parameter, builder.parameters.parameters
|
|
1067
|
-
)
|
|
1068
|
-
)
|
|
883
|
+
retval.extend(_serialize_json_model_body(builder.parameters.body_parameter, builder.parameters.parameters))
|
|
1069
884
|
if builder.has_form_data_body:
|
|
1070
885
|
retval.extend(self._create_body_parameter(builder))
|
|
1071
886
|
elif builder.overloads:
|
|
@@ -1075,18 +890,12 @@ class _OperationSerializer(
|
|
|
1075
890
|
# non-overloaded body
|
|
1076
891
|
retval.extend(self._create_body_parameter(builder))
|
|
1077
892
|
retval.append("")
|
|
1078
|
-
retval.extend(
|
|
1079
|
-
self._create_request_builder_call(builder, request_builder, is_next_request)
|
|
1080
|
-
)
|
|
893
|
+
retval.extend(self._create_request_builder_call(builder, request_builder, is_next_request))
|
|
1081
894
|
retval.extend(self._postprocess_http_request(builder, template_url))
|
|
1082
895
|
return retval
|
|
1083
896
|
|
|
1084
|
-
def call_request_builder(
|
|
1085
|
-
self, builder
|
|
1086
|
-
) -> List[str]:
|
|
1087
|
-
return self._call_request_builder_helper(
|
|
1088
|
-
builder, builder.request_builder, is_paging=is_paging
|
|
1089
|
-
)
|
|
897
|
+
def call_request_builder(self, builder: OperationType, is_paging: bool = False) -> List[str]:
|
|
898
|
+
return self._call_request_builder_helper(builder, builder.request_builder, is_paging=is_paging)
|
|
1090
899
|
|
|
1091
900
|
def response_headers_and_deserialization(
|
|
1092
901
|
self,
|
|
@@ -1112,9 +921,7 @@ class _OperationSerializer(
|
|
|
1112
921
|
if self.code_model.options["version_tolerant"]:
|
|
1113
922
|
deserialized = "response.iter_bytes()"
|
|
1114
923
|
else:
|
|
1115
|
-
deserialized = (
|
|
1116
|
-
f"response.stream_download(self._client.{self.pipeline_name})"
|
|
1117
|
-
)
|
|
924
|
+
deserialized = f"response.stream_download(self._client.{self.pipeline_name})"
|
|
1118
925
|
deserialize_code.append(f"deserialized = {deserialized}")
|
|
1119
926
|
elif response.type:
|
|
1120
927
|
pylint_disable = ""
|
|
@@ -1122,9 +929,7 @@ class _OperationSerializer(
|
|
|
1122
929
|
pylint_disable = " # pylint: disable=protected-access"
|
|
1123
930
|
if self.code_model.options["models_mode"] == "msrest":
|
|
1124
931
|
deserialize_code.append("deserialized = self._deserialize(")
|
|
1125
|
-
deserialize_code.append(
|
|
1126
|
-
f" '{response.serialization_type}',{pylint_disable}"
|
|
1127
|
-
)
|
|
932
|
+
deserialize_code.append(f" '{response.serialization_type}',{pylint_disable}")
|
|
1128
933
|
deserialize_code.append(" pipeline_response")
|
|
1129
934
|
deserialize_code.append(")")
|
|
1130
935
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
@@ -1137,26 +942,16 @@ class _OperationSerializer(
|
|
|
1137
942
|
and response.default_content_type == "application/json"
|
|
1138
943
|
else ""
|
|
1139
944
|
)
|
|
1140
|
-
response_attr = (
|
|
1141
|
-
"json"
|
|
1142
|
-
if _json_serializable(str(response.default_content_type))
|
|
1143
|
-
else "text"
|
|
1144
|
-
)
|
|
945
|
+
response_attr = "json" if _json_serializable(str(response.default_content_type)) else "text"
|
|
1145
946
|
deserialize_code.append("deserialized = _deserialize(")
|
|
1146
947
|
deserialize_code.append(
|
|
1147
948
|
f" {response.type.type_annotation(is_operation_file=True)},{pylint_disable}"
|
|
1148
949
|
)
|
|
1149
|
-
deserialize_code.append(
|
|
1150
|
-
f" response.{response_attr}(){response.result_property}{format_filed}"
|
|
1151
|
-
)
|
|
950
|
+
deserialize_code.append(f" response.{response_attr}(){response.result_property}{format_filed}")
|
|
1152
951
|
deserialize_code.append(")")
|
|
1153
952
|
|
|
1154
953
|
else:
|
|
1155
|
-
deserialized_value = (
|
|
1156
|
-
"ET.fromstring(response.text())"
|
|
1157
|
-
if response.type.is_xml
|
|
1158
|
-
else "response.json()"
|
|
1159
|
-
)
|
|
954
|
+
deserialized_value = "ET.fromstring(response.text())" if response.type.is_xml else "response.json()"
|
|
1160
955
|
deserialize_code.append("if response.content:")
|
|
1161
956
|
deserialize_code.append(f" deserialized = {deserialized_value}")
|
|
1162
957
|
deserialize_code.append("else:")
|
|
@@ -1173,9 +968,7 @@ class _OperationSerializer(
|
|
|
1173
968
|
|
|
1174
969
|
def handle_error_response(self, builder: OperationType) -> List[str]:
|
|
1175
970
|
async_await = "await " if self.async_mode else ""
|
|
1176
|
-
retval = [
|
|
1177
|
-
f"if response.status_code not in {str(builder.success_status_codes)}:"
|
|
1178
|
-
]
|
|
971
|
+
retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
|
|
1179
972
|
if not self.code_model.need_request_converter:
|
|
1180
973
|
retval.extend(
|
|
1181
974
|
[
|
|
@@ -1188,14 +981,9 @@ class _OperationSerializer(
|
|
|
1188
981
|
f" map_error(status_code=response.status_code, response=response, error_map=error_map){type_ignore}"
|
|
1189
982
|
)
|
|
1190
983
|
error_model = ""
|
|
1191
|
-
if
|
|
1192
|
-
builder.default_error_deserialization
|
|
1193
|
-
and self.code_model.options["models_mode"]
|
|
1194
|
-
):
|
|
984
|
+
if builder.default_error_deserialization and self.code_model.options["models_mode"]:
|
|
1195
985
|
if self.code_model.options["models_mode"] == "dpg":
|
|
1196
|
-
retval.append(
|
|
1197
|
-
f" error = _deserialize({builder.default_error_deserialization}, response.json())"
|
|
1198
|
-
)
|
|
986
|
+
retval.append(f" error = _deserialize({builder.default_error_deserialization}, response.json())")
|
|
1199
987
|
else:
|
|
1200
988
|
retval.append(
|
|
1201
989
|
f" error = self._deserialize.failsafe_deserialize({builder.default_error_deserialization}, "
|
|
@@ -1205,11 +993,7 @@ class _OperationSerializer(
|
|
|
1205
993
|
retval.append(
|
|
1206
994
|
" raise HttpResponseError(response=response{}{})".format(
|
|
1207
995
|
error_model,
|
|
1208
|
-
(
|
|
1209
|
-
", error_format=ARMErrorFormat"
|
|
1210
|
-
if self.code_model.options["azure_arm"]
|
|
1211
|
-
else ""
|
|
1212
|
-
),
|
|
996
|
+
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
|
|
1213
997
|
)
|
|
1214
998
|
)
|
|
1215
999
|
return retval
|
|
@@ -1230,20 +1014,11 @@ class _OperationSerializer(
|
|
|
1230
1014
|
if response.headers or response.type:
|
|
1231
1015
|
retval.append(f"if response.status_code == {status_code}:")
|
|
1232
1016
|
retval.extend(
|
|
1233
|
-
[
|
|
1234
|
-
f" {line}"
|
|
1235
|
-
for line in self.response_headers_and_deserialization(
|
|
1236
|
-
builder, response
|
|
1237
|
-
)
|
|
1238
|
-
]
|
|
1017
|
+
[f" {line}" for line in self.response_headers_and_deserialization(builder, response)]
|
|
1239
1018
|
)
|
|
1240
1019
|
retval.append("")
|
|
1241
1020
|
else:
|
|
1242
|
-
retval.extend(
|
|
1243
|
-
self.response_headers_and_deserialization(
|
|
1244
|
-
builder, builder.responses[0]
|
|
1245
|
-
)
|
|
1246
|
-
)
|
|
1021
|
+
retval.extend(self.response_headers_and_deserialization(builder, builder.responses[0]))
|
|
1247
1022
|
retval.append("")
|
|
1248
1023
|
if builder.has_optional_return_type or self.code_model.options["models_mode"]:
|
|
1249
1024
|
deserialized = "deserialized"
|
|
@@ -1258,15 +1033,11 @@ class _OperationSerializer(
|
|
|
1258
1033
|
)
|
|
1259
1034
|
)
|
|
1260
1035
|
if builder.has_response_body and any(
|
|
1261
|
-
response.is_stream_response or response.type
|
|
1262
|
-
for response in builder.responses
|
|
1036
|
+
response.is_stream_response or response.type for response in builder.responses
|
|
1263
1037
|
):
|
|
1264
1038
|
retval.append("")
|
|
1265
1039
|
retval.append(f"return {deserialized} # type: ignore")
|
|
1266
|
-
if
|
|
1267
|
-
builder.request_builder.method == "HEAD"
|
|
1268
|
-
and self.code_model.options["head_as_boolean"]
|
|
1269
|
-
):
|
|
1040
|
+
if builder.request_builder.method == "HEAD" and self.code_model.options["head_as_boolean"]:
|
|
1270
1041
|
retval.append("return 200 <= response.status_code <= 299")
|
|
1271
1042
|
return retval
|
|
1272
1043
|
|
|
@@ -1286,16 +1057,11 @@ class _OperationSerializer(
|
|
|
1286
1057
|
if isinstance(excep.type, ModelType):
|
|
1287
1058
|
if self.code_model.options["models_mode"] == "msrest":
|
|
1288
1059
|
error_model_str = (
|
|
1289
|
-
f", model=self._deserialize("
|
|
1290
|
-
f"_models.{excep.type.serialization_type}, response)"
|
|
1060
|
+
f", model=self._deserialize(" f"_models.{excep.type.serialization_type}, response)"
|
|
1291
1061
|
)
|
|
1292
1062
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
1293
1063
|
error_model_str = f", model=_deserialize(_models.{excep.type.name}, response.json())"
|
|
1294
|
-
error_format_str =
|
|
1295
|
-
", error_format=ARMErrorFormat"
|
|
1296
|
-
if self.code_model.options["azure_arm"]
|
|
1297
|
-
else ""
|
|
1298
|
-
)
|
|
1064
|
+
error_format_str = ", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""
|
|
1299
1065
|
for status_code in excep.status_codes:
|
|
1300
1066
|
if status_code == 401:
|
|
1301
1067
|
retval.append(
|
|
@@ -1359,14 +1125,10 @@ class OperationSerializer(_OperationSerializer[Operation]): ...
|
|
|
1359
1125
|
|
|
1360
1126
|
############################## PAGING OPERATIONS ##############################
|
|
1361
1127
|
|
|
1362
|
-
PagingOperationType = TypeVar(
|
|
1363
|
-
"PagingOperationType", bound=Union[PagingOperation, LROPagingOperation]
|
|
1364
|
-
)
|
|
1128
|
+
PagingOperationType = TypeVar("PagingOperationType", bound=Union[PagingOperation, LROPagingOperation])
|
|
1365
1129
|
|
|
1366
1130
|
|
|
1367
|
-
class _PagingOperationSerializer(
|
|
1368
|
-
_OperationSerializer[PagingOperationType]
|
|
1369
|
-
): # pylint: disable=abstract-method
|
|
1131
|
+
class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]): # pylint: disable=abstract-method
|
|
1370
1132
|
def __init__(self, code_model: CodeModel, async_mode: bool) -> None:
|
|
1371
1133
|
# for pylint reasons need to redefine init
|
|
1372
1134
|
# probably because inheritance is going too deep
|
|
@@ -1376,9 +1138,7 @@ class _PagingOperationSerializer(
|
|
|
1376
1138
|
self.parameter_serializer = ParameterSerializer()
|
|
1377
1139
|
|
|
1378
1140
|
def serialize_path(self, builder: PagingOperationType) -> List[str]:
|
|
1379
|
-
return self.parameter_serializer.serialize_path(
|
|
1380
|
-
builder.parameters.path, self.serializer_name
|
|
1381
|
-
)
|
|
1141
|
+
return self.parameter_serializer.serialize_path(builder.parameters.path, self.serializer_name)
|
|
1382
1142
|
|
|
1383
1143
|
def decorators(self, builder: PagingOperationType) -> List[str]:
|
|
1384
1144
|
"""Decorators for the method"""
|
|
@@ -1412,9 +1172,7 @@ class _PagingOperationSerializer(
|
|
|
1412
1172
|
next_link_str = "next_link"
|
|
1413
1173
|
try:
|
|
1414
1174
|
api_version_param = next(
|
|
1415
|
-
p
|
|
1416
|
-
for p in builder.client.parameters
|
|
1417
|
-
if p.is_api_version and p.location == ParameterLocation.QUERY
|
|
1175
|
+
p for p in builder.client.parameters if p.is_api_version and p.location == ParameterLocation.QUERY
|
|
1418
1176
|
)
|
|
1419
1177
|
retval.append("# make call to next link with the client's api-version")
|
|
1420
1178
|
retval.append("_parsed_next_link = urllib.parse.urlparse(next_link)")
|
|
@@ -1446,17 +1204,10 @@ class _PagingOperationSerializer(
|
|
|
1446
1204
|
retval = self._initialize_overloads(builder)
|
|
1447
1205
|
retval.append("def prepare_request(next_link=None):")
|
|
1448
1206
|
retval.append(" if not next_link:")
|
|
1449
|
-
retval.extend(
|
|
1450
|
-
[
|
|
1451
|
-
f" {line}"
|
|
1452
|
-
for line in self.call_request_builder(builder, is_paging=True)
|
|
1453
|
-
]
|
|
1454
|
-
)
|
|
1207
|
+
retval.extend([f" {line}" for line in self.call_request_builder(builder, is_paging=True)])
|
|
1455
1208
|
retval.append("")
|
|
1456
1209
|
retval.append(" else:")
|
|
1457
|
-
retval.extend(
|
|
1458
|
-
[f" {line}" for line in self.call_next_link_request_builder(builder)]
|
|
1459
|
-
)
|
|
1210
|
+
retval.extend([f" {line}" for line in self.call_next_link_request_builder(builder)])
|
|
1460
1211
|
if not builder.next_request_builder and self.code_model.is_legacy:
|
|
1461
1212
|
retval.append(' _request.method = "GET"')
|
|
1462
1213
|
else:
|
|
@@ -1469,9 +1220,7 @@ class _PagingOperationSerializer(
|
|
|
1469
1220
|
return "def"
|
|
1470
1221
|
|
|
1471
1222
|
def _extract_data_callback(self, builder: PagingOperationType) -> List[str]:
|
|
1472
|
-
retval = [
|
|
1473
|
-
f"{'async ' if self.async_mode else ''}def extract_data(pipeline_response):"
|
|
1474
|
-
]
|
|
1223
|
+
retval = [f"{'async ' if self.async_mode else ''}def extract_data(pipeline_response):"]
|
|
1475
1224
|
response = builder.responses[0]
|
|
1476
1225
|
deserialized = "pipeline_response.http_response.json()"
|
|
1477
1226
|
if self.code_model.options["models_mode"] == "msrest":
|
|
@@ -1488,17 +1237,11 @@ class _PagingOperationSerializer(
|
|
|
1488
1237
|
else:
|
|
1489
1238
|
retval.append(f" deserialized = {deserialized}")
|
|
1490
1239
|
item_name = builder.item_name
|
|
1491
|
-
access =
|
|
1492
|
-
f".{item_name}"
|
|
1493
|
-
if self.code_model.options["models_mode"] == "msrest"
|
|
1494
|
-
else f'["{item_name}"]'
|
|
1495
|
-
)
|
|
1240
|
+
access = f".{item_name}" if self.code_model.options["models_mode"] == "msrest" else f'["{item_name}"]'
|
|
1496
1241
|
list_of_elem_deserialized = ""
|
|
1497
1242
|
if self.code_model.options["models_mode"] == "dpg":
|
|
1498
1243
|
item_type = builder.item_type.type_annotation(is_operation_file=True)
|
|
1499
|
-
list_of_elem_deserialized = (
|
|
1500
|
-
f"_deserialize({item_type}, deserialized{access})"
|
|
1501
|
-
)
|
|
1244
|
+
list_of_elem_deserialized = f"_deserialize({item_type}, deserialized{access})"
|
|
1502
1245
|
else:
|
|
1503
1246
|
list_of_elem_deserialized = f"deserialized{access}"
|
|
1504
1247
|
retval.append(f" list_of_elem = {list_of_elem_deserialized}")
|
|
@@ -1511,9 +1254,7 @@ class _PagingOperationSerializer(
|
|
|
1511
1254
|
elif self.code_model.options["models_mode"] == "msrest":
|
|
1512
1255
|
cont_token_property = f"deserialized.{continuation_token_name} or None"
|
|
1513
1256
|
else:
|
|
1514
|
-
cont_token_property = (
|
|
1515
|
-
f'deserialized.get("{continuation_token_name}") or None'
|
|
1516
|
-
)
|
|
1257
|
+
cont_token_property = f'deserialized.get("{continuation_token_name}") or None'
|
|
1517
1258
|
list_type = "AsyncList" if self.async_mode else "iter"
|
|
1518
1259
|
retval.append(f" return {cont_token_property}, {list_type}(list_of_elem)")
|
|
1519
1260
|
return retval
|
|
@@ -1546,9 +1287,7 @@ class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]): ..
|
|
|
1546
1287
|
|
|
1547
1288
|
############################## LRO OPERATIONS ##############################
|
|
1548
1289
|
|
|
1549
|
-
LROOperationType = TypeVar(
|
|
1550
|
-
"LROOperationType", bound=Union[LROOperation, LROPagingOperation]
|
|
1551
|
-
)
|
|
1290
|
+
LROOperationType = TypeVar("LROOperationType", bound=Union[LROOperation, LROPagingOperation])
|
|
1552
1291
|
|
|
1553
1292
|
|
|
1554
1293
|
class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
@@ -1561,9 +1300,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1561
1300
|
self.parameter_serializer = ParameterSerializer()
|
|
1562
1301
|
|
|
1563
1302
|
def serialize_path(self, builder: LROOperationType) -> List[str]:
|
|
1564
|
-
return self.parameter_serializer.serialize_path(
|
|
1565
|
-
builder.parameters.path, self.serializer_name
|
|
1566
|
-
)
|
|
1303
|
+
return self.parameter_serializer.serialize_path(builder.parameters.path, self.serializer_name)
|
|
1567
1304
|
|
|
1568
1305
|
def initial_call(self, builder: LROOperationType) -> List[str]:
|
|
1569
1306
|
retval = [
|
|
@@ -1573,19 +1310,14 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1573
1310
|
retval.append(" 'polling_interval',")
|
|
1574
1311
|
retval.append(" self._config.polling_interval")
|
|
1575
1312
|
retval.append(")")
|
|
1576
|
-
retval.append(
|
|
1577
|
-
"cont_token: Optional[str] = kwargs.pop('continuation_token', None)"
|
|
1578
|
-
)
|
|
1313
|
+
retval.append("cont_token: Optional[str] = kwargs.pop('continuation_token', None)")
|
|
1579
1314
|
retval.append("if cont_token is None:")
|
|
1580
1315
|
retval.append(
|
|
1581
1316
|
f" raw_result = {self._call_method}self.{builder.initial_operation.name}("
|
|
1582
1317
|
f"{'' if any(rsp.type for rsp in builder.initial_operation.responses) else ' # type: ignore'}"
|
|
1583
1318
|
)
|
|
1584
1319
|
retval.extend(
|
|
1585
|
-
[
|
|
1586
|
-
f" {parameter.client_name}={parameter.client_name},"
|
|
1587
|
-
for parameter in builder.parameters.method
|
|
1588
|
-
]
|
|
1320
|
+
[f" {parameter.client_name}={parameter.client_name}," for parameter in builder.parameters.method]
|
|
1589
1321
|
)
|
|
1590
1322
|
retval.append(" cls=lambda x,y,z: x,")
|
|
1591
1323
|
retval.append(" headers=_headers,")
|
|
@@ -1598,9 +1330,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1598
1330
|
def return_lro_poller(self, builder: LROOperationType) -> List[str]:
|
|
1599
1331
|
retval = []
|
|
1600
1332
|
lro_options_str = (
|
|
1601
|
-
"lro_options={'final-state-via': '"
|
|
1602
|
-
+ builder.lro_options["final-state-via"]
|
|
1603
|
-
+ "'},"
|
|
1333
|
+
"lro_options={'final-state-via': '" + builder.lro_options["final-state-via"] + "'},"
|
|
1604
1334
|
if builder.lro_options
|
|
1605
1335
|
else ""
|
|
1606
1336
|
)
|
|
@@ -1628,20 +1358,14 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1628
1358
|
)
|
|
1629
1359
|
retval.append("else: polling_method = polling")
|
|
1630
1360
|
retval.append("if cont_token:")
|
|
1631
|
-
retval.append(
|
|
1632
|
-
f" return {builder.get_poller_with_response_type(self.async_mode)}.from_continuation_token("
|
|
1633
|
-
)
|
|
1361
|
+
retval.append(f" return {builder.get_poller_with_response_type(self.async_mode)}.from_continuation_token(")
|
|
1634
1362
|
retval.append(" polling_method=polling_method,")
|
|
1635
1363
|
retval.append(" continuation_token=cont_token,")
|
|
1636
1364
|
retval.append(" client=self._client,")
|
|
1637
1365
|
retval.append(" deserialization_callback=get_long_running_output")
|
|
1638
1366
|
retval.append(" )")
|
|
1639
|
-
retval.append(
|
|
1640
|
-
|
|
1641
|
-
)
|
|
1642
|
-
retval.append(
|
|
1643
|
-
" self._client, raw_result, get_long_running_output, polling_method # type: ignore"
|
|
1644
|
-
)
|
|
1367
|
+
retval.append(f"return {builder.get_poller_with_response_type(self.async_mode)}(")
|
|
1368
|
+
retval.append(" self._client, raw_result, get_long_running_output, polling_method # type: ignore")
|
|
1645
1369
|
retval.append(" )")
|
|
1646
1370
|
return retval
|
|
1647
1371
|
|
|
@@ -1660,26 +1384,13 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1660
1384
|
):
|
|
1661
1385
|
retval.append(" response = pipeline_response.http_response")
|
|
1662
1386
|
retval.extend(
|
|
1663
|
-
[
|
|
1664
|
-
f" {line}"
|
|
1665
|
-
for line in self.response_headers_and_deserialization(
|
|
1666
|
-
builder, builder.lro_response
|
|
1667
|
-
)
|
|
1668
|
-
]
|
|
1387
|
+
[f" {line}" for line in self.response_headers_and_deserialization(builder, builder.lro_response)]
|
|
1669
1388
|
)
|
|
1670
1389
|
retval.append(" if cls:")
|
|
1671
1390
|
retval.append(
|
|
1672
1391
|
" return cls(pipeline_response, {}, {}){}".format(
|
|
1673
|
-
(
|
|
1674
|
-
|
|
1675
|
-
if builder.lro_response and builder.lro_response.type
|
|
1676
|
-
else "None"
|
|
1677
|
-
),
|
|
1678
|
-
(
|
|
1679
|
-
"response_headers"
|
|
1680
|
-
if builder.lro_response and builder.lro_response.headers
|
|
1681
|
-
else "{}"
|
|
1682
|
-
),
|
|
1392
|
+
("deserialized" if builder.lro_response and builder.lro_response.type else "None"),
|
|
1393
|
+
("response_headers" if builder.lro_response and builder.lro_response.headers else "{}"),
|
|
1683
1394
|
" # type: ignore",
|
|
1684
1395
|
)
|
|
1685
1396
|
)
|