@autorest/python 5.15.0 → 5.16.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 (86) hide show
  1. package/ChangeLog.md +20 -0
  2. package/autorest/__init__.py +1 -2
  3. package/autorest/black/__init__.py +12 -5
  4. package/autorest/codegen/__init__.py +145 -73
  5. package/autorest/codegen/models/__init__.py +29 -18
  6. package/autorest/codegen/models/base_builder.py +48 -11
  7. package/autorest/codegen/models/base_model.py +6 -4
  8. package/autorest/codegen/models/base_schema.py +19 -18
  9. package/autorest/codegen/models/client.py +65 -21
  10. package/autorest/codegen/models/code_model.py +107 -61
  11. package/autorest/codegen/models/constant_schema.py +25 -13
  12. package/autorest/codegen/models/credential_model.py +23 -15
  13. package/autorest/codegen/models/credential_schema.py +18 -14
  14. package/autorest/codegen/models/credential_schema_policy.py +11 -15
  15. package/autorest/codegen/models/dictionary_schema.py +20 -17
  16. package/autorest/codegen/models/enum_schema.py +35 -25
  17. package/autorest/codegen/models/imports.py +70 -41
  18. package/autorest/codegen/models/list_schema.py +25 -13
  19. package/autorest/codegen/models/lro_operation.py +58 -22
  20. package/autorest/codegen/models/lro_paging_operation.py +2 -3
  21. package/autorest/codegen/models/object_schema.py +99 -49
  22. package/autorest/codegen/models/operation.py +236 -117
  23. package/autorest/codegen/models/operation_group.py +64 -34
  24. package/autorest/codegen/models/paging_operation.py +45 -18
  25. package/autorest/codegen/models/parameter.py +151 -83
  26. package/autorest/codegen/models/parameter_list.py +183 -162
  27. package/autorest/codegen/models/primitive_schemas.py +84 -55
  28. package/autorest/codegen/models/property.py +44 -26
  29. package/autorest/codegen/models/request_builder.py +65 -30
  30. package/autorest/codegen/models/request_builder_parameter.py +47 -23
  31. package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
  32. package/autorest/codegen/models/schema_request.py +16 -6
  33. package/autorest/codegen/models/schema_response.py +18 -13
  34. package/autorest/codegen/models/utils.py +5 -2
  35. package/autorest/codegen/serializers/__init__.py +182 -91
  36. package/autorest/codegen/serializers/builder_serializer.py +667 -331
  37. package/autorest/codegen/serializers/client_serializer.py +98 -37
  38. package/autorest/codegen/serializers/general_serializer.py +61 -26
  39. package/autorest/codegen/serializers/import_serializer.py +93 -31
  40. package/autorest/codegen/serializers/metadata_serializer.py +73 -24
  41. package/autorest/codegen/serializers/model_base_serializer.py +35 -15
  42. package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
  43. package/autorest/codegen/serializers/model_init_serializer.py +5 -1
  44. package/autorest/codegen/serializers/model_python3_serializer.py +7 -6
  45. package/autorest/codegen/serializers/operation_groups_serializer.py +20 -9
  46. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  47. package/autorest/codegen/serializers/patch_serializer.py +4 -1
  48. package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
  49. package/autorest/codegen/serializers/utils.py +35 -21
  50. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  51. package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
  52. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
  53. package/autorest/codegen/templates/metadata.json.jinja2 +7 -6
  54. package/autorest/codegen/templates/operation.py.jinja2 +7 -9
  55. package/autorest/codegen/templates/operation_group.py.jinja2 +2 -8
  56. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
  57. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  58. package/autorest/codegen/templates/request_builder.py.jinja2 +18 -11
  59. package/autorest/jsonrpc/__init__.py +7 -12
  60. package/autorest/jsonrpc/localapi.py +4 -3
  61. package/autorest/jsonrpc/server.py +13 -6
  62. package/autorest/jsonrpc/stdstream.py +13 -6
  63. package/autorest/m2r/__init__.py +5 -8
  64. package/autorest/multiapi/__init__.py +24 -14
  65. package/autorest/multiapi/models/client.py +21 -11
  66. package/autorest/multiapi/models/code_model.py +23 -10
  67. package/autorest/multiapi/models/config.py +4 -1
  68. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  69. package/autorest/multiapi/models/global_parameter.py +2 -1
  70. package/autorest/multiapi/models/global_parameters.py +14 -8
  71. package/autorest/multiapi/models/imports.py +24 -17
  72. package/autorest/multiapi/models/mixin_operation.py +5 -5
  73. package/autorest/multiapi/models/operation_group.py +2 -1
  74. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  75. package/autorest/multiapi/serializers/__init__.py +18 -23
  76. package/autorest/multiapi/serializers/import_serializer.py +47 -17
  77. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  78. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
  79. package/autorest/multiapi/utils.py +3 -3
  80. package/autorest/namer/__init__.py +2 -4
  81. package/autorest/namer/name_converter.py +200 -103
  82. package/autorest/namer/python_mappings.py +10 -22
  83. package/package.json +2 -2
  84. package/run-python3.js +2 -3
  85. package/venvtools.py +1 -1
  86. package/autorest/codegen/models/rest.py +0 -42
