@autorest/python 5.14.0 → 5.17.0

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 (120) hide show
  1. package/ChangeLog.md +91 -2
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +2 -3
  4. package/autorest/black/__init__.py +12 -5
  5. package/autorest/codegen/__init__.py +130 -179
  6. package/autorest/codegen/models/__init__.py +122 -78
  7. package/autorest/codegen/models/base_builder.py +70 -72
  8. package/autorest/codegen/models/base_model.py +7 -5
  9. package/autorest/codegen/models/{base_schema.py → base_type.py} +62 -49
  10. package/autorest/codegen/models/client.py +195 -36
  11. package/autorest/codegen/models/code_model.py +165 -299
  12. package/autorest/codegen/models/combined_type.py +107 -0
  13. package/autorest/codegen/models/constant_type.py +122 -0
  14. package/autorest/codegen/models/credential_types.py +224 -0
  15. package/autorest/codegen/models/dictionary_type.py +116 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +95 -41
  18. package/autorest/codegen/models/list_type.py +134 -0
  19. package/autorest/codegen/models/lro_operation.py +90 -133
  20. package/autorest/codegen/models/lro_paging_operation.py +28 -12
  21. package/autorest/codegen/models/model_type.py +239 -0
  22. package/autorest/codegen/models/operation.py +415 -241
  23. package/autorest/codegen/models/operation_group.py +82 -88
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +307 -322
  26. package/autorest/codegen/models/parameter_list.py +366 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +122 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -79
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +17 -1
  33. package/autorest/codegen/serializers/__init__.py +242 -118
  34. package/autorest/codegen/serializers/builder_serializer.py +863 -1027
  35. package/autorest/codegen/serializers/client_serializer.py +148 -82
  36. package/autorest/codegen/serializers/general_serializer.py +44 -47
  37. package/autorest/codegen/serializers/import_serializer.py +96 -31
  38. package/autorest/codegen/serializers/metadata_serializer.py +39 -79
  39. package/autorest/codegen/serializers/model_base_serializer.py +65 -29
  40. package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
  41. package/autorest/codegen/serializers/model_init_serializer.py +4 -2
  42. package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
  43. package/autorest/codegen/serializers/operation_groups_serializer.py +21 -18
  44. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  45. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  46. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -103
  49. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  50. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  51. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  52. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  53. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -2
  54. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  55. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  56. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  58. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  59. package/autorest/codegen/templates/model.py.jinja2 +23 -29
  60. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  61. package/autorest/codegen/templates/model_init.py.jinja2 +9 -8
  62. package/autorest/codegen/templates/operation.py.jinja2 +10 -15
  63. package/autorest/codegen/templates/operation_group.py.jinja2 +14 -13
  64. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  65. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  66. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  67. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  68. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  69. package/autorest/codegen/templates/request_builder.py.jinja2 +20 -13
  70. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  71. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  72. package/autorest/jsonrpc/__init__.py +7 -12
  73. package/autorest/jsonrpc/localapi.py +4 -3
  74. package/autorest/jsonrpc/server.py +28 -9
  75. package/autorest/jsonrpc/stdstream.py +13 -6
  76. package/autorest/m2r/__init__.py +5 -8
  77. package/autorest/m4reformatter/__init__.py +1108 -0
  78. package/autorest/multiapi/__init__.py +24 -14
  79. package/autorest/multiapi/models/client.py +21 -11
  80. package/autorest/multiapi/models/code_model.py +23 -10
  81. package/autorest/multiapi/models/config.py +4 -1
  82. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  83. package/autorest/multiapi/models/global_parameter.py +2 -1
  84. package/autorest/multiapi/models/global_parameters.py +14 -8
  85. package/autorest/multiapi/models/imports.py +35 -18
  86. package/autorest/multiapi/models/mixin_operation.py +5 -5
  87. package/autorest/multiapi/models/operation_group.py +2 -1
  88. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  89. package/autorest/multiapi/serializers/__init__.py +20 -25
  90. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  91. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  92. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  93. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  94. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  95. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  96. package/autorest/multiapi/utils.py +3 -3
  97. package/autorest/postprocess/__init__.py +202 -0
  98. package/autorest/postprocess/get_all.py +19 -0
  99. package/autorest/postprocess/venvtools.py +73 -0
  100. package/autorest/preprocess/__init__.py +209 -0
  101. package/autorest/preprocess/helpers.py +54 -0
  102. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  103. package/package.json +3 -3
  104. package/run-python3.js +2 -3
  105. package/venvtools.py +1 -1
  106. package/autorest/codegen/models/constant_schema.py +0 -97
  107. package/autorest/codegen/models/credential_schema.py +0 -90
  108. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  109. package/autorest/codegen/models/dictionary_schema.py +0 -103
  110. package/autorest/codegen/models/enum_schema.py +0 -246
  111. package/autorest/codegen/models/list_schema.py +0 -113
  112. package/autorest/codegen/models/object_schema.py +0 -249
  113. package/autorest/codegen/models/primitive_schemas.py +0 -476
  114. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  115. package/autorest/codegen/models/rest.py +0 -42
  116. package/autorest/codegen/models/schema_request.py +0 -45
  117. package/autorest/codegen/models/schema_response.py +0 -123
  118. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  119. package/autorest/namer/__init__.py +0 -25
  120. package/autorest/namer/name_converter.py +0 -412
@@ -5,39 +5,35 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
7
  import sys
8
- from typing import Dict, Any, Set, Union, List, Type
8
+ from typing import Dict, Any, Union, cast
9
9
  from pathlib import Path
10
10
  import yaml
11
11
 
12
+
12
13
  from .. import Plugin
14
+ from .models.client import Client, Config
13
15
  from .models.code_model import CodeModel
14
- from .models import build_schema
16
+ from .models import build_type
17
+ from .models.request_builder import get_request_builder
15
18
  from .models.operation_group import OperationGroup
16
- from .models.parameter import Parameter
17
- from .models.parameter_list import GlobalParameterList
18
- from .models.rest import Rest
19
19
  from .serializers import JinjaSerializer
20
- from .models.credential_schema_policy import CredentialSchemaPolicy, get_credential_schema_policy_type
21
- from .models.credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
20
+
22
21
 
23
22
  def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -> None:
24
23
  # Create operations
25
24
  if code_model.options["show_operations"] and yaml_data.get("operationGroups"):
26
25
  code_model.operation_groups = [
27
- OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"]
26
+ OperationGroup.from_yaml(op_group, code_model)
27
+ for op_group in yaml_data["operationGroups"]
28
28
  ]
29
- if yaml_data.get("schemas"):
30
- code_model.add_inheritance_to_models()
29
+ if yaml_data.get("types"):
31
30
  if code_model.options["models_mode"]:
32
- code_model.sort_schemas()
31
+ code_model.sort_model_types()
33
32
 
34
33
  if code_model.options["show_operations"]:
35
- code_model.add_schema_link_to_operation()
36
- code_model.generate_single_parameter_from_multiple_content_types_operation()
37
- code_model.link_operation_to_request_builder()
38
34
  # LRO operation
39
35
  code_model.format_lro_operations()
40
- code_model.remove_next_operation()
36
+
41
37
 
42
38
  def _validate_code_model_options(options: Dict[str, Any]) -> None:
43
39
 
@@ -81,7 +77,10 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
81
77
  )
82
78
 
83
79
  if options["package_mode"]:
84
- if options["package_mode"] not in ("mgmtplane", "dataplane") and not Path(options["package_mode"]).exists():
80
+ if (
81
+ options["package_mode"] not in ("mgmtplane", "dataplane")
82
+ and not Path(options["package_mode"]).exists()
83
+ ):
85
84
  raise ValueError(
86
85
  "--package-mode can only be 'mgmtplane' or 'dataplane' or directory which contains template files"
87
86
  )
@@ -92,7 +91,16 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
92
91
  "Please remove --reformat-next-link from your call for version tolerant generations."
93
92
  )
94
93
 
94
+ if options["multiapi"] and options["version_tolerant"]:
95
+ raise ValueError(
96
+ "Can not currently generate version tolerant multiapi SDKs. "
97
+ "We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
98
+ )
99
+
100
+
95
101
  _LOGGER = logging.getLogger(__name__)
102
+
103
+
96
104
  class CodeGenerator(Plugin):
97
105
  @staticmethod
98
106
  def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
@@ -103,7 +111,11 @@ class CodeGenerator(Plugin):
103
111
  i = 0
104
112
  while i < len(operation["exceptions"]):
105
113
  exception = operation["exceptions"][i]
106
- if exception.get("schema") and exception["schema"]["language"]["default"]["name"] == "CloudError":
114
+ if (
115
+ exception.get("schema")
116
+ and exception["schema"]["language"]["default"]["name"]
117
+ == "CloudError"
118
+ ):
107
119
  del operation["exceptions"][i]
108
120
  i -= 1
109
121
  i += 1
@@ -114,217 +126,144 @@ class CodeGenerator(Plugin):
114
126
  del yaml_data["schemas"]["objects"][i]
115
127
  break
116
128
 
117
- @staticmethod
118
- def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[int]:
119
- exceptions_set = set()
120
- for group in yaml_data:
121
- for operation in group["operations"]:
122
- if not operation.get("exceptions"):
123
- continue
124
- for exception in operation["exceptions"]:
125
- if not exception.get("schema"):
126
- continue
127
- exceptions_set.add(id(exception["schema"]))
128
- return exceptions_set
129
-
130
129
  @staticmethod
131
130
  def _build_package_dependency() -> Dict[str, str]:
132
131
  return {
133
132
  "dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.0",
134
- "dependency_azure_core": "azure-core<2.0.0,>=1.20.1",
133
+ "dependency_azure_core": "azure-core<2.0.0,>=1.23.0",
135
134
  "dependency_msrest": "msrest>=0.6.21",
136
135
  }
137
136
 
138
- def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]) -> CodeModel:
137
+ def _create_code_model(
138
+ self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]
139
+ ) -> CodeModel:
139
140
  # Create a code model
140
141
 
141
- code_model = CodeModel(options=options)
142
- if code_model.options['credential']:
143
- self._handle_default_authentication_policy(code_model)
144
- code_model.module_name = yaml_data["info"]["python_title"]
145
- code_model.class_name = yaml_data["info"]["pascal_case_title"]
146
- code_model.description = (
147
- yaml_data["info"]["description"] if yaml_data["info"].get("description") else ""
148
- )
149
-
150
- # Global parameters
151
- code_model.global_parameters = GlobalParameterList(
152
- code_model,
153
- [Parameter.from_yaml(param, code_model=code_model) for param in yaml_data.get("globalParameters", [])],
154
- )
155
- code_model.global_parameters.code_model = code_model
156
-
157
- # Custom URL
158
- code_model.setup_client_input_parameters(yaml_data)
142
+ code_model = CodeModel(yaml_data, options=options)
143
+ for type_yaml in yaml_data.get("types", []):
144
+ build_type(yaml_data=type_yaml, code_model=code_model)
159
145
 
160
- # Get my namespace
161
- namespace = self._autorestapi.get_value("namespace")
162
- _LOGGER.debug("Namespace parameter was %s", namespace)
163
- if not namespace:
164
- namespace = yaml_data["info"]["python_title"]
165
- code_model.namespace = namespace
146
+ code_model.client = Client.from_yaml(yaml_data["client"], code_model)
147
+ code_model.config = Config.from_yaml(yaml_data["client"], code_model)
166
148
 
167
- code_model.rest = Rest.from_yaml(yaml_data, code_model=code_model)
168
- if yaml_data.get("schemas"):
169
- exceptions_set = CodeGenerator._build_exceptions_set(yaml_data=yaml_data["operationGroups"])
170
-
171
- for type_list in yaml_data["schemas"].values():
172
- for schema in type_list:
173
- build_schema(yaml_data=schema, exceptions_set=exceptions_set, code_model=code_model)
174
- code_model.add_schema_link_to_request_builder()
175
- code_model.add_schema_link_to_global_parameters()
149
+ # Build request builders
150
+ if yaml_data.get("operationGroups"):
151
+ for og_group in yaml_data["operationGroups"]:
152
+ for operation_yaml in og_group["operations"]:
153
+ request_builder = get_request_builder(
154
+ operation_yaml, code_model=code_model
155
+ )
156
+ if request_builder.overloads:
157
+ code_model.request_builders.extend(request_builder.overloads) # type: ignore
158
+ code_model.request_builders.append(request_builder)
159
+ if operation_yaml.get("nextOperation"):
160
+ # i am a paging operation and i have a next operation. Make sure to include my next operation
161
+ code_model.request_builders.append(
162
+ get_request_builder(
163
+ operation_yaml["nextOperation"], code_model=code_model
164
+ )
165
+ )
176
166
 
177
167
  _build_convenience_layer(yaml_data=yaml_data, code_model=code_model)
178
-
179
- if options["credential"]:
180
- code_model.global_parameters.add_credential_global_parameter()
181
-
182
168
  code_model.package_dependency = self._build_package_dependency()
183
169
  return code_model
184
170
 
185
- def _get_credential_scopes(self, credential):
186
- credential_scopes_temp = self._autorestapi.get_value("credential-scopes")
187
- credential_scopes = credential_scopes_temp.split(",") if credential_scopes_temp else None
188
- if credential_scopes and not credential:
189
- raise ValueError("--credential-scopes must be used with the --add-credential flag")
190
-
191
- # check to see if user just passes in --credential-scopes with no value
192
- if self._autorestapi.get_boolean_value("credential-scopes", False) and not credential_scopes:
193
- raise ValueError(
194
- "--credential-scopes takes a list of scopes in comma separated format. "
195
- "For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
196
- )
197
- return credential_scopes
198
-
199
- def _initialize_credential_schema_policy(
200
- self, code_model: CodeModel, credential_schema_policy: Type[CredentialSchemaPolicy]
201
- ) -> CredentialSchemaPolicy:
202
- credential_scopes = self._get_credential_scopes(code_model.options['credential'])
203
- credential_key_header_name = self._autorestapi.get_value('credential-key-header-name')
204
- azure_arm = code_model.options['azure_arm']
205
- credential = code_model.options['credential']
206
-
207
- if hasattr(credential_schema_policy, "credential_scopes"):
208
- if not credential_scopes:
209
- if azure_arm:
210
- credential_scopes = ["https://management.azure.com/.default"]
211
- elif credential:
212
- # If add-credential is specified, we still want to add a credential_scopes variable.
213
- # Will make it an empty list so we can differentiate between this case and None
214
- _LOGGER.warning(
215
- "You have default credential policy %s "
216
- "but not the --credential-scopes flag set while generating non-management plane code. "
217
- "This is not recommend because it forces the customer to pass credential scopes "
218
- "through kwargs if they want to authenticate.",
219
- credential_schema_policy.name()
220
- )
221
- credential_scopes = []
222
-
223
- if credential_key_header_name:
224
- raise ValueError(
225
- "You have passed in a credential key header name with default credential policy type "
226
- f"{credential_schema_policy.name()}. This is not allowed, since credential key header "
227
- "name is tied with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you "
228
- "pass in --credential-scopes."
229
- )
230
- return credential_schema_policy(
231
- credential=TokenCredentialSchema(async_mode=False),
232
- credential_scopes=credential_scopes,
233
- )
234
- # currently the only other credential policy is AzureKeyCredentialPolicy
235
- if credential_scopes:
236
- raise ValueError(
237
- "You have passed in credential scopes with default credential policy type "
238
- "AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with "
239
- f"{code_model.default_authentication_policy.name()}. Instead, with this policy you must pass in "
240
- "--credential-key-header-name."
241
- )
242
- if not credential_key_header_name:
243
- credential_key_header_name = "api-key"
244
- _LOGGER.info(
245
- "Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'"
246
- )
247
- return credential_schema_policy(
248
- credential=AzureKeyCredentialSchema(),
249
- credential_key_header_name=credential_key_header_name,
250
- )
251
-
252
- def _handle_default_authentication_policy(self, code_model: CodeModel):
253
- credential_schema_policy_name = (
254
- self._autorestapi.get_value("credential-default-policy-type") or
255
- code_model.default_authentication_policy.name()
256
- )
257
- credential_schema_policy_type = get_credential_schema_policy_type(credential_schema_policy_name)
258
- credential_schema_policy = self._initialize_credential_schema_policy(
259
- code_model, credential_schema_policy_type
260
- )
261
- code_model.credential_schema_policy = credential_schema_policy
262
-
263
171
  def _build_code_model_options(self) -> Dict[str, Any]:
264
- """Build en options dict from the user input while running autorest.
265
- """
172
+ """Build en options dict from the user input while running autorest."""
266
173
  azure_arm = self._autorestapi.get_boolean_value("azure-arm", False)
267
- credential = (
268
- self._autorestapi.get_boolean_value("add-credentials", False) or
269
- self._autorestapi.get_boolean_value("add-credential", False)
270
- )
271
-
272
174
  license_header = self._autorestapi.get_value("header-text")
273
175
  if license_header:
274
176
  license_header = license_header.replace("\n", "\n# ")
275
177
  license_header = (
276
- "# --------------------------------------------------------------------------\n# " + license_header
178
+ "# --------------------------------------------------------------------------\n# "
179
+ + license_header
277
180
  )
278
181
  license_header += "\n# --------------------------------------------------------------------------"
279
182
 
280
- low_level_client = self._autorestapi.get_boolean_value("low-level-client", False)
281
- version_tolerant = self._autorestapi.get_boolean_value("version-tolerant", False)
282
- show_operations = self._autorestapi.get_boolean_value("show-operations", not low_level_client)
283
- models_mode_default = "none" if low_level_client or version_tolerant else "msrest"
284
- python3_only = self._autorestapi.get_boolean_value("python3-only", low_level_client or version_tolerant)
183
+ low_level_client = cast(
184
+ bool, self._autorestapi.get_boolean_value("low-level-client", False)
185
+ )
186
+ version_tolerant = cast(
187
+ bool, self._autorestapi.get_boolean_value("version-tolerant", False)
188
+ )
189
+ show_operations = self._autorestapi.get_boolean_value(
190
+ "show-operations", not low_level_client
191
+ )
192
+ models_mode_default = (
193
+ "none" if low_level_client or version_tolerant else "msrest"
194
+ )
195
+ python3_only = cast(
196
+ bool,
197
+ self._autorestapi.get_boolean_value(
198
+ "python3-only", low_level_client or version_tolerant
199
+ ),
200
+ )
285
201
 
286
202
  options: Dict[str, Any] = {
287
203
  "azure_arm": azure_arm,
288
- "credential": credential,
289
- "head_as_boolean": self._autorestapi.get_boolean_value("head-as-boolean", False),
204
+ "head_as_boolean": self._autorestapi.get_boolean_value(
205
+ "head-as-boolean", False
206
+ ),
290
207
  "license_header": license_header,
291
- "keep_version_file": self._autorestapi.get_boolean_value("keep-version-file", False),
208
+ "keep_version_file": self._autorestapi.get_boolean_value(
209
+ "keep-version-file", False
210
+ ),
292
211
  "no_async": self._autorestapi.get_boolean_value("no-async", False),
293
- "no_namespace_folders": self._autorestapi.get_boolean_value("no-namespace-folders", False),
294
- "basic_setup_py": self._autorestapi.get_boolean_value("basic-setup-py", False),
212
+ "no_namespace_folders": self._autorestapi.get_boolean_value(
213
+ "no-namespace-folders", False
214
+ ),
215
+ "basic_setup_py": self._autorestapi.get_boolean_value(
216
+ "basic-setup-py", False
217
+ ),
295
218
  "package_name": self._autorestapi.get_value("package-name"),
296
219
  "package_version": self._autorestapi.get_value("package-version"),
297
- "client_side_validation": self._autorestapi.get_boolean_value("client-side-validation", False),
220
+ "client_side_validation": self._autorestapi.get_boolean_value(
221
+ "client-side-validation", False
222
+ ),
298
223
  "tracing": self._autorestapi.get_boolean_value("trace", show_operations),
299
224
  "multiapi": self._autorestapi.get_boolean_value("multiapi", False),
300
- "polymorphic_examples": self._autorestapi.get_value("polymorphic-examples") or 5,
301
- "models_mode": (self._autorestapi.get_value("models-mode") or models_mode_default).lower(),
225
+ "polymorphic_examples": self._autorestapi.get_value("polymorphic-examples")
226
+ or 5,
227
+ "models_mode": (
228
+ self._autorestapi.get_value("models-mode") or models_mode_default
229
+ ).lower(),
302
230
  "builders_visibility": self._autorestapi.get_value("builders-visibility"),
303
231
  "show_operations": show_operations,
304
232
  "show_send_request": self._autorestapi.get_boolean_value(
305
233
  "show-send-request", low_level_client or version_tolerant
306
234
  ),
307
235
  "only_path_and_body_params_positional": self._autorestapi.get_boolean_value(
308
- "only-path-and-body-params-positional", low_level_client or version_tolerant
236
+ "only-path-and-body-params-positional",
237
+ low_level_client or version_tolerant,
309
238
  ),
310
239
  "add_python3_operation_files": self._autorestapi.get_boolean_value(
311
- "add-python3-operation-files", python3_only and not low_level_client
240
+ "add-python3-operation-files",
241
+ python3_only and not (low_level_client or version_tolerant),
312
242
  ),
313
243
  "version_tolerant": version_tolerant,
314
244
  "low_level_client": low_level_client,
315
- "combine_operation_files": self._autorestapi.get_boolean_value("combine-operation-files", version_tolerant),
245
+ "combine_operation_files": self._autorestapi.get_boolean_value(
246
+ "combine-operation-files", version_tolerant
247
+ ),
316
248
  "python3_only": python3_only,
317
249
  "package_mode": self._autorestapi.get_value("package-mode"),
318
250
  "package_pprint_name": self._autorestapi.get_value("package-pprint-name"),
319
- "package_configuration": self._autorestapi.get_value("package-configuration"),
251
+ "package_configuration": self._autorestapi.get_value(
252
+ "package-configuration"
253
+ ),
320
254
  "default_optional_constants_to_none": self._autorestapi.get_boolean_value(
321
- "default-optional-constants-to-none", low_level_client or version_tolerant
255
+ "default-optional-constants-to-none",
256
+ low_level_client or version_tolerant,
257
+ ),
258
+ "reformat_next_link": self._autorestapi.get_boolean_value(
259
+ "reformat-next-link", not version_tolerant
322
260
  ),
323
- "reformat_next_link": self._autorestapi.get_boolean_value("reformat-next-link", not version_tolerant)
324
261
  }
325
262
 
326
263
  if options["builders_visibility"] is None:
327
- options["builders_visibility"] = "public" if low_level_client else "embedded"
264
+ options["builders_visibility"] = (
265
+ "public" if low_level_client else "embedded"
266
+ )
328
267
  else:
329
268
  options["builders_visibility"] = options["builders_visibility"].lower()
330
269
 
@@ -336,7 +275,6 @@ class CodeGenerator(Plugin):
336
275
 
337
276
  # Force some options in ARM MODE:
338
277
  if azure_arm:
339
- options["credential"] = True
340
278
  options["head_as_boolean"] = True
341
279
  return options
342
280
 
@@ -347,7 +285,16 @@ class CodeGenerator(Plugin):
347
285
  if "code-model-v4-no-tags.yaml" not in inputs:
348
286
  raise ValueError("code-model-v4-no-tags.yaml must be a possible input")
349
287
 
350
- file_content = self._autorestapi.read_file("code-model-v4-no-tags.yaml")
288
+ if self._autorestapi.get_value("input-yaml"):
289
+ input_yaml = self._autorestapi.get_value("input-yaml")
290
+ file_content = self._autorestapi.read_file(input_yaml)
291
+ else:
292
+ inputs = self._autorestapi.list_inputs()
293
+ _LOGGER.debug("Possible Inputs: %s", inputs)
294
+ if "code-model-v4-no-tags.yaml" not in inputs:
295
+ raise ValueError("code-model-v4-no-tags.yaml must be a possible input")
296
+
297
+ file_content = self._autorestapi.read_file("code-model-v4-no-tags.yaml")
351
298
 
352
299
  # Parse the received YAML
353
300
  yaml_data = yaml.safe_load(file_content)
@@ -366,9 +313,13 @@ class CodeGenerator(Plugin):
366
313
 
367
314
 
368
315
  def main(yaml_model_file: str) -> None:
369
- from ..jsonrpc.localapi import LocalAutorestAPI # pylint: disable=import-outside-toplevel
316
+ from ..jsonrpc.localapi import ( # pylint: disable=import-outside-toplevel
317
+ LocalAutorestAPI,
318
+ )
370
319
 
371
- code_generator = CodeGenerator(autorestapi=LocalAutorestAPI(reachable_files=[yaml_model_file]))
320
+ code_generator = CodeGenerator(
321
+ autorestapi=LocalAutorestAPI(reachable_files=[yaml_model_file])
322
+ )
372
323
  if not code_generator.process():
373
324
  raise SystemExit("Process didn't finish gracefully")
374
325