@autorest/python 6.1.11 → 6.2.1

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 (68) hide show
  1. package/autorest/_utils.py +2 -1
  2. package/autorest/codegen/__init__.py +23 -81
  3. package/autorest/codegen/models/__init__.py +5 -3
  4. package/autorest/codegen/models/{base_type.py → base.py} +24 -3
  5. package/autorest/codegen/models/base_builder.py +9 -5
  6. package/autorest/codegen/models/client.py +183 -13
  7. package/autorest/codegen/models/code_model.py +154 -141
  8. package/autorest/codegen/models/combined_type.py +5 -2
  9. package/autorest/codegen/models/constant_type.py +38 -4
  10. package/autorest/codegen/models/credential_types.py +1 -1
  11. package/autorest/codegen/models/dictionary_type.py +1 -1
  12. package/autorest/codegen/models/enum_type.py +5 -3
  13. package/autorest/codegen/models/imports.py +78 -29
  14. package/autorest/codegen/models/list_type.py +1 -1
  15. package/autorest/codegen/models/lro_operation.py +5 -1
  16. package/autorest/codegen/models/model_type.py +1 -2
  17. package/autorest/codegen/models/operation.py +34 -10
  18. package/autorest/codegen/models/operation_group.py +16 -5
  19. package/autorest/codegen/models/paging_operation.py +5 -4
  20. package/autorest/codegen/models/parameter.py +19 -6
  21. package/autorest/codegen/models/primitive_types.py +1 -2
  22. package/autorest/codegen/models/property.py +4 -4
  23. package/autorest/codegen/models/request_builder.py +17 -6
  24. package/autorest/codegen/models/request_builder_parameter.py +5 -2
  25. package/autorest/codegen/models/response.py +6 -3
  26. package/autorest/codegen/serializers/__init__.py +207 -135
  27. package/autorest/codegen/serializers/builder_serializer.py +2 -4
  28. package/autorest/codegen/serializers/client_serializer.py +41 -45
  29. package/autorest/codegen/serializers/general_serializer.py +80 -37
  30. package/autorest/codegen/serializers/import_serializer.py +30 -36
  31. package/autorest/codegen/serializers/metadata_serializer.py +36 -14
  32. package/autorest/codegen/serializers/model_serializer.py +34 -19
  33. package/autorest/codegen/serializers/operation_groups_serializer.py +22 -6
  34. package/autorest/codegen/serializers/operations_init_serializer.py +10 -4
  35. package/autorest/codegen/serializers/sample_serializer.py +144 -0
  36. package/autorest/codegen/templates/client.py.jinja2 +7 -15
  37. package/autorest/codegen/templates/client_container.py.jinja2 +12 -0
  38. package/autorest/codegen/templates/config.py.jinja2 +13 -26
  39. package/autorest/codegen/templates/config_container.py.jinja2 +16 -0
  40. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  41. package/autorest/codegen/templates/init.py.jinja2 +9 -3
  42. package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
  43. package/autorest/codegen/templates/metadata.json.jinja2 +13 -14
  44. package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
  45. package/autorest/codegen/templates/model_init.py.jinja2 +1 -1
  46. package/autorest/codegen/templates/operation.py.jinja2 +1 -1
  47. package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
  48. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +5 -5
  49. package/autorest/codegen/templates/operation_tools.jinja2 +2 -2
  50. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
  51. package/autorest/codegen/templates/{CHANGELOG.md.jinja2 → packaging_templates/CHANGELOG.md.jinja2} +0 -0
  52. package/autorest/codegen/templates/{LICENSE.jinja2 → packaging_templates/LICENSE.jinja2} +0 -0
  53. package/autorest/codegen/templates/{MANIFEST.in.jinja2 → packaging_templates/MANIFEST.in.jinja2} +0 -0
  54. package/autorest/codegen/templates/{README.md.jinja2 → packaging_templates/README.md.jinja2} +0 -0
  55. package/autorest/codegen/templates/{dev_requirements.txt.jinja2 → packaging_templates/dev_requirements.txt.jinja2} +0 -0
  56. package/autorest/codegen/templates/{setup.py.jinja2 → packaging_templates/setup.py.jinja2} +12 -9
  57. package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
  58. package/autorest/codegen/templates/sample.py.jinja2 +44 -0
  59. package/autorest/codegen/templates/vendor.py.jinja2 +4 -2
  60. package/autorest/m4reformatter/__init__.py +18 -4
  61. package/autorest/multiapi/models/imports.py +89 -18
  62. package/autorest/multiapi/serializers/import_serializer.py +88 -7
  63. package/autorest/multiapi/utils.py +6 -0
  64. package/autorest/preprocess/__init__.py +20 -8
  65. package/package.json +1 -1
  66. package/run_cadl.py +0 -1
  67. package/autorest/cadlflags/__init__.py +0 -130
  68. package/autorest/codegen/models/base_model.py +0 -28
