@autorest/python 6.9.4 → 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 (47) hide show
  1. package/autorest/_utils.py +2 -2
  2. package/autorest/codegen/__init__.py +250 -138
  3. package/autorest/codegen/_utils.py +2 -2
  4. package/autorest/codegen/models/__init__.py +7 -7
  5. package/autorest/codegen/models/base.py +5 -2
  6. package/autorest/codegen/models/client.py +31 -24
  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 +71 -3
  13. package/autorest/codegen/models/list_type.py +1 -1
  14. package/autorest/codegen/models/lro_operation.py +2 -2
  15. package/autorest/codegen/models/model_type.py +1 -1
  16. package/autorest/codegen/models/operation.py +25 -17
  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 +17 -13
  21. package/autorest/codegen/models/property.py +1 -1
  22. package/autorest/codegen/models/request_builder.py +8 -6
  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 +33 -19
  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 +19 -23
  30. package/autorest/codegen/serializers/model_serializer.py +5 -9
  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 +4 -4
  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/m4reformatter/__init__.py +1 -1
  44. package/autorest/multiapi/models/imports.py +1 -1
  45. package/autorest/multiapi/serializers/__init__.py +4 -1
  46. package/autorest/preprocess/__init__.py +1 -9
  47. package/package.json +1 -1
@@ -121,7 +121,7 @@ JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
121
121
 
122
122
 
123
123
  def build_policies(
124
- is_arm: bool, async_mode: bool, unbranded: bool = False
124
+ is_arm: bool, async_mode: bool, unbranded: bool = False, tracing: bool = True
125
125
  ) -> List[str]:
126
126
  if not unbranded:
127
127
  # for Azure
@@ -140,7 +140,7 @@ def build_policies(
140
140
  "self._config.authentication_policy",
141
141
  "self._config.custom_hook_policy",
142
142
  "self._config.logging_policy",
143
- "policies.DistributedTracingPolicy(**kwargs)",
143
+ "policies.DistributedTracingPolicy(**kwargs)" if tracing else None,
144
144
  "policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None",
145
145
  "self._config.http_logging_policy",
146
146
  ]
@@ -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,81 +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
36
72
 
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'."
73
+ @property
74
+ def show_operations(self) -> bool:
75
+ return self.options.get("show-operations", not self.low_level_client)
76
+
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
+ )
110
+
111
+ @property
112
+ def _low_level_or_version_tolerant(self) -> bool:
113
+ return self.low_level_client or self.version_tolerant
70
114
 
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."
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
 
88
- if options["unbranded"] and options["tracing"]:
89
- raise ValueError(
90
- "Can not set --unbranded=true and --tracing=true at the same time."
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,
91
140
  )
92
141
 
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()
93
148
 
94
- _LOGGER = logging.getLogger(__name__)
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
95
154
 
96
155
 
97
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
+
98
252
  @staticmethod
99
253
  def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
100
254
  for client in yaml_data["clients"]:
@@ -122,87 +276,39 @@ class CodeGenerator(Plugin):
122
276
 
123
277
  def _build_code_model_options(self) -> Dict[str, Any]:
124
278
  """Build en options dict from the user input while running autorest."""
