@autorest/python 6.2.0 → 6.2.2

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.
Files changed (73) hide show
  1. package/autorest/codegen/__init__.py +9 -74
  2. package/autorest/codegen/models/__init__.py +11 -12
  3. package/autorest/codegen/models/{base_type.py → base.py} +29 -10
  4. package/autorest/codegen/models/base_builder.py +8 -10
  5. package/autorest/codegen/models/client.py +111 -40
  6. package/autorest/codegen/models/code_model.py +131 -90
  7. package/autorest/codegen/models/combined_type.py +7 -7
  8. package/autorest/codegen/models/constant_type.py +44 -10
  9. package/autorest/codegen/models/credential_types.py +17 -19
  10. package/autorest/codegen/models/dictionary_type.py +7 -9
  11. package/autorest/codegen/models/enum_type.py +19 -24
  12. package/autorest/codegen/models/imports.py +82 -33
  13. package/autorest/codegen/models/list_type.py +11 -15
  14. package/autorest/codegen/models/lro_operation.py +6 -10
  15. package/autorest/codegen/models/model_type.py +20 -21
  16. package/autorest/codegen/models/operation.py +49 -42
  17. package/autorest/codegen/models/operation_group.py +11 -11
  18. package/autorest/codegen/models/paging_operation.py +9 -11
  19. package/autorest/codegen/models/parameter.py +48 -32
  20. package/autorest/codegen/models/parameter_list.py +16 -22
  21. package/autorest/codegen/models/primitive_types.py +12 -23
  22. package/autorest/codegen/models/property.py +11 -11
  23. package/autorest/codegen/models/request_builder.py +19 -19
  24. package/autorest/codegen/models/request_builder_parameter.py +14 -16
  25. package/autorest/codegen/models/response.py +24 -28
  26. package/autorest/codegen/serializers/__init__.py +202 -187
  27. package/autorest/codegen/serializers/builder_serializer.py +49 -50
  28. package/autorest/codegen/serializers/client_serializer.py +9 -7
  29. package/autorest/codegen/serializers/enum_serializer.py +4 -4
  30. package/autorest/codegen/serializers/general_serializer.py +26 -36
  31. package/autorest/codegen/serializers/import_serializer.py +30 -36
  32. package/autorest/codegen/serializers/metadata_serializer.py +35 -17
  33. package/autorest/codegen/serializers/model_init_serializer.py +6 -10
  34. package/autorest/codegen/serializers/model_serializer.py +42 -27
  35. package/autorest/codegen/serializers/operation_groups_serializer.py +12 -8
  36. package/autorest/codegen/serializers/operations_init_serializer.py +13 -6
  37. package/autorest/codegen/serializers/patch_serializer.py +4 -4
  38. package/autorest/codegen/serializers/request_builders_serializer.py +6 -6
  39. package/autorest/codegen/serializers/sample_serializer.py +10 -12
  40. package/autorest/codegen/templates/client_container.py.jinja2 +2 -2
  41. package/autorest/codegen/templates/config.py.jinja2 +1 -1
  42. package/autorest/codegen/templates/config_container.py.jinja2 +3 -3
  43. package/autorest/codegen/templates/enum_container.py.jinja2 +2 -2
  44. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  45. package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
  46. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
  47. package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
  48. package/autorest/codegen/templates/model_container.py.jinja2 +3 -3
  49. package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
  50. package/autorest/codegen/templates/model_init.py.jinja2 +3 -3
  51. package/autorest/codegen/templates/operation.py.jinja2 +1 -1
  52. package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
  53. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +3 -3
  54. package/autorest/codegen/templates/operation_tools.jinja2 +3 -3
  55. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
  56. package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +4 -1
  57. package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
  58. package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
  59. package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
  60. package/autorest/codegen/templates/rest_init.py.jinja2 +1 -1
  61. package/autorest/codegen/templates/sample.py.jinja2 +5 -5
  62. package/autorest/codegen/templates/validation.py.jinja2 +1 -1
  63. package/autorest/codegen/templates/vendor.py.jinja2 +6 -6
  64. package/autorest/codegen/templates/version.py.jinja2 +2 -2
  65. package/autorest/m4reformatter/__init__.py +57 -47
  66. package/autorest/multiapi/models/imports.py +89 -18
  67. package/autorest/multiapi/serializers/import_serializer.py +88 -7
  68. package/autorest/multiapi/utils.py +6 -0
  69. package/autorest/preprocess/__init__.py +23 -26
  70. package/package.json +1 -1
  71. package/run_cadl.py +0 -1
  72. package/autorest/cadlflags/__init__.py +0 -130
  73. package/autorest/codegen/models/base_model.py +0 -30
@@ -39,7 +39,7 @@ class {{ client.name }}Configuration(Configuration): # pylint: disable=too-many
39
39
  self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
40
40
  self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
41
41
  self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
42
- self.http_logging_policy = kwargs.get('http_logging_policy') or {{ "ARM" if client.namespace_model.options['azure_arm'] else "policies." }}HttpLoggingPolicy(**kwargs)
42
+ self.http_logging_policy = kwargs.get('http_logging_policy') or {{ "ARM" if client.code_model.options['azure_arm'] else "policies." }}HttpLoggingPolicy(**kwargs)
43
43
  self.retry_policy = kwargs.get('retry_policy') or policies.{{ keywords.async_class }}RetryPolicy(**kwargs)
44
44
  self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
45
45
  self.redirect_policy = kwargs.get('redirect_policy') or policies.{{ keywords.async_class }}RedirectPolicy(**kwargs)
@@ -2,15 +2,15 @@
2
2
  {% import 'operation_tools.jinja2' as op_tools %}
3
3
  {# actual template starts here #}
4
4
  # coding=utf-8
5
- {{ namespace_model.options['license_header'] }}
5
+ {{ code_model.options['license_header'] }}
6
6
 
7
7
  {{ imports }}
8
8
 
9
- {% if not namespace_model.options['package_version'] %}
9
+ {% if not code_model.options['package_version'] %}
10
10
  VERSION = "unknown"
11
11
  {% endif %}
12
12
 
13
- {% for client in namespace_model.clients %}
13
+ {% for client in clients %}
14
14
  {% set serializer = get_serializer(client) %}
15
15
  {% include "config.py.jinja2" %}
16
16
  {% endfor %}
@@ -1,9 +1,9 @@
1
1
  # coding=utf-8
2
- {{ namespace_model.options['license_header'] }}
2
+ {{ code_model.options['license_header'] }}
3
3
 
4
4
  from enum import Enum
5
5
  from azure.core import CaseInsensitiveEnumMeta
6
6
 
7
- {% for enum in namespace_model.enums | sort %}
7
+ {% for enum in code_model.enums | sort %}
8
8
  {% include "enum.py.jinja2" %}
9
9
  {% endfor %}
@@ -1,13 +1,13 @@
1
1
  {% import 'keywords.jinja2' as keywords %}
2
2
  # coding=utf-8
3
- {{ namespace_model.options['license_header'] }}
3
+ {{ code_model.options['license_header'] }}
4
4
 
5
5
  {% if clients %}
6
6
  {% for client in clients %}
7
7
  from .{{ client.filename }} import {{ client.name }}
8
8
  {% endfor %}
9
9
  {% endif %}
10
- {% if not async_mode and namespace_model.options['package_version']%}
10
+ {% if not async_mode and code_model.options['package_version']%}
11
11
  from ._version import VERSION
12
12
 
13
13
  __version__ = VERSION
@@ -14,6 +14,6 @@
14
14
 
15
15
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
16
16
  {% endif %}
17
- {% if not namespace_model.options["version_tolerant"] %}
17
+ {% if not code_model.options["version_tolerant"] %}
18
18
  {{ operation_serializer.get_metadata_url(operation) -}}
19
19
  {% endif %}
@@ -16,6 +16,6 @@
16
16
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
17
17
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
18
18
  {% endif %}
19
- {% if not namespace_model.options["version_tolerant"] %}
19
+ {% if not code_model.options["version_tolerant"] %}
20
20
  {{ operation_serializer.get_metadata_url(operation) }}
21
21
  {% endif %}
@@ -9,9 +9,9 @@
9
9
  "description": {{ client.description | tojson }},
10
10
  "host_value": {{ (client.parameters.host.client_default_value_declaration if not client.has_parameterized_host else None) | tojson }},
11
11
  "parameterized_host_template": {{ (keywords.escape_str(client.url) if client.has_parameterized_host else None) | tojson }},
12
- "azure_arm": {{ client.namespace_model.options["azure_arm"] | tojson }},
12
+ "azure_arm": {{ client.code_model.options["azure_arm"] | tojson }},
13
13
  "has_lro_operations": {{ client.has_lro_operations | tojson }},
14
- "client_side_validation": {{ client.namespace_model.options["client_side_validation"] | tojson }},
14
+ "client_side_validation": {{ client.code_model.options["client_side_validation"] | tojson }},
15
15
  "sync_imports": {{ sync_client_imports | tojson }},
16
16
  "async_imports": {{ async_client_imports | tojson }}
17
17
  },
@@ -1,10 +1,10 @@
1
1
  # coding=utf-8
2
2
  # pylint: disable=too-many-lines
3
- {{ namespace_model.options['license_header'] }}
3
+ {{ code_model.options['license_header'] }}
4
4
 
5
5
  {{ imports }}
6
- {% for model in namespace_model.model_types %}
7
- {% if namespace_model.options["models_mode"] == "dpg" %}
6
+ {% for model in code_model.model_types %}
7
+ {% if code_model.options["models_mode"] == "dpg" %}
8
8
  {% include "model_dpg.py.jinja2" %}
9
9
  {% else %}
10
10
  {% include "model_msrest.py.jinja2" %}
@@ -30,7 +30,7 @@
30
30
  {% if model.is_polymorphic %}
31
31
  __mapping__ = {}
32
32
  {% endif %}
33
- {% for p in serializer.get_properties_to_initialize(model)%}
33
+ {% for p in serializer.get_properties_to_declare(model)%}
34
34
  {% for line in serializer.declare_property(p) %}
35
35
  {{ line }}
36
36
  {% endfor %}
@@ -57,6 +57,6 @@
57
57
  {% endif %}
58
58
  def __init__(self, *args, **kwargs):
59
59
  super().__init__(*args, **kwargs)
60
- {% if model.discriminator_value %}
61
- {{ serializer.initialize_discriminator_property(model, model.discriminator_property) }}
62
- {% endif %}
60
+ {% for initialize_property in serializer.initialize_properties(model) %}
61
+ {{ initialize_property }}
62
+ {% endfor %}
@@ -1,16 +1,16 @@
1
1
  {% import 'keywords.jinja2' as keywords %}
2
2
  # coding=utf-8
3
- {{ namespace_model.options['license_header'] }}
3
+ {{ code_model.options['license_header'] }}
4
4
  {% if schemas %}
5
5
 
6
6
  {% for schema in schemas %}
7
- from .{{ namespace_model.models_filename }} import {{ schema }}
7
+ from .{{ code_model.models_filename }} import {{ schema }}
8
8
  {% endfor %}
9
9
  {% endif %}
10
10
  {% if enums %}
11
11
 
12
12
  {% for enum in enums %}
13
- from .{{ namespace_model.enums_filename }} import {{ enum }}
13
+ from .{{ code_model.enums_filename }} import {{ enum }}
14
14
  {% endfor %}
15
15
  {% endif %}
16
16
  {{ keywords.patch_imports() }}
@@ -19,6 +19,6 @@
19
19
  {{ op_tools.serialize(operation_serializer.make_pipeline_call(operation)) | indent }}
20
20
  {{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
21
21
  {% endif %}
22
- {% if not namespace_model.options["version_tolerant"] %}
22
+ {% if not code_model.options["version_tolerant"] %}
23
23
  {{ operation_serializer.get_metadata_url(operation) }}
24
24
  {% endif %}
@@ -16,11 +16,11 @@ class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
16
16
  **DO NOT** instantiate this class directly.
17
17
 
18
18
  Instead, you should access the following operations through
19
- :class:`{{ "~" + namespace_model.namespace + (".aio." if async_mode else ".") + operation_group.client.name }}`'s
19
+ :class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + operation_group.client.name }}`'s
20
20
  :attr:`{{ operation_group.property_name }}` attribute.
21
21
  """
22
22
 
23
- {% if namespace_model.public_model_types and namespace_model.options["models_mode"] == "msrest" %}
23
+ {% if code_model.public_model_types and code_model.options["models_mode"] == "msrest" %}
24
24
  models = _models
25
25
 
26
26
  {% endif %}
@@ -3,11 +3,11 @@
3
3
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
4
4
  # pylint: disable=too-many-lines
5
5
  # coding=utf-8
6
- {{ namespace_model.options['license_header'] }}
6
+ {{ code_model.options['license_header'] }}
7
7
  {{ imports }}
8
8
 
9
- {% if namespace_model.options["builders_visibility"] == "embedded" and not async_mode %}
10
- {{ op_tools.declare_serializer(namespace_model) }}
9
+ {% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
10
+ {{ op_tools.declare_serializer(code_model) }}
11
11
  {% for operation_group in operation_groups %}
12
12
  {% for request_builder in get_request_builders(operation_group) %}
13
13
 
@@ -50,10 +50,10 @@ Example:
50
50
  {% endif %}
51
51
  {% endfor %}{% endmacro %}
52
52
 
53
- {% macro declare_serializer(namespace_model) %}
54
- {% if namespace_model.request_builders | rejectattr("abstract") | first %}
53
+ {% macro declare_serializer(code_model) %}
54
+ {% if code_model.has_non_abstract_operations %}
55
55
  _SERIALIZER = Serializer()
56
- {% if not namespace_model.options["client_side_validation"] %}
56
+ {% if not code_model.options["client_side_validation"] %}
57
57
  _SERIALIZER.client_side_validation = False
58
58
  {% endif %}
59
59
  {% endif %}
@@ -2,16 +2,16 @@
2
2
  {% import 'keywords.jinja2' as keywords %}
3
3
  {# actual template starts here #}
4
4
  # coding=utf-8
5
- {{ namespace_model.options['license_header'] }}
5
+ {{ code_model.options['license_header'] }}
6
6
 
7
7
  {{ op_tools.serialize(operation_group_imports()) }}
8
8
  {{ keywords.patch_imports() }}
9
- {% if namespace_model.operation_groups %}
10
9
  __all__ = [
11
- {% for operation_group in namespace_model.operation_groups %}
10
+ {% for client in clients %}
11
+ {% for operation_group in client.operation_groups %}
12
12
  '{{ operation_group.class_name }}',
13
+ {% endfor %}
13
14
  {% endfor %}
14
15
  ]
15
- {% endif %}
16
16
  {{ keywords.extend_all }}
17
17
  _patch_sdk()
@@ -7,7 +7,7 @@ import re
7
7
  {% endif -%}
8
8
  from setuptools import setup, find_packages
9
9
 
10
- {% set package_name = package_name or code_model.namespace_models[0].clients[0].name %}
10
+ {% set package_name = package_name or code_model.clients[0].name %}
11
11
 
12
12
  PACKAGE_NAME = "{{ package_name|lower }}"
13
13
  {% if package_mode -%}
@@ -91,6 +91,9 @@ setup(
91
91
  {% else %}
92
92
  "azure-core<2.0.0,>=1.24.0",
93
93
  {% endif %}
94
+ {% if code_model.need_typing_extensions %}
95
+ "typing_extensions>=4.3.0; python_version<'3.8.0'",
96
+ {% endif %}
94
97
  ],
95
98
  {% if package_mode %}
96
99
  python_requires=">=3.7",
@@ -19,6 +19,6 @@
19
19
  get_next, extract_data
20
20
  )
21
21
  {% endif %}
22
- {% if not namespace_model.options["version_tolerant"] %}
22
+ {% if not code_model.options["version_tolerant"] %}
23
23
  {{ operation_serializer.get_metadata_url(operation) -}}
24
24
  {% endif %}
@@ -1,7 +1,7 @@
1
1
  {% import 'keywords.jinja2' as keywords with context %}
2
2
  {% import 'operation_tools.jinja2' as op_tools with context %}
3
3
  {{ request_builder_serializer.method_signature_and_response_type_annotation(request_builder) }}
4
- {% if namespace_model.options["builders_visibility"] == "public" %}
4
+ {% if code_model.options["builders_visibility"] == "public" %}
5
5
  {{ op_tools.description(request_builder, request_builder_serializer) | indent }}
6
6
  {% endif %}
7
7
  {% if not request_builder.is_overload %}
@@ -1,9 +1,9 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  # coding=utf-8
3
- {{ namespace_model.options['license_header'] }}
3
+ {{ code_model.options['license_header'] }}
4
4
  {{ imports }}
5
5
 
6
- {{ op_tools.declare_serializer(namespace_model) }}
6
+ {{ op_tools.declare_serializer(code_model) }}
7
7
  {% for request_builder in request_builders %}
8
8
 
9
9
  {% include "request_builder.py.jinja2" %}
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- {{ client.namespace_model.options['license_header'] }}
2
+ {{ code_model.options['license_header'] }}
3
3
 
4
4
  {% for request_builder in request_builders %}
5
5
  from ._request_builders import {{ request_builder.name }}
@@ -1,7 +1,7 @@
1
1
  # coding=utf-8
2
2
  {% set aad_token = "DefaultAzureCredential" %}
3
3
  {% set azure_key = "AzureKeyCredential" %}
4
- {{ namespace_model.options['license_header'] }}
4
+ {{ code_model.options['license_header'] }}
5
5
 
6
6
  {{ imports }}
7
7
  """
@@ -9,23 +9,23 @@
9
9
  {% if "credential" in client_params and aad_token in client_params["credential"] %}
10
10
  pip install azure-identity
11
11
  {% endif %}
12
- pip install {{ (namespace_model.options["package_name"] or namespace_model.clients[0].name)|lower }}
12
+ pip install {{ (code_model.options["package_name"] or code_model.clients[0].name)|lower }}
13
13
  # USAGE
14
14
  python {{ file_name }}
15
15
  {% if "credential" in client_params and aad_token in client_params["credential"] %}
16
16
 
17
- Before run the sample, please set the values of the client ID, tenant ID and client secret
17
+ Before run the sample, please set the values of the client ID, tenant ID and client secret
18
18
  of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
19
19
  AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
20
20
  https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
21
21
  {% elif "credential" in client_params and azure_key in client_params["credential"] %}
22
-
22
+
23
23
  Before run the sample, please set environment variables AZURE_KEY with real value
24
24
  which can access your service
25
25
  {% endif %}
26
26
  """
27
27
  def main():
28
- client = {{ namespace_model.clients[0].name }}(
28
+ client = {{ code_model.clients[0].name }}(
29
29
  {% for key,value in client_params.items() %}
30
30
  {{ key }}={{ value }},
31
31
  {% endfor %}
@@ -1,4 +1,4 @@
1
- {{ namespace_model.options['license_header'] }}
1
+ {{ code_model.options['license_header'] }}
2
2
  import functools
3
3
 
4
4
  def api_version_validation(**kwargs):
@@ -1,9 +1,9 @@
1
1
  {% import 'keywords.jinja2' as keywords with context %}
2
- {{ namespace_model.options['license_header'] }}
2
+ {{ code_model.options['license_header'] }}
3
3
 
4
4
  {{ imports }}
5
5
 
6
- {% if namespace_model.need_request_converter and not async_mode %}
6
+ {% if code_model.need_request_converter and not async_mode %}
7
7
  def _convert_request(request, files=None):
8
8
  data = request.content if not files else None
9
9
  request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
@@ -11,7 +11,7 @@ def _convert_request(request, files=None):
11
11
  request.set_formdata_body(files)
12
12
  return request
13
13
  {% endif %}
14
- {% if namespace_model.need_format_url and not async_mode %}
14
+ {% if code_model.need_format_url and not async_mode %}
15
15
 
16
16
  def _format_url_section(template, **kwargs):
17
17
  components = template.split("/")
@@ -25,8 +25,8 @@ def _format_url_section(template, **kwargs):
25
25
  ]
26
26
  template = "/".join(components)
27
27
  {% endif %}
28
- {% if namespace_model.need_mixin_abc %}
29
- {% for client in namespace_model.clients | selectattr("has_mixin") %}
28
+ {% if code_model.need_mixin_abc %}
29
+ {% for client in code_model.clients | selectattr("has_mixin") %}
30
30
 
31
31
  class {{ client.name }}MixinABC(ABC):
32
32
  """DO NOT use this class. It is for internal typing use only."""
@@ -36,7 +36,7 @@ class {{ client.name }}MixinABC(ABC):
36
36
  _deserialize: "Deserializer"
37
37
  {% endfor %}
38
38
  {% endif %}
39
- {% if namespace_model.has_abstract_operations %}
39
+ {% if code_model.has_abstract_operations %}
40
40
 
41
41
  def raise_if_not_implemented(cls, abstract_methods):
42
42
  not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))]
@@ -1,4 +1,4 @@
1
1
  # coding=utf-8
2
- {{ namespace_model.options['license_header'] }}
2
+ {{ code_model.options['license_header'] }}
3
3
 
4
- VERSION = "{{ namespace_model.options['package_version'] }}"
4
+ VERSION = "{{ code_model.options['package_version'] }}"
@@ -280,35 +280,6 @@ def update_type(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
280
280
  return updated_type
281
281
 
282
282
 
283
- def update_parameter_base(
284
- yaml_data: Dict[str, Any], *, override_client_name: Optional[str] = None
285
- ) -> Dict[str, Any]:
286
- location = yaml_data["protocol"].get("http", {}).get("in")
287
- if not location:
288
- location = "other"
289
- if location == "uri":
290
- location = "endpointPath"
291
- grouped_by = (
292
- yaml_data["groupedBy"]["language"]["default"]["name"]
293
- if yaml_data.get("groupedBy")
294
- else None
295
- )
296
- client_name: str = override_client_name or yaml_data["language"]["default"]["name"]
297
- if grouped_by and client_name[0] != "_":
298
- # this is an m4 bug, doesn't hide constant grouped params, patching m4 for now
299
- client_name = "_" + client_name
300
- return {
301
- "optional": not yaml_data.get("required", False),
302
- "description": yaml_data["language"]["default"]["description"],
303
- "clientName": client_name,
304
- "restApiName": yaml_data["language"]["default"].get("serializedName"),
305
- "clientDefaultValue": yaml_data.get("clientDefaultValue"),
306
- "location": location,
307
- "groupedBy": grouped_by,
308
- "checkClientInput": yaml_data.get("checkClientInput", False),
309
- }
310
-
311
-
312
283
  def update_parameter_delimiter(style: Optional[str]) -> Optional[str]:
313
284
  if not style:
314
285
  return None
@@ -458,6 +429,45 @@ class M4Reformatter(
458
429
  or self.version_tolerant
459
430
  )
460
431
 
432
+ def update_parameter_base(
433
+ self, yaml_data: Dict[str, Any], *, override_client_name: Optional[str] = None
434
+ ) -> Dict[str, Any]:
435
+ location = yaml_data["protocol"].get("http", {}).get("in")
436
+ if not location:
437
+ location = "other"
438
+ if location == "uri":
439
+ location = "endpointPath"
440
+ grouped_by = (
441
+ yaml_data["groupedBy"]["language"]["default"]["name"]
442
+ if yaml_data.get("groupedBy")
443
+ else None
444
+ )
445
+ client_name: str = (
446
+ override_client_name or yaml_data["language"]["default"]["name"]
447
+ )
448
+ if grouped_by and client_name[0] != "_":
449
+ # this is an m4 bug, doesn't hide constant grouped params, patching m4 for now
450
+ client_name = "_" + client_name
451
+ if yaml_data.get("origin") == "modelerfour:synthesized/api-version":
452
+ yaml_data["inDocstring"] = False
453
+ if self.legacy:
454
+ yaml_data["implementation"] = "Method"
455
+ yaml_data["checkClientInput"] = self.check_client_input
456
+ yaml_data["isApiVersion"] = True
457
+ return {
458
+ "optional": not yaml_data.get("required", False),
459
+ "description": yaml_data["language"]["default"]["description"],
460
+ "clientName": client_name,
461
+ "restApiName": yaml_data["language"]["default"].get("serializedName"),
462
+ "clientDefaultValue": yaml_data.get("clientDefaultValue"),
463
+ "location": location,
464
+ "groupedBy": grouped_by,
465
+ "checkClientInput": yaml_data.get("checkClientInput", False),
466
+ "inDocstring": yaml_data.get("inDocstring", True),
467
+ "isApiVersion": yaml_data.get("isApiVersion", False),
468
+ "implementation": yaml_data.get("implementation"),
469
+ }
470
+
461
471
  def update_overloads(
462
472
  self,
463
473
  group_name: str,
@@ -646,7 +656,7 @@ class M4Reformatter(
646
656
  ) -> Dict[str, Any]:
647
657
  flattened = body_param.get("flattened")
648
658
  is_partial_body = body_param.get("isPartialBody")
649
- param_base = update_parameter_base(body_param)
659
+ param_base = self.update_parameter_base(body_param)
650
660
  body_param = copy.deepcopy(param_base)
651
661
  body_param["type"] = body_type
652
662
  body_param["contentTypes"] = content_types or [
@@ -811,11 +821,6 @@ class M4Reformatter(
811
821
  ):
812
822
  continue
813
823
  seen_client_names.add(client_name)
814
- if param.get("origin") == "modelerfour:synthesized/api-version":
815
- param["inDocstring"] = False
816
- if self.legacy:
817
- param["implementation"] = "Method"
818
- param["checkClientInput"] = self.check_client_input
819
824
  if has_flattened_body and param.get("targetProperty"):
820
825
  retval.append(self.update_flattened_parameter(param, body_parameter))
821
826
  continue
@@ -910,7 +915,7 @@ class M4Reformatter(
910
915
  in_overload: bool = False,
911
916
  in_overriden: bool = False,
912
917
  ) -> Dict[str, Any]:
913
- param_base = update_parameter_base(
918
+ param_base = self.update_parameter_base(
914
919
  yaml_data, override_client_name=override_client_name
915
920
  )
916
921
  type = get_type(yaml_data["schema"])
@@ -948,13 +953,17 @@ class M4Reformatter(
948
953
 
949
954
  client_name = "base_url" if self.legacy else "endpoint"
950
955
  global_parameter["language"]["default"]["description"] = "Service URL."
951
- elif name == "api_version":
956
+ elif (
957
+ global_parameter.get("origin") == "modelerfour:synthesized/api-version"
958
+ ):
952
959
  self.check_client_input = True
953
- global_params.append(
954
- self.update_parameter(
955
- global_parameter, override_client_name=client_name
956
- )
960
+ param = self.update_parameter(
961
+ global_parameter, override_client_name=client_name
957
962
  )
963
+ if global_parameter.get("origin") == "modelerfour:synthesized/api-version":
964
+ param["implementation"] = "Client"
965
+ param["checkClientInput"] = False
966
+ global_params.append(param)
958
967
  return global_params
959
968
 
960
969
  def get_token_credential(self, credential_scopes: List[str]) -> Dict[str, Any]:
@@ -1108,14 +1117,15 @@ class M4Reformatter(
1108
1117
  # we don't generate cloud error
1109
1118
  continue
1110
1119
  update_type(t)
1111
- yaml_data[namespace] = {}
1112
- yaml_data[namespace]["clients"] = [self.update_client(yaml_data)]
1113
- yaml_data[namespace]["clients"][0]["operationGroups"] = [
1120
+ yaml_data["namespace"] = namespace
1121
+ yaml_data["subnamespaceToClients"] = {}
1122
+ yaml_data["clients"] = [self.update_client(yaml_data)]
1123
+ yaml_data["clients"][0]["operationGroups"] = [
1114
1124
  self.update_operation_group(og) for og in yaml_data["operationGroups"]
1115
1125
  ]
1116
- yaml_data[namespace]["types"] = list(
1117
- ORIGINAL_ID_TO_UPDATED_TYPE.values()
1118
- ) + list(KNOWN_TYPES.values())
1126
+ yaml_data["types"] = list(ORIGINAL_ID_TO_UPDATED_TYPE.values()) + list(
1127
+ KNOWN_TYPES.values()
1128
+ )
1119
1129
  if yaml_data.get("globalParameters"):
1120
1130
  del yaml_data["globalParameters"]
1121
1131
  del yaml_data["info"]