package/ChangeLog.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ### 2022-04-18 - 5.16.0
4
+
5
+ | Library | Min Version |
6
+ | ----------------------------------------------------------------------- | ----------- |
7
+ | `@autorest/core` | `3.6.2` |
8
+ | `@autorest/modelerfour` | `4.19.1` |
9
+ | `azure-core` dep of generated code | `1.23.0` |
10
+ | `msrest` dep of generated code | `0.6.21` |
11
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
12
+
13
+ **Breaking Changes in Version Tolerant Generation**
14
+
15
+ - We no longer generate operations for operations with multipart or urlencoded bodies. SDK writers must implement these operations in their customized patch file. See https://aka.ms/azsdk/python/dpcodegen/python/customize for how to customize generated code #1223
16
+
17
+ **Bug Fixes**
18
+
19
+ - Drop package dependency on "@azure-tools/extension", switch to "@autorest/system-requirements" #1229
20
+ - Fix `content_type` generation in multiapi SDKs with multiple content types for bodies #1232
21
+
3
22
  ### 2022-04-07 - 5.15.0
4
23
 
5
24
  | Library | Min Version |
@@ -15,6 +34,7 @@
15
34
  - Add support for security configurations in the swagger. For more information, see https://github.com/Azure/autorest/blob/main/docs/generate/authentication.md #1161
16
35
  - Add support for handwritten customizations of generated code. For more information, see https://aka.ms/azsdk/python/dpcodegen/python/customize #1153
17
36
  - Allow `header` and `params` as kwargs in operation and request-build function to hand over REST Header and Query parameters case insensitively #1183
37
+ - Typing operation parameters as JSON, Primitives or Any for `--version-tolerant` #1210
18
38
 
19
39
  **Bug Fixes**
20
40
 
@@ -38,8 +38,7 @@ class Plugin(ABC):
38
38
 
39
39
 
40
40
  class YamlUpdatePlugin(Plugin):
41
- """A plugin that update the YAML as input.
42
- """
41
+ """A plugin that update the YAML as input."""
43
42
 
44
43
  def process(self) -> bool:
45
44
  # List the input file, should be only one
@@ -15,20 +15,25 @@ _LOGGER = logging.getLogger(__name__)
15
15
  _BLACK_MODE = black.Mode()
16
16
  _BLACK_MODE.line_length = 120
17
17
 
18
- class BlackScriptPlugin(Plugin):
19
18
 
19
+ class BlackScriptPlugin(Plugin):
20
20
  def __init__(self, autorestapi):
21
- super(BlackScriptPlugin, self).__init__(autorestapi)
21
+ super().__init__(autorestapi)
22
22
  output_folder_uri = self._autorestapi.get_value("outputFolderUri")
23
23
  if output_folder_uri.startswith("file:"):
24
24
  output_folder_uri = output_folder_uri[5:]
25
- if os.name == 'nt' and output_folder_uri.startswith("///"):
25
+ if os.name == "nt" and output_folder_uri.startswith("///"):
26
26
  output_folder_uri = output_folder_uri[3:]
27
27
  self.output_folder = Path(output_folder_uri)
28
28
 
29
29
  def process(self) -> bool:
30
30
  # apply format_file on every file in the output folder
31
- list(map(self.format_file, [f for f in self.output_folder.glob('**/*') if f.is_file()]))
31
+ list(
32
+ map(
33
+ self.format_file,
34
+ [f for f in self.output_folder.glob("**/*") if f.is_file()],
35
+ )
36
+ )
32
37
  return True
33
38
 
34
39
  def format_file(self, full_path) -> None:
@@ -38,7 +43,9 @@ class BlackScriptPlugin(Plugin):
38
43
  self._autorestapi.write_file(file, file_content)
39
44
  return
40
45
  try:
41
- file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)
46
+ file_content = black.format_file_contents(
47
+ file_content, fast=True, mode=_BLACK_MODE
48
+ )
42
49
  except black.NothingChanged:
43
50
  pass
44
51
  self._autorestapi.write_file(file, file_content)
@@ -5,30 +5,37 @@
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, Type
9
9
  from pathlib import Path
10
10
  import yaml
11
11
 
12
12
  from .. import Plugin
13
13
  from .models.code_model import CodeModel
14
- from .models import build_schema
14
+ from .models import build_schema, RequestBuilder
15
15
  from .models.operation_group import OperationGroup
16
16
  from .models.parameter import Parameter
17
17
  from .models.parameter_list import GlobalParameterList
18
- from .models.rest import Rest
19
18
  from .serializers import JinjaSerializer
20
- from .models.credential_schema_policy import CredentialSchemaPolicy, get_credential_schema_policy_type
21
- from .models.credential_schema_policy import BearerTokenCredentialPolicy, AzureKeyCredentialPolicy
19
+ from .models.credential_schema_policy import (
20
+ CredentialSchemaPolicy,
21
+ get_credential_schema_policy_type,
22
+ )
23
+ from .models.credential_schema_policy import (
24
+ BearerTokenCredentialPolicy,
25
+ AzureKeyCredentialPolicy,
26
+ )
22
27
  from .models.credential_model import CredentialModel
23
28
 
24
29
  _AAD_TYPE = "AADToken"
25
30
  _KEY_TYPE = "AzureKey"
26
31
 
32
+
27
33
  def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -> None:
28
34
  # Create operations
29
35
  if code_model.options["show_operations"] and yaml_data.get("operationGroups"):
30
36
  code_model.operation_groups = [
31
- OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"]
37
+ OperationGroup.from_yaml(op_group, code_model)
38
+ for op_group in yaml_data["operationGroups"]
32
39
  ]
33
40
  if yaml_data.get("schemas"):
34
41
  code_model.add_inheritance_to_models()
@@ -42,6 +49,7 @@ def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -
42
49
  code_model.format_lro_operations()
43
50
  code_model.remove_next_operation()
44
51
 
52
+
45
53
  def _validate_code_model_options(options: Dict[str, Any]) -> None:
46
54
 
47
55
  if options["builders_visibility"] not in ["public", "hidden", "embedded"]:
@@ -84,7 +92,10 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
84
92
  )
85
93
 
86
94
  if options["package_mode"]:
87
- if options["package_mode"] not in ("mgmtplane", "dataplane") and not Path(options["package_mode"]).exists():
95
+ if (
96
+ options["package_mode"] not in ("mgmtplane", "dataplane")
97
+ and not Path(options["package_mode"]).exists()
98
+ ):
88
99
  raise ValueError(
89
100
  "--package-mode can only be 'mgmtplane' or 'dataplane' or directory which contains template files"
90
101
  )
@@ -101,7 +112,10 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
101
112
  "We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
102
113
  )
103
114
 
115
+
104
116
  _LOGGER = logging.getLogger(__name__)
117
+
118
+
105
119
  class CodeGenerator(Plugin):
106
120
  @staticmethod
107
121
  def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
@@ -112,7 +126,11 @@ class CodeGenerator(Plugin):
112
126
  i = 0
113
127
  while i < len(operation["exceptions"]):
114
128
  exception = operation["exceptions"][i]
115
- if exception.get("schema") and exception["schema"]["language"]["default"]["name"] == "CloudError":
129
+ if (
130
+ exception.get("schema")
131
+ and exception["schema"]["language"]["default"]["name"]
132
+ == "CloudError"
133
+ ):
116
134
  del operation["exceptions"][i]
117
135
  i -= 1
118
136
  i += 1
@@ -123,19 +141,6 @@ class CodeGenerator(Plugin):
123
141
  del yaml_data["schemas"]["objects"][i]
124
142
  break
125
143
 
126
- @staticmethod
127
- def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[int]:
128
- exceptions_set = set()
129
- for group in yaml_data:
130
- for operation in group["operations"]:
131
- if not operation.get("exceptions"):
132
- continue
133
- for exception in operation["exceptions"]:
134
- if not exception.get("schema"):
135
- continue
136
- exceptions_set.add(id(exception["schema"]))
137
- return exceptions_set
138
-
139
144
  @staticmethod
140
145
  def _build_package_dependency() -> Dict[str, str]:
141
146
  return {
@@ -145,7 +150,9 @@ class CodeGenerator(Plugin):
145
150
  }
146
151
 
147
152
  @staticmethod
148
- def _build_with_security_definition(yaml_data: Dict[str, Any], credential_model: CredentialModel):
153
+ def _build_with_security_definition(
154
+ yaml_data: Dict[str, Any], credential_model: CredentialModel
155
+ ):
149
156
  security_yaml = yaml_data.get("security", {})
150
157
  if security_yaml.get("authenticationRequired"):
151
158
  for scheme in security_yaml.get("schemes"):
@@ -161,13 +168,17 @@ class CodeGenerator(Plugin):
161
168
  credential_model.policy_type = AzureKeyCredentialPolicy
162
169
 
163
170
  @staticmethod
164
- def _build_credential_model(code_model: CodeModel, credential_model: CredentialModel):
171
+ def _build_credential_model(
172
+ code_model: CodeModel, credential_model: CredentialModel
173
+ ):
165
174
  if credential_model.policy_type:
166
175
  code_model.options["credential"] = True
167
176
  credential_model.build_authentication_policy()
168
177
  code_model.credential_model = credential_model
169
178
 
170
- def _handle_credential_model(self, yaml_data: Dict[str, Any], code_model: CodeModel):
179
+ def _handle_credential_model(
180
+ self, yaml_data: Dict[str, Any], code_model: CodeModel
181
+ ):
171
182
  credential_model = CredentialModel(code_model.options["azure_arm"])
172
183
 
173
184
  # credential info with security definition will be overridded by credential flags
@@ -176,15 +187,19 @@ class CodeGenerator(Plugin):
176
187
 
177
188
  self._build_credential_model(code_model, credential_model)
178
189
 
179
- def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]) -> CodeModel:
190
+ def _create_code_model(
191
+ self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]
192
+ ) -> CodeModel:
180
193
  # Create a code model
181
194
 
182
- code_model = CodeModel(options=options)
195
+ code_model = CodeModel(yaml_data, options=options)
183
196
  self._handle_credential_model(yaml_data, code_model)
184
197
  code_model.module_name = yaml_data["info"]["python_title"]
185
198
  code_model.class_name = yaml_data["info"]["pascal_case_title"]
186
199
  code_model.description = (
187
- yaml_data["info"]["description"] if yaml_data["info"].get("description") else ""
200
+ yaml_data["info"]["description"]
201
+ if yaml_data["info"].get("description")
202
+ else ""
188
203
  )
189
204
 
190
205
  # Get my namespace
@@ -195,23 +210,29 @@ class CodeGenerator(Plugin):
195
210
  code_model.namespace = namespace
196
211
 
197
212
  if yaml_data.get("schemas"):
198
- exceptions_set = CodeGenerator._build_exceptions_set(yaml_data=yaml_data["operationGroups"])
199
-
200
213
  for type_list in yaml_data["schemas"].values():
201
214
  for schema in type_list:
202
- build_schema(yaml_data=schema, exceptions_set=exceptions_set, code_model=code_model)
215
+ build_schema(yaml_data=schema, code_model=code_model)
203
216
 
204
217
  # Global parameters
205
218
  code_model.global_parameters = GlobalParameterList(
206
219
  code_model,
207
- [Parameter.from_yaml(param, code_model=code_model) for param in yaml_data.get("globalParameters", [])],
220
+ [
221
+ Parameter.from_yaml(param, code_model=code_model)
222
+ for param in yaml_data.get("globalParameters", [])
223
+ ],
208
224
  )
209
- code_model.global_parameters.code_model = code_model
210
225
 
211
226
  # Custom URL
212
227
  code_model.setup_client_input_parameters(yaml_data)
213
228
 
214
- code_model.rest = Rest.from_yaml(yaml_data, code_model=code_model)
229
+ # Build request builders
230
+ if yaml_data.get("operationGroups"):
231
+ code_model.request_builders = [
232
+ RequestBuilder.from_yaml(operation_yaml, code_model=code_model)
233
+ for og_group in yaml_data["operationGroups"]
234
+ for operation_yaml in og_group["operations"]
235
+ ]
215
236
  _build_convenience_layer(yaml_data=yaml_data, code_model=code_model)
216
237
 
217
238
  if options["credential"]:
@@ -222,12 +243,19 @@ class CodeGenerator(Plugin):
222
243
 
223
244
  def _get_credential_scopes(self, credential):
224
245
  credential_scopes_temp = self._autorestapi.get_value("credential-scopes")
225
- credential_scopes = credential_scopes_temp.split(",") if credential_scopes_temp else None
246
+ credential_scopes = (
247
+ credential_scopes_temp.split(",") if credential_scopes_temp else None
248
+ )
226
249
  if credential_scopes and not credential:
227
- raise ValueError("--credential-scopes must be used with the --add-credential flag")
250
+ raise ValueError(
251
+ "--credential-scopes must be used with the --add-credential flag"
252
+ )
228
253
 
229
254
  # check to see if user just passes in --credential-scopes with no value
230
- if self._autorestapi.get_boolean_value("credential-scopes", False) and not credential_scopes:
255
+ if (
256
+ self._autorestapi.get_boolean_value("credential-scopes", False)
257
+ and not credential_scopes
258
+ ):
231
259
  raise ValueError(
232
260
  "--credential-scopes takes a list of scopes in comma separated format. "
233
261
  "For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
@@ -238,13 +266,17 @@ class CodeGenerator(Plugin):
238
266
  self,
239
267
  code_model: CodeModel,
240
268
  credential_schema_policy: Type[CredentialSchemaPolicy],
241
- credential_model: CredentialModel
269
+ credential_model: CredentialModel,
242
270
  ):
243
271
  credential_model.policy_type = credential_schema_policy
244
- credential_scopes = self._get_credential_scopes(code_model.options['credential'])
245
- credential_key_header_name = self._autorestapi.get_value('credential-key-header-name')
246
- azure_arm = code_model.options['azure_arm']
247
- credential = code_model.options['credential']
272
+ credential_scopes = self._get_credential_scopes(
273
+ code_model.options["credential"]
274
+ )
275
+ credential_key_header_name = self._autorestapi.get_value(
276
+ "credential-key-header-name"
277
+ )
278
+ azure_arm = code_model.options["azure_arm"]
279
+ credential = code_model.options["credential"]
248
280
 
249
281
  if hasattr(credential_schema_policy, "credential_scopes"):
250
282
  if not credential_scopes:
@@ -258,7 +290,7 @@ class CodeGenerator(Plugin):
258
290
  "but not the --credential-scopes flag set while generating non-management plane code. "
259
291
  "This is not recommend because it forces the customer to pass credential scopes "
260
292
  "through kwargs if they want to authenticate.",
261
- credential_schema_policy.name()
293
+ credential_schema_policy.name(),
262
294
  )
263
295
  credential_scopes = []
264
296
 
@@ -287,84 +319,120 @@ class CodeGenerator(Plugin):
287
319
 
288
320
  credential_model.key_header_name = credential_key_header_name
289
321
 
290
- def _build_with_credential_flags(self, code_model: CodeModel, credential_model: CredentialModel):
322
+ def _build_with_credential_flags(
323
+ self, code_model: CodeModel, credential_model: CredentialModel
324
+ ):
291
325
  if not code_model.options["credential"]:
292
326
  return
293
327
 
294
328
  credential_schema_policy_name = (
295
- self._autorestapi.get_value("credential-default-policy-type") or
296
- credential_model.default_authentication_policy.name()
329
+ self._autorestapi.get_value("credential-default-policy-type")
330
+ or credential_model.default_authentication_policy.name()
331
+ )
332
+ credential_schema_policy_type = get_credential_schema_policy_type(
333
+ credential_schema_policy_name
297
334
  )
298
- credential_schema_policy_type = get_credential_schema_policy_type(credential_schema_policy_name)
299
335
  self._update_with_credential_flags(
300
336
  code_model, credential_schema_policy_type, credential_model
301
337
  )
302
338
 
303
339
  def _build_code_model_options(self) -> Dict[str, Any]:
304
- """Build en options dict from the user input while running autorest.
305
- """
340
+ """Build en options dict from the user input while running autorest."""
306
341
  azure_arm = self._autorestapi.get_boolean_value("azure-arm", False)
307
- credential = (
308
- self._autorestapi.get_boolean_value("add-credentials", False) or
309
- self._autorestapi.get_boolean_value("add-credential", False)
310
- )
342
+ credential = self._autorestapi.get_boolean_value(
343
+ "add-credentials", False
344
+ ) or self._autorestapi.get_boolean_value("add-credential", False)
311
345
 
312
346
  license_header = self._autorestapi.get_value("header-text")
313
347
  if license_header:
314
348
  license_header = license_header.replace("\n", "\n# ")
315
349
  license_header = (
316
- "# --------------------------------------------------------------------------\n# " + license_header
350
+ "# --------------------------------------------------------------------------\n# "
351
+ + license_header
317
352
  )
318
353
  license_header += "\n# --------------------------------------------------------------------------"
319
354
 
320
- low_level_client = self._autorestapi.get_boolean_value("low-level-client", False)
321
- version_tolerant = self._autorestapi.get_boolean_value("version-tolerant", False)
322
- show_operations = self._autorestapi.get_boolean_value("show-operations", not low_level_client)
323
- models_mode_default = "none" if low_level_client or version_tolerant else "msrest"
324
- python3_only = self._autorestapi.get_boolean_value("python3-only", low_level_client or version_tolerant)
355
+ low_level_client = self._autorestapi.get_boolean_value(
356
+ "low-level-client", False
357
+ )
358
+ version_tolerant = self._autorestapi.get_boolean_value(
359
+ "version-tolerant", False
360
+ )
361
+ show_operations = self._autorestapi.get_boolean_value(
362
+ "show-operations", not low_level_client
363
+ )
364
+ models_mode_default = (
365
+ "none" if low_level_client or version_tolerant else "msrest"
366
+ )
367
+ python3_only = self._autorestapi.get_boolean_value(
368
+ "python3-only", low_level_client or version_tolerant
369
+ )
325
370
 
326
371
  options: Dict[str, Any] = {
327
372
  "azure_arm": azure_arm,
328
373
  "credential": credential,
329
- "head_as_boolean": self._autorestapi.get_boolean_value("head-as-boolean", False),
374
+ "head_as_boolean": self._autorestapi.get_boolean_value(
375
+ "head-as-boolean", False
376
+ ),
330
377
  "license_header": license_header,
331
- "keep_version_file": self._autorestapi.get_boolean_value("keep-version-file", False),
378
+ "keep_version_file": self._autorestapi.get_boolean_value(
379
+ "keep-version-file", False
380
+ ),
332
381
  "no_async": self._autorestapi.get_boolean_value("no-async", False),
333
- "no_namespace_folders": self._autorestapi.get_boolean_value("no-namespace-folders", False),
334
- "basic_setup_py": self._autorestapi.get_boolean_value("basic-setup-py", False),
382
+ "no_namespace_folders": self._autorestapi.get_boolean_value(
383
+ "no-namespace-folders", False
384
+ ),
385
+ "basic_setup_py": self._autorestapi.get_boolean_value(
386
+ "basic-setup-py", False
387
+ ),
335
388
  "package_name": self._autorestapi.get_value("package-name"),
336
389
  "package_version": self._autorestapi.get_value("package-version"),
337
- "client_side_validation": self._autorestapi.get_boolean_value("client-side-validation", False),
390
+ "client_side_validation": self._autorestapi.get_boolean_value(
391
+ "client-side-validation", False
392
+ ),
338
393
  "tracing": self._autorestapi.get_boolean_value("trace", show_operations),
339
394
  "multiapi": self._autorestapi.get_boolean_value("multiapi", False),
340
- "polymorphic_examples": self._autorestapi.get_value("polymorphic-examples") or 5,
341
- "models_mode": (self._autorestapi.get_value("models-mode") or models_mode_default).lower(),
395
+ "polymorphic_examples": self._autorestapi.get_value("polymorphic-examples")
396
+ or 5,
397
+ "models_mode": (
398
+ self._autorestapi.get_value("models-mode") or models_mode_default
399
+ ).lower(),
342
400
  "builders_visibility": self._autorestapi.get_value("builders-visibility"),
343
401
  "show_operations": show_operations,
344
402
  "show_send_request": self._autorestapi.get_boolean_value(
345
403
  "show-send-request", low_level_client or version_tolerant
346
404
  ),
347
405
  "only_path_and_body_params_positional": self._autorestapi.get_boolean_value(
348
- "only-path-and-body-params-positional", low_level_client or version_tolerant
406
+ "only-path-and-body-params-positional",
407
+ low_level_client or version_tolerant,
349
408
  ),
350
409
  "add_python3_operation_files": self._autorestapi.get_boolean_value(
351
410
  "add-python3-operation-files", python3_only and not low_level_client
352
411
  ),
353
412
  "version_tolerant": version_tolerant,
354
413
  "low_level_client": low_level_client,
355
- "combine_operation_files": self._autorestapi.get_boolean_value("combine-operation-files", version_tolerant),
414
+ "combine_operation_files": self._autorestapi.get_boolean_value(
415
+ "combine-operation-files", version_tolerant
416
+ ),
356
417
  "python3_only": python3_only,
357
418
  "package_mode": self._autorestapi.get_value("package-mode"),
358
419
  "package_pprint_name": self._autorestapi.get_value("package-pprint-name"),
359
- "package_configuration": self._autorestapi.get_value("package-configuration"),
420
+ "package_configuration": self._autorestapi.get_value(
421
+ "package-configuration"
422
+ ),
360
423
  "default_optional_constants_to_none": self._autorestapi.get_boolean_value(
361
- "default-optional-constants-to-none", low_level_client or version_tolerant
424
+ "default-optional-constants-to-none",
425
+ low_level_client or version_tolerant,
426
+ ),
427
+ "reformat_next_link": self._autorestapi.get_boolean_value(
428
+ "reformat-next-link", not version_tolerant
362
429
  ),
363
- "reformat_next_link": self._autorestapi.get_boolean_value("reformat-next-link", not version_tolerant)
364
430
  }
365
431
 
366
432
  if options["builders_visibility"] is None:
367
- options["builders_visibility"] = "public" if low_level_client else "embedded"
433
+ options["builders_visibility"] = (
434
+ "public" if low_level_client else "embedded"
435
+ )
368
436
  else:
369
437
  options["builders_visibility"] = options["builders_visibility"].lower()
370
438
 
@@ -406,9 +474,13 @@ class CodeGenerator(Plugin):
406
474
 
407
475
 
408
476
  def main(yaml_model_file: str) -> None:
409
- from ..jsonrpc.localapi import LocalAutorestAPI # pylint: disable=import-outside-toplevel
477
+ from ..jsonrpc.localapi import ( # pylint: disable=import-outside-toplevel
478
+ LocalAutorestAPI,
479
+ )
410
480
 
411
- code_generator = CodeGenerator(autorestapi=LocalAutorestAPI(reachable_files=[yaml_model_file]))
481
+ code_generator = CodeGenerator(
482
+ autorestapi=LocalAutorestAPI(reachable_files=[yaml_model_file])
483
+ )
412
484
  if not code_generator.process():
413
485
  raise SystemExit("Process didn't finish gracefully")
414
486
 
@@ -10,14 +10,24 @@ from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
10
10
  from .object_schema import ObjectSchema, get_object_schema, HiddenModelObjectSchema
11
11
  from .dictionary_schema import DictionarySchema
12
12
  from .list_schema import ListSchema
13
- from .primitive_schemas import get_primitive_schema, AnySchema, PrimitiveSchema, IOSchema
13
+ from .primitive_schemas import (
14
+ get_primitive_schema,
15
+ AnySchema,
16
+ PrimitiveSchema,
17
+ IOSchema,
18
+ )
14
19
  from .enum_schema import EnumSchema, HiddenModelEnumSchema, get_enum_schema
15
20
  from .base_schema import BaseSchema
16
21
  from .constant_schema import ConstantSchema
17
22
  from .imports import FileImport, ImportType, TypingSection
18
23
  from .lro_operation import LROOperation
19
24
  from .paging_operation import PagingOperation
20
- from .parameter import Parameter, ParameterStyle, ParameterLocation
25
+ from .parameter import (
26
+ Parameter,
27
+ ParameterStyle,
28
+ ParameterLocation,
29
+ ParameterMethodLocation,
30
+ )
21
31
  from .operation import Operation
22
32
  from .property import Property
23
33
  from .operation_group import OperationGroup
@@ -64,24 +74,23 @@ __all__ = [
64
74
  "ParameterStyle",
65
75
  "IOSchema",
66
76
  "GlobalParameterList",
77
+ "ParameterMethodLocation",
67
78
  ]
68
79
 
80
+
69
81
  def _generate_as_object_schema(yaml_data: Dict[str, Any]) -> bool:
70
82
  if (
71
- yaml_data.get('properties') or
72
- yaml_data.get('discriminator') or
73
- yaml_data.get('parents') and yaml_data['parents'].get('immediate')
83
+ yaml_data.get("properties")
84
+ or yaml_data.get("discriminator")
85
+ or yaml_data.get("parents")
86
+ and yaml_data["parents"].get("immediate")
74
87
  ):
75
88
  return True
76
89
  return False
77
90
 
78
91
 
79
- def build_schema(yaml_data: Dict[str, Any], **kwargs) -> BaseSchema:
80
- code_model = kwargs.get("code_model", None)
81
- if not code_model:
82
- raise ValueError("CodeModel not passed through kwargs")
92
+ def build_schema(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseSchema:
83
93
  yaml_id = id(yaml_data)
84
- namespace = code_model.namespace
85
94
  try:
86
95
  return code_model.lookup_schema(yaml_id)
87
96
  except KeyError:
@@ -90,33 +99,35 @@ def build_schema(yaml_data: Dict[str, Any], **kwargs) -> BaseSchema:
90
99
  schema: BaseSchema
91
100
  schema_type = yaml_data["type"]
92
101
  if schema_type == "constant":
93
- schema = ConstantSchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
102
+ schema = ConstantSchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
94
103
  code_model.primitives[yaml_id] = schema
95
104
 
96
105
  elif schema_type in ["choice", "sealed-choice"]:
97
- schema = get_enum_schema(code_model).from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
106
+ schema = get_enum_schema(code_model).from_yaml(
107
+ yaml_data=yaml_data, code_model=code_model
108
+ )
98
109
  code_model.enums[yaml_id] = schema
99
110
 
100
111
  elif schema_type == "array":
101
- schema = ListSchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
112
+ schema = ListSchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
102
113
  code_model.primitives[yaml_id] = schema
103
114
 
104
115
  elif schema_type == "dictionary":
105
- schema = DictionarySchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
116
+ schema = DictionarySchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
106
117
  code_model.primitives[yaml_id] = schema
107
118
 
108
119
  elif schema_type in ["object", "and", "group", "any-object"]:
109
120
  if _generate_as_object_schema(yaml_data):
110
121
  # To avoid infinite loop, create the right instance in memory,
111
122
  # put it in the index, and then parse the object.
112
- schema = get_object_schema(code_model)(namespace, yaml_data, "_", "")
123
+ schema = get_object_schema(code_model)(yaml_data, code_model, "_", "")
113
124
  code_model.schemas[yaml_id] = schema
114
- schema.fill_instance_from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
125
+ schema.fill_instance_from_yaml(yaml_data=yaml_data, code_model=code_model)
115
126
  else:
116
- schema = AnySchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
127
+ schema = AnySchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
117
128
  code_model.primitives[yaml_id] = schema
118
129
  else:
119
- schema = get_primitive_schema(namespace=namespace, yaml_data=yaml_data)
130
+ schema = get_primitive_schema(yaml_data=yaml_data, code_model=code_model)
120
131
  code_model.primitives[yaml_id] = schema
121
132
 
122
133
  return schema