125
- azure_arm = self.options.get("azure-arm", False)
126
- license_header = self.options.get("header-text", DEFAULT_HEADER_TEXT)
127
- if license_header:
128
- license_header = license_header.replace("\n", "\n# ")
129
- license_header = (
130
- "# --------------------------------------------------------------------------\n# "
131
- + license_header
132
- )
133
- license_header += "\n# --------------------------------------------------------------------------"
134
-
135
- low_level_client = cast(bool, self.options.get("low-level-client", False))
136
- version_tolerant = cast(bool, self.options.get("version-tolerant", True))
137
- show_operations = self.options.get("show-operations", not low_level_client)
138
- models_mode_default = (
139
- "none" if low_level_client or version_tolerant else "msrest"
140
- )
141
- if self.options.get("cadl_file") is not None:
142
- models_mode_default = "dpg"
143
-
144
- package_name = self.options.get("package-name")
145
- unbranded = self.options.get("unbranded", False)
146
- options: Dict[str, Any] = {
147
- "azure_arm": azure_arm,
148
- "head_as_boolean": self.options.get("head-as-boolean", True),
149
- "license_header": license_header,
150
- "keep_version_file": self.options.get("keep-version-file", False),
151
- "no_async": self.options.get("no-async", False),
152
- "no_namespace_folders": self.options.get("no-namespace-folders", False),
153
- "basic_setup_py": self.options.get("basic-setup-py", False),
154
- "package_name": package_name,
155
- "package_version": self.options.get("package-version"),
156
- "client_side_validation": self.options.get("client-side-validation", False),
157
- "tracing": self.options.get("tracing", show_operations and not unbranded),
158
- "multiapi": self.options.get("multiapi", False),
159
- "polymorphic_examples": self.options.get("polymorphic-examples", 5),
160
- "models_mode": self.options.get("models-mode", models_mode_default).lower(),
161
- "builders_visibility": self.options.get("builders-visibility"),
162
- "show_operations": show_operations,
163
- "show_send_request": self.options.get(
164
- "show-send-request", low_level_client or version_tolerant
165
- ),
166
- "only_path_and_body_params_positional": self.options.get(
167
- "only-path-and-body-params-positional",
168
- low_level_client or version_tolerant,
169
- ),
170
- "version_tolerant": version_tolerant,
171
- "low_level_client": low_level_client,
172
- "combine_operation_files": self.options.get(
173
- "combine-operation-files", version_tolerant
174
- ),
175
- "package_mode": self.options.get("package-mode"),
176
- "package_pprint_name": self.options.get("package-pprint-name")
177
- or _default_pprint(str(package_name)),
178
- "package_configuration": self.options.get("package-configuration"),
179
- "default_optional_constants_to_none": self.options.get(
180
- "default-optional-constants-to-none",
181
- low_level_client or version_tolerant,
182
- ),
183
- "generate_sample": self.options.get("generate-sample", False),
184
- "default_api_version": self.options.get("default-api-version"),
185
- "from_typespec": self.options.get("from-typespec", False),
186
- "unbranded": unbranded,
187
- }
188
-
189
- if options["builders_visibility"] is None:
190
- options["builders_visibility"] = (
191
- "public" if low_level_client else "embedded"
192
- )
193
- else:
194
- options["builders_visibility"] = options["builders_visibility"].lower()
195
-
196
- _validate_code_model_options(options)
197
-
198
- if options["models_mode"] == "none":
199
- # switch to falsy value for easier code writing
200
- options["models_mode"] = False
201
-
202
- # Force some options in ARM MODE:
203
- if azure_arm:
204
- options["head_as_boolean"] = True
205
- 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}
206
312
 
207
313
  def get_yaml(self) -> Dict[str, Any]:
208
314
  # cadl file doesn't have to be relative to output folder
@@ -214,14 +320,18 @@ class CodeGenerator(Plugin):
214
320
 
215
321
  def process(self) -> bool:
216
322
  # List the input file, should be only one
217
-
323
+ self._validate_code_model_options()
218
324
  options = self._build_code_model_options()
219
325
  yaml_data = self.get_yaml()
220
326
 
221
- if options["azure_arm"]:
327
+ if self.options_retriever.azure_arm:
222
328
  self.remove_cloud_errors(yaml_data)
223
329
 
224
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")
225
335
  serializer = self.get_serializer(code_model)
226
336
  serializer.serialize()
227
337
 
@@ -330,7 +440,9 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
330
440
 
331
441
  if __name__ == "__main__":
332
442
  # CADL pipeline will call this
333
- args, unknown_args = parse_args()
443
+ parsed_args, unknown_args = parse_args()
334
444
  CodeGenerator(
335
- 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,
336
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,13 +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(self.code_model)
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
64
  def imports_for_sample(self) -> FileImport:
62
- return FileImport(self.code_model)
65
+ return self.init_file_import()
63
66
 
64
67
  @staticmethod
65
68
  def serialize_sample_value(value: Any) -> str: