@autorest/python 6.9.3 → 6.9.5

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 (48) hide show
  1. package/autorest/_utils.py +35 -20
  2. package/autorest/codegen/__init__.py +252 -133
  3. package/autorest/codegen/_utils.py +2 -2
  4. package/autorest/codegen/models/__init__.py +7 -7
  5. package/autorest/codegen/models/base.py +6 -4
  6. package/autorest/codegen/models/client.py +34 -28
  7. package/autorest/codegen/models/combined_type.py +1 -1
  8. package/autorest/codegen/models/constant_type.py +1 -1
  9. package/autorest/codegen/models/credential_types.py +33 -23
  10. package/autorest/codegen/models/dictionary_type.py +1 -1
  11. package/autorest/codegen/models/enum_type.py +2 -2
  12. package/autorest/codegen/models/imports.py +77 -8
  13. package/autorest/codegen/models/list_type.py +1 -1
  14. package/autorest/codegen/models/lro_operation.py +5 -2
  15. package/autorest/codegen/models/model_type.py +1 -1
  16. package/autorest/codegen/models/operation.py +26 -18
  17. package/autorest/codegen/models/operation_group.py +2 -2
  18. package/autorest/codegen/models/paging_operation.py +13 -5
  19. package/autorest/codegen/models/parameter.py +1 -1
  20. package/autorest/codegen/models/primitive_types.py +27 -28
  21. package/autorest/codegen/models/property.py +3 -1
  22. package/autorest/codegen/models/request_builder.py +11 -10
  23. package/autorest/codegen/models/response.py +26 -14
  24. package/autorest/codegen/serializers/__init__.py +5 -0
  25. package/autorest/codegen/serializers/base_serializer.py +21 -0
  26. package/autorest/codegen/serializers/builder_serializer.py +39 -22
  27. package/autorest/codegen/serializers/client_serializer.py +20 -5
  28. package/autorest/codegen/serializers/enum_serializer.py +5 -8
  29. package/autorest/codegen/serializers/general_serializer.py +22 -27
  30. package/autorest/codegen/serializers/model_serializer.py +8 -10
  31. package/autorest/codegen/serializers/operation_groups_serializer.py +4 -5
  32. package/autorest/codegen/serializers/patch_serializer.py +4 -8
  33. package/autorest/codegen/serializers/request_builders_serializer.py +4 -4
  34. package/autorest/codegen/serializers/sample_serializer.py +11 -9
  35. package/autorest/codegen/serializers/types_serializer.py +3 -8
  36. package/autorest/codegen/templates/config.py.jinja2 +3 -1
  37. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  38. package/autorest/codegen/templates/model_base.py.jinja2 +5 -5
  39. package/autorest/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -1
  40. package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +3 -1
  41. package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +7 -3
  42. package/autorest/codegen/templates/serialization.py.jinja2 +17 -18
  43. package/autorest/jsonrpc/server.py +5 -1
  44. package/autorest/m4reformatter/__init__.py +1 -1
  45. package/autorest/multiapi/models/imports.py +18 -16
  46. package/autorest/multiapi/serializers/__init__.py +4 -1
  47. package/autorest/preprocess/__init__.py +1 -9
  48. package/package.json +1 -1