@@ -5,10 +5,12 @@
5
5
  # --------------------------------------------------------------------------
6
6
  from typing import cast, List
7
7
  from abc import ABC, abstractmethod
8
+
8
9
  from jinja2 import Environment
9
10
  from ..models import ModelType, CodeModel, Property
10
11
  from ..models.imports import FileImport, TypingSection, MsrestImportType, ImportType
11
12
  from .import_serializer import FileImportSerializer
13
+ from ..models.constant_type import ConstantType
12
14
 
13
15
 
14
16
  def _documentation_string(
@@ -93,13 +95,17 @@ class _ModelSerializer(ABC):
93
95
  f"Known sub-classes are: {', '.join(v.name for v in model.discriminated_subtypes.values())}"
94
96
  )
95
97
 
96
- def init_line(self, model: ModelType) -> List[str]:
97
- init_properties_declaration = []
98
- init_line_parameters = [
98
+ @staticmethod
99
+ def _init_line_parameters(model: ModelType):
100
+ return [
99
101
  p
100
102
  for p in model.properties
101
103
  if not p.readonly and not p.is_discriminator and not p.constant
102
104
  ]
105
+
106
+ def init_line(self, model: ModelType) -> List[str]:
107
+ init_properties_declaration = []
108
+ init_line_parameters = self._init_line_parameters(model)
103
109
  init_line_parameters.sort(key=lambda x: x.optional)
104
110
  if init_line_parameters:
105
111
  init_properties_declaration.append("*,")
@@ -134,11 +140,9 @@ class MsrestModelSerializer(_ModelSerializer):
134
140
  )
135
141
  for model in self.code_model.model_types:
136
142
  file_import.merge(model.imports(is_operation_file=False))
137
- init_line_parameters = [
138
- p for p in model.properties if not p.readonly and not p.is_discriminator
139
- ]
140
- for param in init_line_parameters:
143
+ for param in self._init_line_parameters(model):
141
144
  file_import.merge(param.imports())
145
+
142
146
  return file_import
143
147
 
144
148
  def declare_model(self, model: ModelType) -> str:
@@ -209,8 +213,8 @@ class DpgModelSerializer(_ModelSerializer):
209
213
 
210
214
  for model in self.code_model.model_types:
211
215
  file_import.merge(model.imports(is_operation_file=False))
212
- for param in model.properties:
213
- file_import.merge(param.imports())
216
+ for prop in model.properties:
217
+ file_import.merge(prop.imports())
214
218
  return file_import
215
219
 
216
220
  def declare_model(self, model: ModelType) -> str:
@@ -222,30 +226,31 @@ class DpgModelSerializer(_ModelSerializer):
222
226
  return f"class {model.name}({basename}):{model.pylint_disable}"
223
227
 
224
228
  @staticmethod
225
- def get_properties_to_initialize(model: ModelType) -> List[Property]:
229
+ def get_properties_to_declare(model: ModelType) -> List[Property]:
226
230
  if model.parents:
231
+ parent_properties = [
232
+ p for bm in model.parents for p in cast(ModelType, bm).properties
233
+ ]
227
234
  properties_to_declare = [
228
235
  p
229
- for bm in model.parents
230
236
  for p in model.properties
231
- if p not in cast(ModelType, bm).properties
237
+ if not any(
238
+ p.client_name == pp.client_name
239
+ and p.type_annotation() == pp.type_annotation()
240
+ for pp in parent_properties
241
+ )
232
242
  ]
233
-
234
243
  else:
235
244
  properties_to_declare = model.properties
236
245
  if any(p for p in properties_to_declare if p.client_name == "_"):
237
246
  raise ValueError("We do not generate anonymous properties")
238
- return [
239
- p
240
- for p in properties_to_declare
241
- if (not p.is_discriminator or p.is_polymorphic)
242
- ]
247
+ return properties_to_declare
243
248
 
244
249
  @staticmethod
245
250
  def declare_property(prop: Property) -> List[str]:
246
251
  attribute_key = _ModelSerializer.escape_dot(prop.rest_api_name)
247
252
  args = []
248
- if prop.client_name != attribute_key:
253
+ if prop.client_name != attribute_key or prop.is_discriminator:
249
254
  args.append(f'name="{attribute_key}"')
250
255
  if prop.readonly:
251
256
  args.append("readonly=True")
@@ -261,3 +266,13 @@ class DpgModelSerializer(_ModelSerializer):
261
266
  if comment:
262
267
  ret.append(f'"""{comment}"""')
263
268
  return ret
269
+
270
+ def initialize_properties(self, model: ModelType) -> List[str]:
271
+ init_args = []
272
+ for prop in self.get_properties_to_declare(model):
273
+ if prop.constant or prop.is_discriminator:
274
+ init_args.append(
275
+ f"self.{prop.client_name} = {cast(ConstantType, prop.type).get_declaration()} "
276
+ f"# type: {prop.type_annotation()}"
277
+ )
278
+ return init_args
@@ -3,7 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Optional
6
+ from typing import Optional, List, Union
7
7
  import functools
8
8
  from jinja2 import Environment
9
9
 
@@ -11,6 +11,9 @@ from ..models import (
11
11
  CodeModel,
12
12
  OperationGroup,
13
13
  FileImport,
14
+ RequestBuilder,
15
+ OverloadedRequestBuilder,
16
+ Client,
14
17
  )
15
18
  from .import_serializer import FileImportSerializer
16
19
  from .builder_serializer import get_operation_serializer, RequestBuilderSerializer
@@ -20,20 +23,35 @@ class OperationGroupsSerializer:
20
23
  def __init__(
21
24
  self,
22
25
  code_model: CodeModel,
26
+ clients: List[Client],
23
27
  env: Environment,
24
28
  async_mode: bool,
25
29
  operation_group: Optional[OperationGroup] = None,
26
- ) -> None:
30
+ ):
31
+ self.clients = clients
27
32
  self.code_model = code_model
28
33
  self.env = env
29
34
  self.async_mode = async_mode
30
35
  self.operation_group = operation_group
31
36
 
37
+ def _get_request_builders(
38
+ self, operation_group: OperationGroup
39
+ ) -> List[Union[OverloadedRequestBuilder, RequestBuilder]]:
40
+ return [
41
+ r
42
+ for client in self.clients
43
+ for r in client.request_builders
44
+ if r.client.name == operation_group.client.name
45
+ and r.group_name == operation_group.property_name
46
+ and not r.is_overload
47
+ and not r.abstract
48
+ ]
49
+
32
50
  def serialize(self) -> str:
33
51
  operation_groups = (
34
52
  [self.operation_group]
35
53
  if self.operation_group
36
- else self.code_model.operation_groups
54
+ else [og for client in self.clients for og in client.operation_groups]
37
55
  )
38
56
  imports = FileImport()
39
57
  for operation_group in operation_groups:
@@ -63,7 +81,5 @@ class OperationGroupsSerializer:
63
81
  self.code_model,
64
82
  async_mode=False,
65
83
  ),
66
- request_builders=[
67
- rb for rb in self.code_model.request_builders if not rb.abstract
68
- ],
84
+ get_request_builders=self._get_request_builders,
69
85
  )
@@ -7,14 +7,19 @@ from typing import List
7
7
  from jinja2 import Environment
8
8
 
9
9
  from autorest.codegen.models.operation_group import OperationGroup
10
- from ..models import CodeModel
10
+ from ..models import CodeModel, Client
11
11
 
12
12
 
13
13
  class OperationsInitSerializer:
14
14
  def __init__(
15
- self, code_model: CodeModel, env: Environment, async_mode: bool
15
+ self,
16
+ code_model: CodeModel,
17
+ clients: List[Client],
18
+ env: Environment,
19
+ async_mode: bool,
16
20
  ) -> None:
17
21
  self.code_model = code_model
22
+ self.clients = clients
18
23
  self.env = env
19
24
  self.async_mode = async_mode
20
25
 
@@ -28,7 +33,8 @@ class OperationsInitSerializer:
28
33
 
29
34
  return [
30
35
  f"from .{_get_filename(og)} import {og.class_name}"
31
- for og in self.code_model.operation_groups
36
+ for client in self.clients
37
+ for og in client.operation_groups
32
38
  ]
33
39
 
34
40
  def serialize(self) -> str:
@@ -38,7 +44,7 @@ class OperationsInitSerializer:
38
44
 
39
45
  return operation_group_init_template.render(
40
46
  code_model=self.code_model,
41
- operation_groups=self.code_model.operation_groups,
42
47
  async_mode=self.async_mode,
43
48
  operation_group_imports=self.operation_group_imports,
49
+ clients=self.clients,
44
50
  )
@@ -0,0 +1,144 @@
1
+ # pylint: disable=too-many-lines
2
+ # -------------------------------------------------------------------------
3
+ # Copyright (c) Microsoft Corporation. All rights reserved.
4
+ # Licensed under the MIT License. See License.txt in the project root for
5
+ # license information.
6
+ # --------------------------------------------------------------------------
7
+ import logging
8
+ from typing import Dict, Any
9
+ from jinja2 import Environment
10
+
11
+ from autorest.codegen.models.credential_types import AzureKeyCredentialType
12
+ from autorest.codegen.models.credential_types import TokenCredentialType
13
+ from autorest.codegen.models.imports import FileImport, ImportType
14
+ from autorest.codegen.models.operation import OperationBase
15
+ from autorest.codegen.models.operation_group import OperationGroup
16
+ from autorest.codegen.serializers.import_serializer import FileImportSerializer
17
+ from ..models import CodeModel
18
+
19
+ _LOGGER = logging.getLogger(__name__)
20
+
21
+
22
+ class SampleSerializer:
23
+ def __init__(
24
+ self,
25
+ code_model: CodeModel,
26
+ env: Environment,
27
+ operation_group: OperationGroup,
28
+ operation: OperationBase[Any],
29
+ sample: Dict[str, Any],
30
+ file_name: str,
31
+ sample_origin_name: str,
32
+ ) -> None:
33
+ self.code_model = code_model
34
+ self.env = env
35
+ self.operation_group = operation_group
36
+ self.operation = operation
37
+ self.sample = sample
38
+ self.file_name = file_name
39
+ self.sample_origin_name = sample_origin_name
40
+
41
+ def _imports(self) -> FileImportSerializer:
42
+ imports = FileImport()
43
+ namespace = (self.code_model.options["package_name"] or "").replace(
44
+ "-", "."
45
+ ) or self.code_model.namespace
46
+ client = self.code_model.clients[0]
47
+ imports.add_submodule_import(namespace, client.name, ImportType.THIRDPARTY)
48
+ credential_type = getattr(client.credential, "type", None)
49
+ if isinstance(credential_type, TokenCredentialType):
50
+ imports.add_submodule_import(
51
+ "azure.identity", "DefaultAzureCredential", ImportType.THIRDPARTY
52
+ )
53
+ elif isinstance(credential_type, AzureKeyCredentialType):
54
+ imports.add_import("os", ImportType.STDLIB)
55
+ imports.add_submodule_import(
56
+ "azure.core.credentials", "AzureKeyCredential", ImportType.THIRDPARTY
57
+ )
58
+ return FileImportSerializer(imports, True)
59
+
60
+ def _client_params(self) -> Dict[str, Any]:
61
+ # client params
62
+ special_param = dict()
63
+ credential_type = getattr(self.code_model.clients[0].credential, "type", None)
64
+ if isinstance(credential_type, TokenCredentialType):
65
+ special_param.update({"credential": "DefaultAzureCredential()"})
66
+ elif isinstance(credential_type, AzureKeyCredentialType):
67
+ special_param.update(
68
+ {"credential": 'AzureKeyCredential(key=os.getenv("AZURE_KEY"))'}
69
+ )
70
+
71
+ params_positional = [
72
+ p
73
+ for p in self.code_model.clients[0].parameters.positional
74
+ if not (p.optional or p.client_default_value)
75
+ ]
76
+ cls = lambda x: f'"{x}"'
77
+ client_params = {
78
+ p.client_name: special_param.get(
79
+ p.client_name,
80
+ cls(
81
+ self.sample["parameters"].get(p.rest_api_name)
82
+ or p.client_name.upper()
83
+ ),
84
+ )
85
+ for p in params_positional
86
+ }
87
+
88
+ return client_params
89
+
90
+ # prepare operation parameters
91
+ def _operation_params(self) -> Dict[str, Any]:
92
+ params_positional = [
93
+ p
94
+ for p in self.operation.parameters.positional
95
+ if not p.client_default_value
96
+ ]
97
+ cls = lambda x: f'"{x}"' if isinstance(x, str) else str(x)
98
+ failure_info = "fail to find required param named {} in example file {}"
99
+ operation_params = {}
100
+ for param in params_positional:
101
+ name = param.rest_api_name
102
+ param_value = self.sample["parameters"].get(name)
103
+ if not param.optional:
104
+ if not param_value:
105
+ raise Exception(failure_info.format(name, self.sample_origin_name))
106
+ operation_params[param.client_name] = cls(param_value)
107
+ return operation_params
108
+
109
+ def _operation_group_name(self) -> str:
110
+ if self.operation_group.is_mixin:
111
+ return ""
112
+ return f".{self.operation_group.property_name}"
113
+
114
+ def _operation_result(self) -> str:
115
+ lro = ".result()"
116
+ paging = "\n for item in response:\n print(item)"
117
+ normal_print = "\n print(response)"
118
+ if self.operation.operation_type == "paging":
119
+ return paging
120
+ if self.operation.operation_type == "lro":
121
+ return lro + normal_print
122
+ if self.operation.operation_type == "lropaging":
123
+ return lro + paging
124
+ return normal_print
125
+
126
+ def _operation_name(self) -> str:
127
+ return f".{self.operation.name}"
128
+
129
+ def _origin_file(self) -> str:
130
+ name = self.sample.get("x-ms-original-file", "").split("specification")[-1]
131
+ return "specification" + name if name else name
132
+
133
+ def serialize(self) -> str:
134
+ return self.env.get_template("sample.py.jinja2").render(
135
+ code_model=self.code_model,
136
+ file_name=self.file_name,
137
+ operation_result=self._operation_result(),
138
+ operation_params=self._operation_params(),
139
+ operation_group_name=self._operation_group_name(),
140
+ operation_name=self._operation_name(),
141
+ imports=self._imports(),
142
+ client_params=self._client_params(),
143
+ origin_file=self._origin_file(),
144
+ )
@@ -1,24 +1,16 @@
1
- {% import 'keywords.jinja2' as keywords with context %}
2
- {% import 'operation_tools.jinja2' as op_tools %}
3
- {# actual template starts here #}
4
- # coding=utf-8
5
- {{ code_model.options['license_header'] }}
6
-
7
- {{ imports }}
8
-
9
1
  {{ serializer.class_definition }}
10
- """{{ op_tools.wrap_string(code_model.client.description, "\n") | indent }}
2
+ """{{ op_tools.wrap_string(client.description, "\n") | indent }}
11
3
 
12
4
  {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
13
5
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
14
6
  {% if serializer.should_init_super %}
15
7
  super().__init__()
16
8
  {% endif %}
17
- {% if code_model.client.parameters.kwargs_to_pop %}
9
+ {% if client.parameters.kwargs_to_pop %}
18
10
  {{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
19
11
  {% endif %}
20
- {% if code_model.client.has_parameterized_host %}
21
- {{ serializer.host_variable_name }} = {{ keywords.escape_str(code_model.client.url) }}
12
+ {% if client.has_parameterized_host %}
13
+ {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
22
14
  {% endif %}
23
15
  {{ serializer.initialize_config() }}
24
16
  {{ serializer.initialize_pipeline_client(async_mode) }}
@@ -29,7 +21,7 @@
29
21
  {{ serializer.send_request_signature_and_response_type_annotation(async_mode) | indent }}
30
22
  {{ op_tools.serialize(serializer.send_request_description(async_mode)) | indent(8) }}
31
23
  request_copy = deepcopy(request)
32
- {% if code_model.client.parameters.path %}
24
+ {% if client.parameters.path %}
33
25
  {{ op_tools.serialize(serializer.serialize_path()) | indent(8) }}
34
26
  request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
35
27
  {% else %}
@@ -43,9 +35,9 @@
43
35
  {% endif %}
44
36
  {{ keywords.await }}self._client.close()
45
37
 
46
- {{ keywords.def }} __{{ keywords.async_prefix }}enter__(self){{ (" -> \"" + code_model.client.name + "\"") if async_mode else "" }}:
38
+ {{ keywords.def }} __{{ keywords.async_prefix }}enter__(self){{ (" -> \"" + client.name + "\"") if async_mode else "" }}:
47
39
  {% if not async_mode %}
48
- # type: () -> {{ code_model.client.name }}
40
+ # type: () -> {{ client.name }}
49
41
  {% endif %}
50
42
  {{ keywords.await }}self._client.__{{ keywords.async_prefix }}enter__()
51
43
  return self
@@ -0,0 +1,12 @@
1
+ {% import 'keywords.jinja2' as keywords with context %}
2
+ {% import 'operation_tools.jinja2' as op_tools %}
3
+ {# actual template starts here #}
4
+ # coding=utf-8
5
+ {{ code_model.options['license_header'] }}
6
+
7
+ {{ imports }}
8
+
9
+ {% for client in clients %}
10
+ {% set serializer = get_serializer(client) %}
11
+ {% include "client.py.jinja2" %}
12
+ {% endfor %}
@@ -1,44 +1,31 @@
1
- {% import 'keywords.jinja2' as keywords with context %}
2
- {% import 'operation_tools.jinja2' as op_tools %}
3
- {% set version_import = ".._version" if async_mode else "._version" %}
4
- {# actual template starts here #}
5
- # coding=utf-8
6
- {{ code_model.options['license_header'] }}
7
-
8
- {{ imports }}
9
-
10
- {% if not code_model.options['package_version'] %}
11
- VERSION = "unknown"
12
- {% endif %}
13
-
14
- class {{ code_model.client.name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
15
- """Configuration for {{ code_model.client.name }}.
1
+ class {{ client.name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
2
+ """Configuration for {{ client.name }}.
16
3
 
17
4
  Note that all parameters used to create this instance are saved as instance
18
5
  attributes.
19
- {% if code_model.config.parameters.method | first %}
6
+ {% if client.config.parameters.method | first %}
20
7
 
21
8
  {% endif %}
22
9
  {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
23
10
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
24
- super({{ code_model.client.name }}Configuration, self).__init__(**kwargs)
25
- {% if code_model.config.parameters.kwargs_to_pop %}
11
+ super({{ client.name }}Configuration, self).__init__(**kwargs)
12
+ {% if client.config.parameters.kwargs_to_pop %}
26
13
  {{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
27
14
  {% endif %}
28
15
  {% if serializer.check_required_parameters() %}
29
16
  {{ op_tools.serialize(serializer.check_required_parameters()) | indent(8) -}}
30
17
  {% endif %}
31
18
 
32
- {% for parameter in code_model.config.parameters.method %}
19
+ {% for parameter in client.config.parameters.method %}
33
20
  self.{{ parameter.client_name }} = {{ parameter.client_name }}
34
21
  {% endfor %}
35
22
  {% if serializer.set_constants() %}
36
23
  {{ op_tools.serialize(serializer.set_constants()) | indent(8) -}}
37
24
  {% endif %}
38
- {% if code_model.credential and code_model.credential.type.policy.credential_scopes is defined %}
39
- self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential.type.policy.credential_scopes }})
25
+ {% if client.credential and client.credential.type.policy.credential_scopes is defined %}
26
+ self.credential_scopes = kwargs.pop('credential_scopes', {{ client.credential.type.policy.credential_scopes }})
40
27
  {% endif %}
41
- kwargs.setdefault('sdk_moniker', '{{ sdk_moniker }}/{}'.format(VERSION))
28
+ kwargs.setdefault('sdk_moniker', '{{ client.config.sdk_moniker }}/{}'.format(VERSION))
42
29
  self._configure(**kwargs)
43
30
 
44
31
  def _configure(
@@ -52,17 +39,17 @@ class {{ code_model.client.name }}Configuration(Configuration): # pylint: disab
52
39
  self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
53
40
  self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
54
41
  self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
55
- self.http_logging_policy = kwargs.get('http_logging_policy') or {{ "ARM" if code_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)
56
43
  self.retry_policy = kwargs.get('retry_policy') or policies.{{ keywords.async_class }}RetryPolicy(**kwargs)
57
44
  self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
58
45
  self.redirect_policy = kwargs.get('redirect_policy') or policies.{{ keywords.async_class }}RedirectPolicy(**kwargs)
59
46
  self.authentication_policy = kwargs.get('authentication_policy')
60
- {% if code_model.credential %}
47
+ {% if client.credential %}
61
48
  {# only adding this if credential_scopes is not passed during code generation #}
62
- {% if code_model.credential.type.policy.credential_scopes is defined and code_model.credential.type.policy.credential_scopes | length == 0 %}
49
+ {% if client.credential.type.policy.credential_scopes is defined and client.credential.type.policy.credential_scopes | length == 0 %}
63
50
  if not self.credential_scopes and not self.authentication_policy:
64
51
  raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
65
52
  {% endif %}
66
53
  if self.credential and not self.authentication_policy:
67
- self.authentication_policy = {{ code_model.credential.type.policy.call(async_mode) }}
54
+ self.authentication_policy = {{ client.credential.type.policy.call(async_mode) }}
68
55
  {% endif %}
@@ -0,0 +1,16 @@
1
+ {% import 'keywords.jinja2' as keywords with context %}
2
+ {% import 'operation_tools.jinja2' as op_tools %}
3
+ {# actual template starts here #}
4
+ # coding=utf-8
5
+ {{ code_model.options['license_header'] }}
6
+
7
+ {{ imports }}
8
+
9
+ {% if not code_model.options['package_version'] %}
10
+ VERSION = "unknown"
11
+ {% endif %}
12
+
13
+ {% for client in clients %}
14
+ {% set serializer = get_serializer(client) %}
15
+ {% include "config.py.jinja2" %}
16
+ {% endfor %}
@@ -6,4 +6,4 @@ from azure.core import CaseInsensitiveEnumMeta
6
6
 
7
7
  {% for enum in code_model.enums | sort %}
8
8
  {% include "enum.py.jinja2" %}
9
- {% endfor %}
9
+ {% endfor %}
@@ -2,8 +2,10 @@
2
2
  # coding=utf-8
3
3
  {{ code_model.options['license_header'] }}
4
4
 
5
- {% if code_model.request_builders %}
6
- from .{{ code_model.client.filename }} import {{ code_model.client.name }}
5
+ {% if clients %}
6
+ {% for client in clients %}
7
+ from .{{ client.filename }} import {{ client.name }}
8
+ {% endfor %}
7
9
  {% endif %}
8
10
  {% if not async_mode and code_model.options['package_version']%}
9
11
  from ._version import VERSION
@@ -12,7 +14,11 @@ __version__ = VERSION
12
14
  {% endif %}
13
15
 
14
16
  {{ keywords.patch_imports(try_except=True) }}
15
- __all__ = [{{("'" + code_model.client.name + "'") if code_model.request_builders else ""}}]
17
+ __all__ = [
18
+ {% for client in clients %}
19
+ {{ keywords.escape_str(client.name) }},
20
+ {% endfor %}
21
+ ]
16
22
  {{ keywords.extend_all }}
17
23
 
18
24
  _patch_sdk()
@@ -16,4 +16,4 @@
16
16
  {% endif %}
17
17
  {% if not code_model.options["version_tolerant"] %}
18
18
  {{ operation_serializer.get_metadata_url(operation) -}}
19
- {% endif %}
19
+ {% endif %}
@@ -1,18 +1,17 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  {% import 'keywords.jinja2' as keywords %}
3
- {% set client = code_model.client %}
4
3
  {
5
4
  "chosen_version": {{ chosen_version | tojson }},
6
5
  "total_api_version_list": {{ total_api_version_list | tojson }},
7
6
  "client": {
8
- "name": {{ code_model.client.name | tojson }},
9
- "filename": {{ ("_" + code_model.module_name) | tojson }},
10
- "description": {{ code_model.client.description | tojson }},
7
+ "name": {{ client.name | tojson }},
8
+ "filename": {{ ("_" + client.legacy_filename) | tojson }},
9
+ "description": {{ client.description | tojson }},
11
10
  "host_value": {{ (client.parameters.host.client_default_value_declaration if not client.has_parameterized_host else None) | tojson }},
12
11
  "parameterized_host_template": {{ (keywords.escape_str(client.url) if client.has_parameterized_host else None) | tojson }},
13
- "azure_arm": {{ code_model.options["azure_arm"] | tojson }},
14
- "has_lro_operations": {{ code_model.has_lro_operations | tojson }},
15
- "client_side_validation": {{ code_model.options["client_side_validation"] | tojson }},
12
+ "azure_arm": {{ client.code_model.options["azure_arm"] | tojson }},
13
+ "has_lro_operations": {{ client.has_lro_operations | tojson }},
14
+ "client_side_validation": {{ client.code_model.options["client_side_validation"] | tojson }},
16
15
  "sync_imports": {{ sync_client_imports | tojson }},
17
16
  "async_imports": {{ async_client_imports | tojson }}
18
17
  },
@@ -38,11 +37,11 @@
38
37
  {% endfor %}
39
38
  },
40
39
  "constant": {
41
- {% for gp in code_model.client.parameters.constant | rejectattr("client_name", "equalto", "api_version") %}
40
+ {% for gp in client.parameters.constant | rejectattr("client_name", "equalto", "api_version") %}
42
41
  {{ gp.client_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
43
42
  {% endfor %}
44
43
  },
45
- "call": {{ code_model.client.parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") | map(attribute="client_name") | join(', ') | tojson }},
44
+ "call": {{ client.parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") | map(attribute="client_name") | join(', ') | tojson }},
46
45
  "service_client_specific": {
47
46
  "sync": {
48
47
  "api_version": {
@@ -92,14 +91,14 @@
92
91
  },
93
92
  "config": {
94
93
  "credential": {{ has_credential | tojson }},
95
- "credential_scopes": {{ (code_model.credential.type.policy.credential_scopes if has_credential and code_model.credential.type.policy.credential_scopes is defined else None)| tojson}},
96
- "credential_call_sync": {{ (code_model.credential.type.policy.call(async_mode=False) if has_credential else None) | tojson }},
97
- "credential_call_async": {{ (code_model.credential.type.policy.call(async_mode=True) if has_credential else None) | tojson }},
94
+ "credential_scopes": {{ (client.credential.type.policy.credential_scopes if has_credential and client.credential.type.policy.credential_scopes is defined else None)| tojson}},
95
+ "credential_call_sync": {{ (client.credential.type.policy.call(async_mode=False) if has_credential else None) | tojson }},
96
+ "credential_call_async": {{ (client.credential.type.policy.call(async_mode=True) if has_credential else None) | tojson }},
98
97
  "sync_imports": {{ sync_config_imports | tojson }},
99
98
  "async_imports": {{ async_config_imports | tojson }}
100
99
  },
101
100
  "operation_groups": {
102
- {% for operation_group in code_model.operation_groups | rejectattr('is_mixin') %}
101
+ {% for operation_group in client.operation_groups | rejectattr('is_mixin') %}
103
102
  {{ operation_group.property_name | tojson }}: {{ operation_group.class_name | tojson }}{{ "," if not loop.last else "" }}
104
103
  {% endfor %}
105
104
  }{{ "," if mixin_operations }}
@@ -156,4 +155,4 @@
156
155
  }
157
156
  }
158
157
  {% endif %}
159
- }
158
+ }
@@ -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 %}
@@ -25,4 +25,4 @@ __all__ = [
25
25
  {% endif %}
26
26
  ]
27
27
  {{ keywords.extend_all }}
28
- _patch_sdk()
28
+ _patch_sdk()
@@ -21,4 +21,4 @@
21
21
  {% endif %}
22
22
  {% if not code_model.options["version_tolerant"] %}
23
23
  {{ operation_serializer.get_metadata_url(operation) }}
24
- {% endif %}
24
+ {% endif %}