@autorest/python 6.13.16 → 6.13.18
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 +25 -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 +13 -51
- 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/serialization.py.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 +43 -129
- 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
|
@@ -111,9 +111,7 @@ def update_enum(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
111
111
|
return base
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
def update_property(
|
|
115
|
-
yaml_data: Dict[str, Any], has_additional_properties: bool
|
|
116
|
-
) -> Dict[str, Any]:
|
|
114
|
+
def update_property(yaml_data: Dict[str, Any], has_additional_properties: bool) -> Dict[str, Any]:
|
|
117
115
|
client_name = yaml_data["language"]["default"]["name"]
|
|
118
116
|
if has_additional_properties and client_name == "additional_properties":
|
|
119
117
|
client_name = "additional_properties1"
|
|
@@ -150,9 +148,7 @@ def create_model(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
150
148
|
return base
|
|
151
149
|
|
|
152
150
|
|
|
153
|
-
def fill_model(
|
|
154
|
-
yaml_data: Dict[str, Any], current_model: Dict[str, Any]
|
|
155
|
-
) -> Dict[str, Any]:
|
|
151
|
+
def fill_model(yaml_data: Dict[str, Any], current_model: Dict[str, Any]) -> Dict[str, Any]:
|
|
156
152
|
properties = []
|
|
157
153
|
yaml_parents = yaml_data.get("parents", {}).get("immediate", [])
|
|
158
154
|
dict_parents = [p for p in yaml_parents if p["type"] == "dictionary"]
|
|
@@ -170,17 +166,12 @@ def fill_model(
|
|
|
170
166
|
}
|
|
171
167
|
)
|
|
172
168
|
properties.extend(
|
|
173
|
-
[
|
|
174
|
-
update_property(p, has_additional_properties=bool(dict_parents))
|
|
175
|
-
for p in yaml_data.get("properties", [])
|
|
176
|
-
]
|
|
169
|
+
[update_property(p, has_additional_properties=bool(dict_parents)) for p in yaml_data.get("properties", [])]
|
|
177
170
|
)
|
|
178
171
|
current_model.update(
|
|
179
172
|
{
|
|
180
173
|
"properties": properties,
|
|
181
|
-
"parents": [
|
|
182
|
-
update_type(yaml_data=p) for p in yaml_parents if p["type"] == "object"
|
|
183
|
-
],
|
|
174
|
+
"parents": [update_type(yaml_data=p) for p in yaml_parents if p["type"] == "object"],
|
|
184
175
|
"discriminatedSubtypes": update_discriminated_subtypes(yaml_data),
|
|
185
176
|
"discriminatorValue": yaml_data.get("discriminatorValue"),
|
|
186
177
|
}
|
|
@@ -253,11 +244,7 @@ def update_types(yaml_data: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
|
253
244
|
if KNOWN_TYPES.get(type["type"]):
|
|
254
245
|
types.append(KNOWN_TYPES[type["type"]])
|
|
255
246
|
else:
|
|
256
|
-
types.append(
|
|
257
|
-
next(
|
|
258
|
-
v for v in ORIGINAL_ID_TO_UPDATED_TYPE.values() if id(v) == id(type)
|
|
259
|
-
)
|
|
260
|
-
)
|
|
247
|
+
types.append(next(v for v in ORIGINAL_ID_TO_UPDATED_TYPE.values() if id(v) == id(type)))
|
|
261
248
|
retval = {"type": "combined", "types": types}
|
|
262
249
|
ORIGINAL_ID_TO_UPDATED_TYPE[id(retval)] = retval
|
|
263
250
|
return retval
|
|
@@ -318,17 +305,11 @@ def add_lro_information(
|
|
|
318
305
|
for response in operation["responses"]:
|
|
319
306
|
response["pollerSync"] = extensions.get("x-python-custom-poller-sync")
|
|
320
307
|
response["pollerAsync"] = extensions.get("x-python-custom-poller-async")
|
|
321
|
-
response["pollingMethodSync"] = extensions.get(
|
|
322
|
-
|
|
323
|
-
)
|
|
324
|
-
response["pollingMethodAsync"] = extensions.get(
|
|
325
|
-
"x-python-custom-default-polling-method-async"
|
|
326
|
-
)
|
|
308
|
+
response["pollingMethodSync"] = extensions.get("x-python-custom-default-polling-method-sync")
|
|
309
|
+
response["pollingMethodAsync"] = extensions.get("x-python-custom-default-polling-method-async")
|
|
327
310
|
|
|
328
311
|
|
|
329
|
-
def filter_out_paging_next_operation(
|
|
330
|
-
yaml_data: List[Dict[str, Any]]
|
|
331
|
-
) -> List[Dict[str, Any]]:
|
|
312
|
+
def filter_out_paging_next_operation(yaml_data: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
332
313
|
next_operations: Set[str] = set()
|
|
333
314
|
for operation in yaml_data:
|
|
334
315
|
next_operation = operation.get("nextOperation")
|
|
@@ -355,13 +336,9 @@ def update_response(
|
|
|
355
336
|
else:
|
|
356
337
|
type = None
|
|
357
338
|
return {
|
|
358
|
-
"headers": [
|
|
359
|
-
update_response_header(h)
|
|
360
|
-
for h in yaml_data["protocol"]["http"].get("headers", [])
|
|
361
|
-
],
|
|
339
|
+
"headers": [update_response_header(h) for h in yaml_data["protocol"]["http"].get("headers", [])],
|
|
362
340
|
"statusCodes": [
|
|
363
|
-
int(code) if code != "default" else "default"
|
|
364
|
-
for code in yaml_data["protocol"]["http"]["statusCodes"]
|
|
341
|
+
int(code) if code != "default" else "default" for code in yaml_data["protocol"]["http"]["statusCodes"]
|
|
365
342
|
],
|
|
366
343
|
"type": type,
|
|
367
344
|
"nullable": yaml_data.get("nullable", False),
|
|
@@ -391,28 +368,20 @@ def _get_default_content_type( # pylint: disable=too-many-return-statements
|
|
|
391
368
|
|
|
392
369
|
|
|
393
370
|
def update_client_url(yaml_data: Dict[str, Any]) -> str:
|
|
394
|
-
if any(
|
|
395
|
-
p
|
|
396
|
-
for p in yaml_data["globalParameters"]
|
|
397
|
-
if p["language"]["default"]["name"] == "$host"
|
|
398
|
-
):
|
|
371
|
+
if any(p for p in yaml_data["globalParameters"] if p["language"]["default"]["name"] == "$host"):
|
|
399
372
|
# this means we DO NOT have a parameterized host
|
|
400
373
|
# in order to share code better, going to make it a "parameterized host" of
|
|
401
374
|
# just the endpoint parameter
|
|
402
375
|
return "{endpoint}"
|
|
403
376
|
# we have a parameterized host. Return first url from first request, quite gross
|
|
404
|
-
return yaml_data["operationGroups"][0]["operations"][0]["requests"][0]["protocol"][
|
|
405
|
-
"http"
|
|
406
|
-
]["uri"]
|
|
377
|
+
return yaml_data["operationGroups"][0]["operations"][0]["requests"][0]["protocol"]["http"]["uri"]
|
|
407
378
|
|
|
408
379
|
|
|
409
380
|
def to_lower_camel_case(name: str) -> str:
|
|
410
381
|
return re.sub(r"_([a-z])", lambda x: x.group(1).upper(), name)
|
|
411
382
|
|
|
412
383
|
|
|
413
|
-
class M4Reformatter(
|
|
414
|
-
YamlUpdatePluginAutorest
|
|
415
|
-
): # pylint: disable=too-many-public-methods
|
|
384
|
+
class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-public-methods
|
|
416
385
|
"""Add Python naming information."""
|
|
417
386
|
|
|
418
387
|
def __init__(self, *args, **kwargs) -> None:
|
|
@@ -443,10 +412,7 @@ class M4Reformatter(
|
|
|
443
412
|
|
|
444
413
|
@property
|
|
445
414
|
def default_optional_constants_to_none(self) -> bool:
|
|
446
|
-
return bool(
|
|
447
|
-
self._autorestapi.get_boolean_value("default-optional-constants-to-none")
|
|
448
|
-
or self.version_tolerant
|
|
449
|
-
)
|
|
415
|
+
return bool(self._autorestapi.get_boolean_value("default-optional-constants-to-none") or self.version_tolerant)
|
|
450
416
|
|
|
451
417
|
def update_parameter_base(
|
|
452
418
|
self, yaml_data: Dict[str, Any], *, override_client_name: Optional[str] = None
|
|
@@ -456,14 +422,8 @@ class M4Reformatter(
|
|
|
456
422
|
location = "other"
|
|
457
423
|
if location == "uri":
|
|
458
424
|
location = "endpointPath"
|
|
459
|
-
grouped_by = (
|
|
460
|
-
|
|
461
|
-
if yaml_data.get("groupedBy")
|
|
462
|
-
else None
|
|
463
|
-
)
|
|
464
|
-
client_name: str = (
|
|
465
|
-
override_client_name or yaml_data["language"]["default"]["name"]
|
|
466
|
-
)
|
|
425
|
+
grouped_by = yaml_data["groupedBy"]["language"]["default"]["name"] if yaml_data.get("groupedBy") else None
|
|
426
|
+
client_name: str = override_client_name or yaml_data["language"]["default"]["name"]
|
|
467
427
|
if grouped_by and client_name[0] != "_":
|
|
468
428
|
# this is an m4 bug, doesn't hide constant grouped params, patching m4 for now
|
|
469
429
|
client_name = "_" + client_name
|
|
@@ -502,17 +462,11 @@ class M4Reformatter(
|
|
|
502
462
|
if not body_types:
|
|
503
463
|
return overloads
|
|
504
464
|
for body_type in body_types:
|
|
505
|
-
overload = self.update_overload(
|
|
506
|
-
|
|
507
|
-
)
|
|
508
|
-
overload["internal"] = yaml_data.get("extensions", {}).get(
|
|
509
|
-
"x-ms-internal", False
|
|
510
|
-
)
|
|
465
|
+
overload = self.update_overload(group_name, yaml_data, body_type, content_types=content_types)
|
|
466
|
+
overload["internal"] = yaml_data.get("extensions", {}).get("x-ms-internal", False)
|
|
511
467
|
for parameter in overload["parameters"]:
|
|
512
468
|
if parameter["wireName"].lower() == "content-type":
|
|
513
|
-
parameter["clientDefaultValue"] = overload["bodyParameter"][
|
|
514
|
-
"defaultContentType"
|
|
515
|
-
]
|
|
469
|
+
parameter["clientDefaultValue"] = overload["bodyParameter"]["defaultContentType"]
|
|
516
470
|
overloads.append(overload)
|
|
517
471
|
return overloads
|
|
518
472
|
|
|
@@ -524,14 +478,9 @@ class M4Reformatter(
|
|
|
524
478
|
*,
|
|
525
479
|
is_overload: bool = False,
|
|
526
480
|
) -> Dict[str, Any]:
|
|
527
|
-
in_overriden =
|
|
528
|
-
body_parameter["type"]["type"] == "combined" if body_parameter else False
|
|
529
|
-
)
|
|
481
|
+
in_overriden = body_parameter["type"]["type"] == "combined" if body_parameter else False
|
|
530
482
|
abstract = False
|
|
531
|
-
if body_parameter and (
|
|
532
|
-
body_parameter.get("entries")
|
|
533
|
-
or len(body_parameter["type"].get("types", [])) > 2
|
|
534
|
-
):
|
|
483
|
+
if body_parameter and (body_parameter.get("entries") or len(body_parameter["type"].get("types", [])) > 2):
|
|
535
484
|
# this means it's formdata or urlencoded, or there are more than 2 types of body
|
|
536
485
|
abstract = True
|
|
537
486
|
return {
|
|
@@ -551,10 +500,7 @@ class M4Reformatter(
|
|
|
551
500
|
"exceptions": [
|
|
552
501
|
update_response(e)
|
|
553
502
|
for e in yaml_data.get("exceptions", [])
|
|
554
|
-
if not (
|
|
555
|
-
e.get("schema")
|
|
556
|
-
and e["schema"]["language"]["default"]["name"] == "CloudError"
|
|
557
|
-
)
|
|
503
|
+
if not (e.get("schema") and e["schema"]["language"]["default"]["name"] == "CloudError")
|
|
558
504
|
],
|
|
559
505
|
"groupName": group_name,
|
|
560
506
|
"discriminator": "operation",
|
|
@@ -564,12 +510,8 @@ class M4Reformatter(
|
|
|
564
510
|
"externalDocs": yaml_data.get("externalDocs"),
|
|
565
511
|
}
|
|
566
512
|
|
|
567
|
-
def get_operation_creator(
|
|
568
|
-
|
|
569
|
-
) -> Callable[[str, Dict[str, Any]], List[Dict[str, Any]]]:
|
|
570
|
-
lro_operation = yaml_data.get("extensions", {}).get(
|
|
571
|
-
"x-ms-long-running-operation"
|
|
572
|
-
)
|
|
513
|
+
def get_operation_creator(self, yaml_data: Dict[str, Any]) -> Callable[[str, Dict[str, Any]], List[Dict[str, Any]]]:
|
|
514
|
+
lro_operation = yaml_data.get("extensions", {}).get("x-ms-long-running-operation")
|
|
573
515
|
paging_operation = yaml_data.get("extensions", {}).get("x-ms-pageable")
|
|
574
516
|
if lro_operation and paging_operation:
|
|
575
517
|
return self.update_lro_paging_operation
|
|
@@ -579,72 +521,50 @@ class M4Reformatter(
|
|
|
579
521
|
return self.update_paging_operation
|
|
580
522
|
return self.update_operation
|
|
581
523
|
|
|
582
|
-
def update_operation(
|
|
583
|
-
self, group_name: str, yaml_data: Dict[str, Any]
|
|
584
|
-
) -> List[Dict[str, Any]]:
|
|
524
|
+
def update_operation(self, group_name: str, yaml_data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
585
525
|
body_parameter = (
|
|
586
|
-
self.update_body_parameter(yaml_data["requestMediaTypes"])
|
|
587
|
-
if yaml_data.get("requestMediaTypes")
|
|
588
|
-
else None
|
|
526
|
+
self.update_body_parameter(yaml_data["requestMediaTypes"]) if yaml_data.get("requestMediaTypes") else None
|
|
589
527
|
)
|
|
590
528
|
content_types = None
|
|
591
529
|
operation = self._update_operation_helper(group_name, yaml_data, body_parameter)
|
|
592
|
-
operation["internal"] = yaml_data.get("extensions", {}).get(
|
|
593
|
-
"x-ms-internal", False
|
|
594
|
-
)
|
|
530
|
+
operation["internal"] = yaml_data.get("extensions", {}).get("x-ms-internal", False)
|
|
595
531
|
operation["overloads"] = self.update_overloads(
|
|
596
532
|
group_name, yaml_data, body_parameter, content_types=content_types
|
|
597
533
|
)
|
|
598
534
|
operation["samples"] = yaml_data.get("extensions", {}).get("x-ms-examples", {})
|
|
599
535
|
return [operation]
|
|
600
536
|
|
|
601
|
-
def add_paging_information(
|
|
602
|
-
self, group_name: str, operation: Dict[str, Any], yaml_data: Dict[str, Any]
|
|
603
|
-
) -> None:
|
|
537
|
+
def add_paging_information(self, group_name: str, operation: Dict[str, Any], yaml_data: Dict[str, Any]) -> None:
|
|
604
538
|
operation["discriminator"] = "paging"
|
|
605
|
-
operation["itemName"] = yaml_data["extensions"]["x-ms-pageable"].get(
|
|
606
|
-
|
|
607
|
-
)
|
|
608
|
-
operation["continuationTokenName"] = yaml_data["extensions"][
|
|
609
|
-
"x-ms-pageable"
|
|
610
|
-
].get("nextLinkName")
|
|
539
|
+
operation["itemName"] = yaml_data["extensions"]["x-ms-pageable"].get("itemName", "value")
|
|
540
|
+
operation["continuationTokenName"] = yaml_data["extensions"]["x-ms-pageable"].get("nextLinkName")
|
|
611
541
|
returned_response_object = (
|
|
612
|
-
operation["nextOperation"]["responses"][0]
|
|
613
|
-
if operation.get("nextOperation")
|
|
614
|
-
else operation["responses"][0]
|
|
542
|
+
operation["nextOperation"]["responses"][0] if operation.get("nextOperation") else operation["responses"][0]
|
|
615
543
|
)
|
|
616
544
|
if self.version_tolerant:
|
|
617
545
|
# if we're in version tolerant, hide the paging model
|
|
618
546
|
returned_response_object["type"]["internal"] = True
|
|
619
547
|
operation["itemType"] = next(
|
|
620
|
-
p["type"]
|
|
621
|
-
for p in returned_response_object["type"]["properties"]
|
|
622
|
-
if p["wireName"] == operation["itemName"]
|
|
548
|
+
p["type"] for p in returned_response_object["type"]["properties"] if p["wireName"] == operation["itemName"]
|
|
623
549
|
)
|
|
624
550
|
if yaml_data["language"]["default"]["paging"].get("nextLinkOperation"):
|
|
625
551
|
operation["nextOperation"] = self.update_operation(
|
|
626
552
|
group_name=group_name,
|
|
627
|
-
yaml_data=yaml_data["language"]["default"]["paging"][
|
|
628
|
-
"nextLinkOperation"
|
|
629
|
-
],
|
|
553
|
+
yaml_data=yaml_data["language"]["default"]["paging"]["nextLinkOperation"],
|
|
630
554
|
)[0]
|
|
631
555
|
extensions = yaml_data["extensions"]
|
|
632
556
|
for response in operation["responses"]:
|
|
633
557
|
response["pagerSync"] = extensions.get("x-python-custom-pager-sync")
|
|
634
558
|
response["pagerAsync"] = extensions.get("x-python-custom-pager-async")
|
|
635
559
|
|
|
636
|
-
def update_paging_operation(
|
|
637
|
-
self, group_name: str, yaml_data: Dict[str, Any]
|
|
638
|
-
) -> List[Dict[str, Any]]:
|
|
560
|
+
def update_paging_operation(self, group_name: str, yaml_data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
639
561
|
retval: List[Dict[str, Any]] = []
|
|
640
562
|
for base_operation in self.update_operation(group_name, yaml_data):
|
|
641
563
|
self.add_paging_information(group_name, base_operation, yaml_data)
|
|
642
564
|
retval.append(base_operation)
|
|
643
565
|
return retval
|
|
644
566
|
|
|
645
|
-
def update_lro_paging_operation(
|
|
646
|
-
self, group_name: str, yaml_data: Dict[str, Any]
|
|
647
|
-
) -> List[Dict[str, Any]]:
|
|
567
|
+
def update_lro_paging_operation(self, group_name: str, yaml_data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
648
568
|
retval: List[Dict[str, Any]] = []
|
|
649
569
|
for operation in self.update_lro_operation(group_name, yaml_data):
|
|
650
570
|
if operation.get("discriminator") == "lro":
|
|
@@ -659,9 +579,7 @@ class M4Reformatter(
|
|
|
659
579
|
initial_operation["wantTracing"] = False
|
|
660
580
|
return initial_operation
|
|
661
581
|
|
|
662
|
-
def update_lro_operation(
|
|
663
|
-
self, group_name: str, yaml_data: Dict[str, Any]
|
|
664
|
-
) -> List[Dict[str, Any]]:
|
|
582
|
+
def update_lro_operation(self, group_name: str, yaml_data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
665
583
|
retval: List[Dict[str, Any]] = []
|
|
666
584
|
for base_operation in self.update_operation(group_name, yaml_data):
|
|
667
585
|
initial_operation = self.update_operation(group_name, yaml_data)[0]
|
|
@@ -684,9 +602,7 @@ class M4Reformatter(
|
|
|
684
602
|
body_parameter = self.update_body_parameter_overload(
|
|
685
603
|
yaml_data["requestMediaTypes"], body_type, content_types=content_types
|
|
686
604
|
)
|
|
687
|
-
return self._update_operation_helper(
|
|
688
|
-
group_name, yaml_data, body_parameter, is_overload=True
|
|
689
|
-
)
|
|
605
|
+
return self._update_operation_helper(group_name, yaml_data, body_parameter, is_overload=True)
|
|
690
606
|
|
|
691
607
|
def update_operation_group(self, yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
692
608
|
property_name = yaml_data["language"]["default"]["name"]
|
|
@@ -694,11 +610,7 @@ class M4Reformatter(
|
|
|
694
610
|
"propertyName": property_name,
|
|
695
611
|
"className": property_name,
|
|
696
612
|
"operations": filter_out_paging_next_operation(
|
|
697
|
-
[
|
|
698
|
-
o
|
|
699
|
-
for ydo in yaml_data["operations"]
|
|
700
|
-
for o in self.get_operation_creator(ydo)(property_name, ydo)
|
|
701
|
-
]
|
|
613
|
+
[o for ydo in yaml_data["operations"] for o in self.get_operation_creator(ydo)(property_name, ydo)]
|
|
702
614
|
),
|
|
703
615
|
}
|
|
704
616
|
|
|
@@ -718,28 +630,19 @@ class M4Reformatter(
|
|
|
718
630
|
body_param["contentTypes"] = content_types or [
|
|
719
631
|
ct
|
|
720
632
|
for ct, request in yaml_data.items()
|
|
721
|
-
if id(body_type)
|
|
722
|
-
== id(
|
|
723
|
-
ORIGINAL_ID_TO_UPDATED_TYPE[id(get_body_parameter(request)["schema"])]
|
|
724
|
-
)
|
|
633
|
+
if id(body_type) == id(ORIGINAL_ID_TO_UPDATED_TYPE[id(get_body_parameter(request)["schema"])])
|
|
725
634
|
]
|
|
726
635
|
# get default content type
|
|
727
|
-
body_param["defaultContentType"] = _get_default_content_type(
|
|
728
|
-
body_param["contentTypes"]
|
|
729
|
-
)
|
|
636
|
+
body_param["defaultContentType"] = _get_default_content_type(body_param["contentTypes"])
|
|
730
637
|
# python supports IO input with all kinds of content_types
|
|
731
638
|
if body_type["type"] == "binary":
|
|
732
639
|
body_param["contentTypes"] = content_types or list(yaml_data.keys())
|
|
733
640
|
if body_param["type"]["type"] == "constant":
|
|
734
|
-
if not body_param["optional"] or (
|
|
735
|
-
body_param["optional"] and not self.default_optional_constants_to_none
|
|
736
|
-
):
|
|
641
|
+
if not body_param["optional"] or (body_param["optional"] and not self.default_optional_constants_to_none):
|
|
737
642
|
body_param["clientDefaultValue"] = body_type["value"]
|
|
738
643
|
body_param["flattened"] = flattened
|
|
739
644
|
body_param["isPartialBody"] = is_partial_body
|
|
740
|
-
body_param["wireName"] = body_param["wireName"] or to_lower_camel_case(
|
|
741
|
-
body_param["clientName"]
|
|
742
|
-
)
|
|
645
|
+
body_param["wireName"] = body_param["wireName"] or to_lower_camel_case(body_param["clientName"])
|
|
743
646
|
return body_param
|
|
744
647
|
|
|
745
648
|
def update_multipart_body_parameter(
|
|
@@ -767,21 +670,15 @@ class M4Reformatter(
|
|
|
767
670
|
def update_body_parameter(self, yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
768
671
|
protocol_http = list(yaml_data.values())[0].get("protocol", {}).get("http", {})
|
|
769
672
|
if protocol_http.get("multipart"):
|
|
770
|
-
return self.update_multipart_body_parameter(
|
|
771
|
-
yaml_data, "files", "Multipart input for files."
|
|
772
|
-
)
|
|
673
|
+
return self.update_multipart_body_parameter(yaml_data, "files", "Multipart input for files.")
|
|
773
674
|
if protocol_http.get("knownMediaType") == "form":
|
|
774
|
-
return self.update_multipart_body_parameter(
|
|
775
|
-
yaml_data, "data", "Multipart input for form encoded data."
|
|
776
|
-
)
|
|
675
|
+
return self.update_multipart_body_parameter(yaml_data, "data", "Multipart input for form encoded data.")
|
|
777
676
|
body_types = get_all_body_types(yaml_data)
|
|
778
677
|
if len(body_types) > 1 and not yaml_data.get("flattened"):
|
|
779
678
|
body_type = update_types(body_types)
|
|
780
679
|
else:
|
|
781
680
|
body_type = body_types[0]
|
|
782
|
-
body_param = next(
|
|
783
|
-
p for sr in yaml_data.values() for p in sr["parameters"] if is_body(p)
|
|
784
|
-
)
|
|
681
|
+
body_param = next(p for sr in yaml_data.values() for p in sr["parameters"] if is_body(p))
|
|
785
682
|
return self._update_body_parameter_helper(yaml_data, body_param, body_type)
|
|
786
683
|
|
|
787
684
|
def update_body_parameter_overload(
|
|
@@ -792,12 +689,8 @@ class M4Reformatter(
|
|
|
792
689
|
content_types: Optional[List[str]] = None,
|
|
793
690
|
) -> Dict[str, Any]:
|
|
794
691
|
"""For overloads we already know what body_type we want to go with"""
|
|
795
|
-
body_param = next(
|
|
796
|
-
|
|
797
|
-
)
|
|
798
|
-
return self._update_body_parameter_helper(
|
|
799
|
-
yaml_data, body_param, body_type, content_types=content_types
|
|
800
|
-
)
|
|
692
|
+
body_param = next(p for sr in yaml_data.values() for p in sr["parameters"] if is_body(p))
|
|
693
|
+
return self._update_body_parameter_helper(yaml_data, body_param, body_type, content_types=content_types)
|
|
801
694
|
|
|
802
695
|
def update_flattened_parameter(
|
|
803
696
|
self, yaml_data: Dict[str, Any], body_parameter: Optional[Dict[str, Any]]
|
|
@@ -805,13 +698,9 @@ class M4Reformatter(
|
|
|
805
698
|
if not body_parameter:
|
|
806
699
|
raise ValueError("Has to have a body parameter if it's flattened")
|
|
807
700
|
# this means i'm a property that is part of a flattened model
|
|
808
|
-
target_property_name = yaml_data["targetProperty"]["language"]["default"][
|
|
809
|
-
"name"
|
|
810
|
-
]
|
|
701
|
+
target_property_name = yaml_data["targetProperty"]["language"]["default"]["name"]
|
|
811
702
|
param = self.update_parameter(yaml_data)
|
|
812
|
-
body_parameter.setdefault("propertyToParameterName", {})[
|
|
813
|
-
target_property_name
|
|
814
|
-
] = param["clientName"]
|
|
703
|
+
body_parameter.setdefault("propertyToParameterName", {})[target_property_name] = param["clientName"]
|
|
815
704
|
param["inFlattenedBody"] = True
|
|
816
705
|
return param
|
|
817
706
|
|
|
@@ -829,11 +718,7 @@ class M4Reformatter(
|
|
|
829
718
|
return yaml_data
|
|
830
719
|
param = copy.deepcopy(yaml_data)
|
|
831
720
|
param["schema"] = KNOWN_TYPES["string"] # override to string type
|
|
832
|
-
if
|
|
833
|
-
body_parameter["type"]["type"] == "binary"
|
|
834
|
-
and not body_parameter["defaultContentType"]
|
|
835
|
-
and not self.legacy
|
|
836
|
-
):
|
|
721
|
+
if body_parameter["type"]["type"] == "binary" and not body_parameter["defaultContentType"] and not self.legacy:
|
|
837
722
|
param["required"] = True
|
|
838
723
|
else:
|
|
839
724
|
param["required"] = False
|
|
@@ -843,13 +728,8 @@ class M4Reformatter(
|
|
|
843
728
|
if not (in_overriden or in_overload):
|
|
844
729
|
param["inDocstring"] = False
|
|
845
730
|
elif in_overload:
|
|
846
|
-
description += (
|
|
847
|
-
|
|
848
|
-
f"{get_body_type_for_description(body_parameter)} body."
|
|
849
|
-
)
|
|
850
|
-
if not in_overload or (
|
|
851
|
-
body_parameter["type"]["type"] == "binary" and len(request_media_types) > 1
|
|
852
|
-
):
|
|
731
|
+
description += " Content type parameter for " f"{get_body_type_for_description(body_parameter)} body."
|
|
732
|
+
if not in_overload or (body_parameter["type"]["type"] == "binary" and len(request_media_types) > 1):
|
|
853
733
|
content_types = "'" + "', '".join(request_media_types) + "'"
|
|
854
734
|
description += f" Known values are: {content_types}."
|
|
855
735
|
if not in_overload and not in_overriden:
|
|
@@ -872,9 +752,7 @@ class M4Reformatter(
|
|
|
872
752
|
has_flattened_body = body_parameter and body_parameter.get("flattened")
|
|
873
753
|
for param in parameters:
|
|
874
754
|
client_name = param["language"]["default"]["name"]
|
|
875
|
-
if param["language"]["default"]["name"] == "$host" or (
|
|
876
|
-
client_name in seen_client_names
|
|
877
|
-
):
|
|
755
|
+
if param["language"]["default"]["name"] == "$host" or (client_name in seen_client_names):
|
|
878
756
|
continue
|
|
879
757
|
seen_client_names.add(client_name)
|
|
880
758
|
if has_flattened_body and param.get("targetProperty"):
|
|
@@ -889,10 +767,7 @@ class M4Reformatter(
|
|
|
889
767
|
continue
|
|
890
768
|
if is_body(param):
|
|
891
769
|
continue
|
|
892
|
-
if (
|
|
893
|
-
param["language"]["default"].get("serializedName").lower()
|
|
894
|
-
== "content-type"
|
|
895
|
-
):
|
|
770
|
+
if param["language"]["default"].get("serializedName").lower() == "content-type":
|
|
896
771
|
param = self._update_content_type_parameter(
|
|
897
772
|
param,
|
|
898
773
|
body_parameter,
|
|
@@ -900,9 +775,7 @@ class M4Reformatter(
|
|
|
900
775
|
in_overload=in_overload,
|
|
901
776
|
in_overriden=in_overriden,
|
|
902
777
|
)
|
|
903
|
-
updated_param = self.update_parameter(
|
|
904
|
-
param, in_overload=in_overload, in_overriden=in_overriden
|
|
905
|
-
)
|
|
778
|
+
updated_param = self.update_parameter(param, in_overload=in_overload, in_overriden=in_overriden)
|
|
906
779
|
retval.append(updated_param)
|
|
907
780
|
return retval
|
|
908
781
|
|
|
@@ -955,8 +828,7 @@ class M4Reformatter(
|
|
|
955
828
|
next(
|
|
956
829
|
prop
|
|
957
830
|
for prop in grouper["type"]["properties"]
|
|
958
|
-
if p["clientName"].lstrip("_")
|
|
959
|
-
in prop["groupedParameterNames"] # TODO: patching m4
|
|
831
|
+
if p["clientName"].lstrip("_") in prop["groupedParameterNames"] # TODO: patching m4
|
|
960
832
|
)["clientName"]: p["clientName"]
|
|
961
833
|
for p in all_params
|
|
962
834
|
if p.get("groupedBy") == grouper_name
|
|
@@ -971,14 +843,10 @@ class M4Reformatter(
|
|
|
971
843
|
in_overload: bool = False,
|
|
972
844
|
in_overriden: bool = False,
|
|
973
845
|
) -> Dict[str, Any]:
|
|
974
|
-
param_base = self.update_parameter_base(
|
|
975
|
-
yaml_data, override_client_name=override_client_name
|
|
976
|
-
)
|
|
846
|
+
param_base = self.update_parameter_base(yaml_data, override_client_name=override_client_name)
|
|
977
847
|
type = get_type(yaml_data["schema"])
|
|
978
848
|
if type["type"] == "constant":
|
|
979
|
-
if not param_base["optional"] or (
|
|
980
|
-
param_base["optional"] and not self.default_optional_constants_to_none
|
|
981
|
-
):
|
|
849
|
+
if not param_base["optional"] or (param_base["optional"] and not self.default_optional_constants_to_none):
|
|
982
850
|
param_base["clientDefaultValue"] = type["value"]
|
|
983
851
|
protocol_http = yaml_data["protocol"].get("http", {})
|
|
984
852
|
param_base.update(
|
|
@@ -987,9 +855,7 @@ class M4Reformatter(
|
|
|
987
855
|
"implementation": yaml_data["implementation"],
|
|
988
856
|
"explode": protocol_http.get("explode", False),
|
|
989
857
|
"inOverload": in_overload,
|
|
990
|
-
"skipUrlEncoding": yaml_data.get("extensions", {}).get(
|
|
991
|
-
"x-ms-skip-url-encoding", False
|
|
992
|
-
),
|
|
858
|
+
"skipUrlEncoding": yaml_data.get("extensions", {}).get("x-ms-skip-url-encoding", False),
|
|
993
859
|
"inDocstring": yaml_data.get("inDocstring", True),
|
|
994
860
|
"inOverriden": in_overriden,
|
|
995
861
|
"delimiter": update_parameter_delimiter(protocol_http.get("style")),
|
|
@@ -997,9 +863,7 @@ class M4Reformatter(
|
|
|
997
863
|
)
|
|
998
864
|
return param_base
|
|
999
865
|
|
|
1000
|
-
def update_global_parameters(
|
|
1001
|
-
self, yaml_data: List[Dict[str, Any]]
|
|
1002
|
-
) -> List[Dict[str, Any]]:
|
|
866
|
+
def update_global_parameters(self, yaml_data: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
1003
867
|
global_params: List[Dict[str, Any]] = []
|
|
1004
868
|
for global_parameter in yaml_data:
|
|
1005
869
|
client_name: Optional[str] = None
|
|
@@ -1009,13 +873,9 @@ class M4Reformatter(
|
|
|
1009
873
|
|
|
1010
874
|
client_name = "endpoint" if self.version_tolerant else "base_url"
|
|
1011
875
|
global_parameter["language"]["default"]["description"] = "Service URL."
|
|
1012
|
-
elif (
|
|
1013
|
-
global_parameter.get("origin") == "modelerfour:synthesized/api-version"
|
|
1014
|
-
):
|
|
876
|
+
elif global_parameter.get("origin") == "modelerfour:synthesized/api-version":
|
|
1015
877
|
self.check_client_input = True
|
|
1016
|
-
param = self.update_parameter(
|
|
1017
|
-
global_parameter, override_client_name=client_name
|
|
1018
|
-
)
|
|
878
|
+
param = self.update_parameter(global_parameter, override_client_name=client_name)
|
|
1019
879
|
if global_parameter.get("origin") == "modelerfour:synthesized/api-version":
|
|
1020
880
|
param["implementation"] = "Client"
|
|
1021
881
|
param["checkClientInput"] = False
|
|
@@ -1033,9 +893,7 @@ class M4Reformatter(
|
|
|
1033
893
|
update_type(retval)
|
|
1034
894
|
return retval
|
|
1035
895
|
|
|
1036
|
-
def update_credential_from_security(
|
|
1037
|
-
self, yaml_data: Dict[str, Any]
|
|
1038
|
-
) -> Dict[str, Any]:
|
|
896
|
+
def update_credential_from_security(self, yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
1039
897
|
retval: Dict[str, Any] = {}
|
|
1040
898
|
for scheme in yaml_data.get("schemes", []):
|
|
1041
899
|
if scheme["type"] == OAUTH_TYPE:
|
|
@@ -1049,13 +907,8 @@ class M4Reformatter(
|
|
|
1049
907
|
if self.azure_arm:
|
|
1050
908
|
return ["https://management.azure.com/.default"]
|
|
1051
909
|
credential_scopes_temp = self._autorestapi.get_value("credential-scopes")
|
|
1052
|
-
credential_scopes = (
|
|
1053
|
-
|
|
1054
|
-
)
|
|
1055
|
-
if (
|
|
1056
|
-
self._autorestapi.get_boolean_value("credential-scopes", False)
|
|
1057
|
-
and not credential_scopes
|
|
1058
|
-
):
|
|
910
|
+
credential_scopes = credential_scopes_temp.split(",") if credential_scopes_temp else None
|
|
911
|
+
if self._autorestapi.get_boolean_value("credential-scopes", False) and not credential_scopes:
|
|
1059
912
|
raise ValueError(
|
|
1060
913
|
"--credential-scopes takes a list of scopes in comma separated format. "
|
|
1061
914
|
"For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
|
|
@@ -1073,10 +926,7 @@ class M4Reformatter(
|
|
|
1073
926
|
|
|
1074
927
|
def update_credential_from_flags(self) -> Dict[str, Any]:
|
|
1075
928
|
default_auth_policy = "BearerTokenCredentialPolicy"
|
|
1076
|
-
auth_policy = (
|
|
1077
|
-
self._autorestapi.get_value("credential-default-policy-type")
|
|
1078
|
-
or default_auth_policy
|
|
1079
|
-
)
|
|
929
|
+
auth_policy = self._autorestapi.get_value("credential-default-policy-type") or default_auth_policy
|
|
1080
930
|
credential_scopes = self.get_credential_scopes_from_flags(auth_policy)
|
|
1081
931
|
key = self._autorestapi.get_value("credential-key-header-name")
|
|
1082
932
|
if auth_policy.lower() in (
|
|
@@ -1101,14 +951,10 @@ class M4Reformatter(
|
|
|
1101
951
|
)
|
|
1102
952
|
if not key:
|
|
1103
953
|
key = "api-key"
|
|
1104
|
-
_LOGGER.info(
|
|
1105
|
-
"Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'"
|
|
1106
|
-
)
|
|
954
|
+
_LOGGER.info("Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'")
|
|
1107
955
|
return get_azure_key_credential(key)
|
|
1108
956
|
|
|
1109
|
-
def update_credential(
|
|
1110
|
-
self, yaml_data: Dict[str, Any], parameters: List[Dict[str, Any]]
|
|
1111
|
-
) -> None:
|
|
957
|
+
def update_credential(self, yaml_data: Dict[str, Any], parameters: List[Dict[str, Any]]) -> None:
|
|
1112
958
|
# then override with credential flags
|
|
1113
959
|
credential_flag = (
|
|
1114
960
|
self._autorestapi.get_boolean_value("add-credentials", False)
|
|
@@ -1135,19 +981,13 @@ class M4Reformatter(
|
|
|
1135
981
|
parameters.append(credential)
|
|
1136
982
|
|
|
1137
983
|
def update_client(self, yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
1138
|
-
parameters = self.update_global_parameters(
|
|
1139
|
-
yaml_data.get("globalParameters", [])
|
|
1140
|
-
)
|
|
984
|
+
parameters = self.update_global_parameters(yaml_data.get("globalParameters", []))
|
|
1141
985
|
self.update_credential(yaml_data.get("security", {}), parameters)
|
|
1142
986
|
return {
|
|
1143
987
|
"name": yaml_data["language"]["default"]["name"],
|
|
1144
988
|
"description": yaml_data["info"].get("description"),
|
|
1145
989
|
"parameters": parameters,
|
|
1146
|
-
"url": (
|
|
1147
|
-
update_client_url(yaml_data)
|
|
1148
|
-
if yaml_data.get("globalParameters")
|
|
1149
|
-
else ""
|
|
1150
|
-
),
|
|
990
|
+
"url": (update_client_url(yaml_data) if yaml_data.get("globalParameters") else ""),
|
|
1151
991
|
}
|
|
1152
992
|
|
|
1153
993
|
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
@@ -1159,10 +999,7 @@ class M4Reformatter(
|
|
|
1159
999
|
# First we update the types, so we can access for when we're creating parameters etc.
|
|
1160
1000
|
for type_group, types in yaml_data["schemas"].items():
|
|
1161
1001
|
for t in types:
|
|
1162
|
-
if
|
|
1163
|
-
type_group == "objects"
|
|
1164
|
-
and t["language"]["default"]["name"] == "CloudError"
|
|
1165
|
-
):
|
|
1002
|
+
if type_group == "objects" and t["language"]["default"]["name"] == "CloudError":
|
|
1166
1003
|
# we don't generate cloud error
|
|
1167
1004
|
continue
|
|
1168
1005
|
update_type(t)
|
|
@@ -1172,9 +1009,7 @@ class M4Reformatter(
|
|
|
1172
1009
|
yaml_data["clients"][0]["operationGroups"] = [
|
|
1173
1010
|
self.update_operation_group(og) for og in yaml_data["operationGroups"]
|
|
1174
1011
|
]
|
|
1175
|
-
yaml_data["types"] = list(ORIGINAL_ID_TO_UPDATED_TYPE.values()) + list(
|
|
1176
|
-
KNOWN_TYPES.values()
|
|
1177
|
-
)
|
|
1012
|
+
yaml_data["types"] = list(ORIGINAL_ID_TO_UPDATED_TYPE.values()) + list(KNOWN_TYPES.values())
|
|
1178
1013
|
if yaml_data.get("globalParameters"):
|
|
1179
1014
|
del yaml_data["globalParameters"]
|
|
1180
1015
|
del yaml_data["info"]
|