@@ -120,24 +120,39 @@ KNOWN_TYPES: Dict[str, Dict[str, Any]] = {
120
120
  JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
121
121
 
122
122
 
123
- def build_policies(is_arm: bool, async_mode: bool) -> List[str]:
124
- async_prefix = "Async" if async_mode else ""
125
- policies = [
126
- "policies.RequestIdPolicy(**kwargs)",
127
- "self._config.headers_policy",
128
- "self._config.user_agent_policy",
129
- "self._config.proxy_policy",
130
- "policies.ContentDecodePolicy(**kwargs)",
131
- f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
132
- if is_arm
133
- else None,
134
- "self._config.redirect_policy",
135
- "self._config.retry_policy",
136
- "self._config.authentication_policy",
137
- "self._config.custom_hook_policy",
138
- "self._config.logging_policy",
139
- "policies.DistributedTracingPolicy(**kwargs)",
140
- "policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None",
141
- "self._config.http_logging_policy",
142
- ]
123
+ def build_policies(
124
+ is_arm: bool, async_mode: bool, unbranded: bool = False, tracing: bool = True
125
+ ) -> List[str]:
126
+ if not unbranded:
127
+ # for Azure
128
+ async_prefix = "Async" if async_mode else ""
129
+ policies = [
130
+ "policies.RequestIdPolicy(**kwargs)",
131
+ "self._config.headers_policy",
132
+ "self._config.user_agent_policy",
133
+ "self._config.proxy_policy",
134
+ "policies.ContentDecodePolicy(**kwargs)",
135
+ f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
136
+ if is_arm
137
+ else None,
138
+ "self._config.redirect_policy",
139
+ "self._config.retry_policy",
140
+ "self._config.authentication_policy",
141
+ "self._config.custom_hook_policy",
142
+ "self._config.logging_policy",
143
+ "policies.DistributedTracingPolicy(**kwargs)" if tracing else None,
144
+ "policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None",
145
+ "self._config.http_logging_policy",
146
+ ]
147
+ else:
148
+ # for non-Azure
149
+ policies = [
150
+ "self._config.headers_policy",
151
+ "self._config.user_agent_policy",
152
+ "self._config.proxy_policy",
153
+ "policies.ContentDecodePolicy(**kwargs)",
154
+ "self._config.retry_policy",
155
+ "self._config.authentication_policy",
156
+ "self._config.logging_policy",
157
+ ]
143
158
  return [p for p in policies if p]
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
- from typing import Dict, Any, cast
7
+ from typing import Dict, Any, Union
8
8
  from pathlib import Path
9
9
  import yaml
10
10
 
@@ -20,76 +20,235 @@ def _default_pprint(package_name: str) -> str:
20
20
  return " ".join([i.capitalize() for i in package_name.split("-")])
21
21
 
22
22
 
23
- def _validate_code_model_options(options: Dict[str, Any]) -> None:
24
- if options["builders_visibility"] not in ["public", "hidden", "embedded"]:
25
- raise ValueError(
26
- "The value of --builders-visibility must be either 'public', 'hidden', "
27
- "or 'embedded'"
23
+ _LOGGER = logging.getLogger(__name__)
24
+
25
+
26
+ class OptionsRetriever:
27
+ OPTIONS_TO_DEFAULT = {
28
+ "azure-arm": False,
29
+ "unbranded": False,
30
+ "no-async": False,
31
+ "low-level-client": False,
32
+ "version-tolerant": True,
33
+ "keep-version-file": False,
34
+ "no-namespace-folders": False,
35
+ "basic-setup-py": False,
36
+ "client-side-validation": False,
37
+ "multiapi": False,
38
+ "polymorphic-examples": 5,
39
+ "generate-sample": False,
40
+ "from-typespec": False,
41
+ }
42
+
43
+ def __init__(self, options: Dict[str, Any]) -> None:
44
+ self.options = options
45
+
46
+ def __getattr__(self, prop: str) -> Any:
47
+ key = prop.replace("_", "-")
48
+ return self.options.get(key, self.OPTIONS_TO_DEFAULT.get(key))
49
+
50
+ @property
51
+ def company_name(self) -> bool:
52
+ return self.options.get(
53
+ "company-name", "Microsoft" if not self.unbranded else ""
28
54
  )
29
55
 
30
- if options["models_mode"] not in ["msrest", "dpg", "none"]:
31
- raise ValueError(
32
- "--models-mode can only be 'msrest', 'dpg' or 'none'. "
33
- "Pass in 'msrest' if you want msrest models, or "
34
- "'none' if you don't want any."
56
+ @property
57
+ def license_header(self) -> str:
58
+ license_header = self.options.get(
59
+ "header-text",
60
+ ""
61
+ if self.unbranded and not self.company_name
62
+ else DEFAULT_HEADER_TEXT.format(company_name=self.company_name),
35
63
  )
64
+ if license_header:
65
+ license_header = license_header.replace("\n", "\n# ")
66
+ license_header = (
67
+ "# --------------------------------------------------------------------------\n# "
68
+ + license_header
69
+ )
70
+ license_header += "\n# --------------------------------------------------------------------------"
71
+ return license_header
72
+
73
+ @property
74
+ def show_operations(self) -> bool:
75
+ return self.options.get("show-operations", not self.low_level_client)
36
76
 
37
- if not options["show_operations"] and options["builders_visibility"] == "embedded":
38
- raise ValueError(
39
- "Can not embed builders without operations. "
40
- "Either set --show-operations to True, or change the value of --builders-visibility "
41
- "to 'public' or 'hidden'."
77
+ @property
78
+ def _models_mode_default(self) -> str:
79
+ models_mode_default = (
80
+ "none" if self.low_level_client or self.version_tolerant else "msrest"
42
81
  )
82
+ if self.options.get("cadl_file") is not None:
83
+ models_mode_default = "dpg"
84
+ return models_mode_default
43
85
 
44
- if options["basic_setup_py"] and not options["package_version"]:
45
- raise ValueError("--basic-setup-py must be used with --package-version")
86
+ @property
87
+ def original_models_mode(self) -> str:
88
+ return self.options.get("models-mode", self._models_mode_default)
46
89
 
47
- if options["package_mode"] and not options["package_version"]:
48
- raise ValueError("--package-mode must be used with --package-version")
90
+ @property
91
+ def models_mode(self) -> Union[str, bool]:
92
+ # switch to falsy value for easier code writing
93
+ return (
94
+ False if self.original_models_mode == "none" else self.original_models_mode
95
+ )
49
96
 
50
- if not options["show_operations"] and options["combine_operation_files"]:
51
- raise ValueError(
52
- "Can not combine operation files if you are not showing operations. "
53
- "If you want operation files, pass in flag --show-operations"
97
+ @property
98
+ def tracing(self) -> bool:
99
+ return self.options.get(
100
+ "tracing",
101
+ self.show_operations and not self.unbranded,
54
102
  )
55
103
 
56
- if options["package_mode"]:
57
- if (
58
- (
59
- options["package_mode"] not in TYPESPEC_PACKAGE_MODE
60
- and options["from_typespec"]
61
- )
62
- or (
63
- options["package_mode"] not in VALID_PACKAGE_MODE
64
- and not options["from_typespec"]
65
- )
66
- ) and not Path(options["package_mode"]).exists():
67
- raise ValueError(
68
- f"--package-mode can only be {' or '.join(TYPESPEC_PACKAGE_MODE)} or directory which contains template files" # pylint: disable=line-too-long
69
- )
104
+ @property
105
+ def show_send_request(self) -> bool:
106
+ return self.options.get(
107
+ "show-send-request",
108
+ self._low_level_or_version_tolerant,
109
+ )
70
110
 
71
- if options["multiapi"] and options["version_tolerant"]:
72
- raise ValueError(
73
- "Can not currently generate version tolerant multiapi SDKs. "
74
- "We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
111
+ @property
112
+ def _low_level_or_version_tolerant(self) -> bool:
113
+ return self.low_level_client or self.version_tolerant
114
+
115
+ @property
116
+ def only_path_and_body_params_positional(self) -> bool:
117
+ return self.options.get(
118
+ "only-path-and-body-params-positional",
119
+ self._low_level_or_version_tolerant,
75
120
  )
76
121
 
77
- if options["client_side_validation"] and options["version_tolerant"]:
78
- raise ValueError(
79
- "Can not generate version tolerant with --client-side-validation. "
122
+ @property
123
+ def combine_operation_files(self) -> bool:
124
+ return self.options.get(
125
+ "combine-operation-files",
126
+ self.version_tolerant,
80
127
  )
81
128
 
82
- if not (options["azure_arm"] or options["version_tolerant"]):
83
- _LOGGER.warning(
84
- "You are generating with options that would not allow the SDK to be shipped as an official Azure SDK. "
85
- "Please read https://aka.ms/azsdk/dpcodegen for more details."
129
+ @property
130
+ def package_pprint_name(self) -> str:
131
+ return self.options.get("package-pprint-name") or _default_pprint(
132
+ str(self.package_name)
86
133
  )
87
134
 
135
+ @property
136
+ def default_optional_constants_to_none(self) -> bool:
137
+ return self.options.get(
138
+ "default-optional-constants-to-none",
139
+ self._low_level_or_version_tolerant,
140
+ )
88
141
 
89
- _LOGGER = logging.getLogger(__name__)
142
+ @property
143
+ def builders_visibility(self) -> str:
144
+ builders_visibility = self.options.get("builders-visibility")
145
+ if builders_visibility is None:
146
+ return "public" if self.low_level_client else "embedded"
147
+ return builders_visibility.lower()
148
+
149
+ @property
150
+ def head_as_boolean(self) -> bool:
151
+ head_as_boolean = self.options.get("head-as-boolean", True)
152
+ # Force some options in ARM MODE
153
+ return True if self.azure_arm else head_as_boolean
90
154
 
91
155
 
92
156
  class CodeGenerator(Plugin):
157
+ def __init__(self, *args, **kwargs: Any) -> None:
158
+ super().__init__(*args, **kwargs)
159
+ self.options_retriever = OptionsRetriever(self.options)
160
+
161
+ def _validate_code_model_options(self) -> None:
162
+ if self.options_retriever.builders_visibility not in [
163
+ "public",
164
+ "hidden",
165
+ "embedded",
166
+ ]:
167
+ raise ValueError(
168
+ "The value of --builders-visibility must be either 'public', 'hidden', "
169
+ "or 'embedded'"
170
+ )
171
+
172
+ if self.options_retriever.original_models_mode not in ["msrest", "dpg", "none"]:
173
+ raise ValueError(
174
+ "--models-mode can only be 'msrest', 'dpg' or 'none'. "
175
+ "Pass in 'msrest' if you want msrest models, or "
176
+ "'none' if you don't want any."
177
+ )
178
+
179
+ if (
180
+ not self.options_retriever.show_operations
181
+ and self.options_retriever.builders_visibility == "embedded"
182
+ ):
183
+ raise ValueError(
184
+ "Can not embed builders without operations. "
185
+ "Either set --show-operations to True, or change the value of --builders-visibility "
186
+ "to 'public' or 'hidden'."
187
+ )
188
+
189
+ if (
190
+ self.options_retriever.basic_setup_py
191
+ and not self.options_retriever.package_version
192
+ ):
193
+ raise ValueError("--basic-setup-py must be used with --package-version")
194
+
195
+ if (
196
+ self.options_retriever.package_mode
197
+ and not self.options_retriever.package_version
198
+ ):
199
+ raise ValueError("--package-mode must be used with --package-version")
200
+
201
+ if (
202
+ not self.options_retriever.show_operations
203
+ and self.options_retriever.combine_operation_files
204
+ ):
205
+ raise ValueError(
206
+ "Can not combine operation files if you are not showing operations. "
207
+ "If you want operation files, pass in flag --show-operations"
208
+ )
209
+
210
+ if self.options_retriever.package_mode:
211
+ if (
212
+ (
213
+ self.options_retriever.package_mode not in TYPESPEC_PACKAGE_MODE
214
+ and self.options_retriever.from_typespec
215
+ )
216
+ or (
217
+ self.options_retriever.package_mode not in VALID_PACKAGE_MODE
218
+ and not self.options_retriever.from_typespec
219
+ )
220
+ ) and not Path(self.options_retriever.package_mode).exists():
221
+ raise ValueError(
222
+ f"--package-mode can only be {' or '.join(TYPESPEC_PACKAGE_MODE)} or directory which contains template files" # pylint: disable=line-too-long
223
+ )
224
+
225
+ if self.options_retriever.multiapi and self.options_retriever.version_tolerant:
226
+ raise ValueError(
227
+ "Can not currently generate version tolerant multiapi SDKs. "
228
+ "We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
229
+ )
230
+
231
+ if (
232
+ self.options_retriever.client_side_validation
233
+ and self.options_retriever.version_tolerant
234
+ ):
235
+ raise ValueError(
236
+ "Can not generate version tolerant with --client-side-validation. "
237
+ )
238
+
239
+ if not (
240
+ self.options_retriever.azure_arm or self.options_retriever.version_tolerant
241
+ ):
242
+ _LOGGER.warning(
243
+ "You are generating with options that would not allow the SDK to be shipped as an official Azure SDK. "
244
+ "Please read https://aka.ms/azsdk/dpcodegen for more details."
245
+ )
246
+
247
+ if self.options_retriever.unbranded and self.options_retriever.tracing:
248
+ raise ValueError(
249
+ "Can not set --unbranded=true and --tracing=true at the same time."
250
+ )
251
+
93
252
  @staticmethod
94
253
  def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
95
254
  for client in yaml_data["clients"]:
@@ -117,85 +276,39 @@ class CodeGenerator(Plugin):
117
276
 
118
277
  def _build_code_model_options(self) -> Dict[str, Any]:
119
278
  """Build en options dict from the user input while running autorest."""
120
- azure_arm = self.options.get("azure-arm", False)
121
- license_header = self.options.get("header-text", DEFAULT_HEADER_TEXT)
122
- if license_header:
123
- license_header = license_header.replace("\n", "\n# ")
124
- license_header = (
125
- "# --------------------------------------------------------------------------\n# "
126
- + license_header
127
- )
128
- license_header += "\n# --------------------------------------------------------------------------"
129
-
130
- low_level_client = cast(bool, self.options.get("low-level-client", False))
131
- version_tolerant = cast(bool, self.options.get("version-tolerant", True))
132
- show_operations = self.options.get("show-operations", not low_level_client)
133
- models_mode_default = (
134
- "none" if low_level_client or version_tolerant else "msrest"
135
- )
136
- if self.options.get("cadl_file") is not None:
137
- models_mode_default = "dpg"
138
-
139
- package_name = self.options.get("package-name")
140
- options: Dict[str, Any] = {
141
- "azure_arm": azure_arm,
142
- "head_as_boolean": self.options.get("head-as-boolean", True),
143
- "license_header": license_header,
144
- "keep_version_file": self.options.get("keep-version-file", False),
145
- "no_async": self.options.get("no-async", False),
146
- "no_namespace_folders": self.options.get("no-namespace-folders", False),
147
- "basic_setup_py": self.options.get("basic-setup-py", False),
148
- "package_name": package_name,
149
- "package_version": self.options.get("package-version"),
150
- "client_side_validation": self.options.get("client-side-validation", False),
151
- "tracing": self.options.get("tracing", show_operations),
152
- "multiapi": self.options.get("multiapi", False),
153
- "polymorphic_examples": self.options.get("polymorphic-examples", 5),
154
- "models_mode": self.options.get("models-mode", models_mode_default).lower(),
155
- "builders_visibility": self.options.get("builders-visibility"),
156
- "show_operations": show_operations,
157
- "show_send_request": self.options.get(
158
- "show-send-request", low_level_client or version_tolerant
159
- ),
160
- "only_path_and_body_params_positional": self.options.get(
161
- "only-path-and-body-params-positional",
162
- low_level_client or version_tolerant,
163
- ),
164
- "version_tolerant": version_tolerant,
165
- "low_level_client": low_level_client,
166
- "combine_operation_files": self.options.get(
167
- "combine-operation-files", version_tolerant
168
- ),
169
- "package_mode": self.options.get("package-mode"),
170
- "package_pprint_name": self.options.get("package-pprint-name")
171
- or _default_pprint(str(package_name)),
172
- "package_configuration": self.options.get("package-configuration"),
173
- "default_optional_constants_to_none": self.options.get(
174
- "default-optional-constants-to-none",
175
- low_level_client or version_tolerant,
176
- ),
177
- "generate_sample": self.options.get("generate-sample", False),
178
- "default_api_version": self.options.get("default-api-version"),
179
- "from_typespec": self.options.get("from-typespec", False),
180
- }
181
-
182
- if options["builders_visibility"] is None:
183
- options["builders_visibility"] = (
184
- "public" if low_level_client else "embedded"
185
- )
186
- else:
187
- options["builders_visibility"] = options["builders_visibility"].lower()
188
-
189
- _validate_code_model_options(options)
190
-
191
- if options["models_mode"] == "none":
192
- # switch to falsy value for easier code writing
193
- options["models_mode"] = False
194
-
195
- # Force some options in ARM MODE:
196
- if azure_arm:
197
- options["head_as_boolean"] = True
198
- return options
279
+ flags = [
280
+ "azure_arm",
281
+ "head_as_boolean",
282
+ "license_header",
283
+ "keep_version_file",
284
+ "no_async",
285
+ "no_namespace_folders",
286
+ "basic_setup_py",
287
+ "package_name",
288
+ "package_version",
289
+ "client_side_validation",
290
+ "tracing",
291
+ "multiapi",
292
+ "polymorphic_examples",
293
+ "models_mode",
294
+ "builders_visibility",
295
+ "show_operations",
296
+ "show_send_request",
297
+ "only_path_and_body_params_positional",
298
+ "version_tolerant",
299
+ "low_level_client",
300
+ "combine_operation_files",
301
+ "package_mode",
302
+ "package_pprint_name",
303
+ "package_configuration",
304
+ "default_optional_constants_to_none",
305
+ "generate_sample",
306
+ "default_api_version",
307
+ "from_typespec",
308
+ "unbranded",
309
+ "company_name",
310
+ ]
311
+ return {f: getattr(self.options_retriever, f) for f in flags}
199
312
 
200
313
  def get_yaml(self) -> Dict[str, Any]:
201
314
  # cadl file doesn't have to be relative to output folder
@@ -207,14 +320,18 @@ class CodeGenerator(Plugin):
207
320
 
208
321
  def process(self) -> bool:
209
322
  # List the input file, should be only one
210
-
323
+ self._validate_code_model_options()
211
324
  options = self._build_code_model_options()
212
325
  yaml_data = self.get_yaml()
213
326
 
214
- if options["azure_arm"]:
327
+ if self.options_retriever.azure_arm:
215
328
  self.remove_cloud_errors(yaml_data)
216
329
 
217
330
  code_model = CodeModel(yaml_data=yaml_data, options=options)
331
+ if self.options_retriever.unbranded and any(
332
+ client.lro_operations for client in code_model.clients
333
+ ):
334
+ raise ValueError("Do not support LRO when --unbranded=true")
218
335
  serializer = self.get_serializer(code_model)
219
336
  serializer.serialize()
220
337
 
@@ -323,7 +440,9 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
323
440
 
324
441
  if __name__ == "__main__":
325
442
  # CADL pipeline will call this
326
- args, unknown_args = parse_args()
443
+ parsed_args, unknown_args = parse_args()
327
444
  CodeGenerator(
328
- output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
445
+ output_folder=parsed_args.output_folder,
446
+ cadl_file=parsed_args.cadl_file,
447
+ **unknown_args,
329
448
  ).process()
@@ -5,9 +5,9 @@
5
5
  # --------------------------------------------------------------------------
6
6
 
7
7
  DEFAULT_HEADER_TEXT = (
8
- "Copyright (c) Microsoft Corporation. All rights reserved.\n"
8
+ "Copyright (c) {company_name} Corporation. All rights reserved.\n"
9
9
  "Licensed under the MIT License. See License.txt in the project root for license information.\n"
10
- "Code generated by Microsoft (R) Python Code Generator.\n"
10
+ "Code generated by {company_name} (R) Python Code Generator.\n"
11
11
  "Changes may cause incorrect behavior and will be lost if the code is regenerated."
12
12
  )
13
13
 
@@ -28,7 +28,7 @@ from .primitive_types import (
28
28
  BooleanType,
29
29
  AnyObjectType,
30
30
  UnixTimeType,
31
- AzureCoreType,
31
+ SdkCoreType,
32
32
  )
33
33
  from .enum_type import EnumType, EnumValue
34
34
  from .base import BaseType
@@ -67,15 +67,15 @@ from .request_builder_parameter import (
67
67
  )
68
68
  from .credential_types import (
69
69
  TokenCredentialType,
70
- AzureKeyCredentialType,
70
+ KeyCredentialType,
71
71
  ARMChallengeAuthenticationPolicyType,
72
72
  BearerTokenCredentialPolicyType,
73
- AzureKeyCredentialPolicyType,
73
+ KeyCredentialPolicyType,
74
74
  CredentialType,
75
75
  )
76
76
 
77
77
  __all__ = [
78
- "AzureKeyCredentialPolicyType",
78
+ "KeyCredentialPolicyType",
79
79
  "AnyType",
80
80
  "BaseModel",
81
81
  "BaseType",
@@ -140,14 +140,14 @@ TYPE_TO_OBJECT = {
140
140
  "boolean": BooleanType,
141
141
  "combined": CombinedType,
142
142
  "OAuth2": TokenCredentialType,
143
- "Key": AzureKeyCredentialType,
143
+ "Key": KeyCredentialType,
144
144
  "ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
145
145
  "BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
146
- "AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
146
+ "KeyCredentialPolicy": KeyCredentialPolicyType,
147
147
  "any-object": AnyObjectType,
148
148
  "unixtime": UnixTimeType,
149
149
  "credential": StringType,
150
- "azurecore": AzureCoreType,
150
+ "sdkcore": SdkCoreType,
151
151
  }
152
152
  _LOGGER = logging.getLogger(__name__)
153
153
 
@@ -31,6 +31,9 @@ class BaseModel:
31
31
  def __repr__(self):
32
32
  return f"<{self.__class__.__name__}>"
33
33
 
34
+ def init_file_import(self) -> FileImport:
35
+ return FileImport(self.code_model)
36
+
34
37
 
35
38
  class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
36
39
  """This is the base class for all types.
@@ -53,14 +56,13 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
53
56
  return cls(yaml_data=yaml_data, code_model=code_model)
54
57
 
55
58
  def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
56
- return FileImport()
59
+ return self.init_file_import()
57
60
 
58
61
  def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
59
62
  return self.imports(**kwargs)
60
63
 
61
- @staticmethod
62
- def imports_for_sample() -> FileImport:
63
- return FileImport()
64
+ def imports_for_sample(self) -> FileImport:
65
+ return self.init_file_import()
64
66
 
65
67
  @staticmethod
66
68
  def serialize_sample_value(value: Any) -> str: