@autorest/python 5.16.0 → 5.19.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 (96) hide show
  1. package/ChangeLog.md +79 -4
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +1 -1
  4. package/autorest/codegen/__init__.py +55 -211
  5. package/autorest/codegen/models/__init__.py +116 -83
  6. package/autorest/codegen/models/base_builder.py +49 -88
  7. package/autorest/codegen/models/base_model.py +1 -1
  8. package/autorest/codegen/models/{base_schema.py → base_type.py} +61 -39
  9. package/autorest/codegen/models/client.py +165 -53
  10. package/autorest/codegen/models/code_model.py +122 -257
  11. package/autorest/codegen/models/combined_type.py +107 -0
  12. package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
  13. package/autorest/codegen/models/credential_types.py +224 -0
  14. package/autorest/codegen/models/dictionary_type.py +131 -0
  15. package/autorest/codegen/models/enum_type.py +195 -0
  16. package/autorest/codegen/models/imports.py +80 -2
  17. package/autorest/codegen/models/list_type.py +149 -0
  18. package/autorest/codegen/models/lro_operation.py +79 -156
  19. package/autorest/codegen/models/lro_paging_operation.py +28 -11
  20. package/autorest/codegen/models/model_type.py +262 -0
  21. package/autorest/codegen/models/operation.py +331 -298
  22. package/autorest/codegen/models/operation_group.py +54 -91
  23. package/autorest/codegen/models/paging_operation.py +82 -123
  24. package/autorest/codegen/models/parameter.py +289 -396
  25. package/autorest/codegen/models/parameter_list.py +355 -360
  26. package/autorest/codegen/models/primitive_types.py +544 -0
  27. package/autorest/codegen/models/property.py +123 -139
  28. package/autorest/codegen/models/request_builder.py +130 -102
  29. package/autorest/codegen/models/request_builder_parameter.py +112 -100
  30. package/autorest/codegen/models/response.py +325 -0
  31. package/autorest/codegen/models/utils.py +12 -19
  32. package/autorest/codegen/serializers/__init__.py +55 -37
  33. package/autorest/codegen/serializers/builder_serializer.py +695 -1144
  34. package/autorest/codegen/serializers/client_serializer.py +92 -89
  35. package/autorest/codegen/serializers/general_serializer.py +15 -69
  36. package/autorest/codegen/serializers/import_serializer.py +7 -4
  37. package/autorest/codegen/serializers/metadata_serializer.py +15 -104
  38. package/autorest/codegen/serializers/model_base_serializer.py +49 -36
  39. package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
  40. package/autorest/codegen/serializers/model_init_serializer.py +2 -4
  41. package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
  42. package/autorest/codegen/serializers/operation_groups_serializer.py +7 -13
  43. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  44. package/autorest/codegen/serializers/request_builders_serializer.py +13 -30
  45. package/autorest/codegen/serializers/utils.py +0 -140
  46. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  47. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +10 -7
  48. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  49. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  50. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  52. package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
  53. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
  54. package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
  55. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  56. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  57. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  58. package/autorest/codegen/templates/operation.py.jinja2 +6 -8
  59. package/autorest/codegen/templates/operation_group.py.jinja2 +21 -8
  60. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -2
  61. package/autorest/codegen/templates/operation_tools.jinja2 +11 -3
  62. package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
  63. package/autorest/codegen/templates/request_builder.py.jinja2 +10 -15
  64. package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
  65. package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
  66. package/autorest/codegen/templates/setup.py.jinja2 +13 -3
  67. package/autorest/codegen/templates/vendor.py.jinja2 +11 -1
  68. package/autorest/jsonrpc/server.py +15 -3
  69. package/autorest/m4reformatter/__init__.py +1126 -0
  70. package/autorest/multiapi/models/client.py +12 -2
  71. package/autorest/multiapi/models/code_model.py +1 -1
  72. package/autorest/multiapi/serializers/__init__.py +18 -4
  73. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  74. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  75. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  76. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  77. package/autorest/postprocess/__init__.py +202 -0
  78. package/autorest/postprocess/get_all.py +19 -0
  79. package/autorest/postprocess/venvtools.py +73 -0
  80. package/autorest/preprocess/__init__.py +210 -0
  81. package/autorest/preprocess/helpers.py +54 -0
  82. package/autorest/{namer → preprocess}/python_mappings.py +21 -16
  83. package/package.json +2 -2
  84. package/autorest/codegen/models/credential_model.py +0 -55
  85. package/autorest/codegen/models/credential_schema.py +0 -95
  86. package/autorest/codegen/models/credential_schema_policy.py +0 -73
  87. package/autorest/codegen/models/dictionary_schema.py +0 -106
  88. package/autorest/codegen/models/enum_schema.py +0 -225
  89. package/autorest/codegen/models/list_schema.py +0 -135
  90. package/autorest/codegen/models/object_schema.py +0 -303
  91. package/autorest/codegen/models/primitive_schemas.py +0 -495
  92. package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
  93. package/autorest/codegen/models/schema_request.py +0 -55
  94. package/autorest/codegen/models/schema_response.py +0 -141
  95. package/autorest/namer/__init__.py +0 -23
  96. package/autorest/namer/name_converter.py +0 -509
package/ChangeLog.md CHANGED
@@ -1,4 +1,79 @@
1
- # Change Log
1
+ # Release History
2
+
3
+ ### 2022-07-13 - 5.19.0
4
+
5
+ | Library | Min Version |
6
+ | ----------------------------------------------------------------------- | ----------- |
7
+ | `@autorest/core` | `3.8.1` |
8
+ | `@autorest/modelerfour` | `4.23.5` |
9
+ | `azure-core` dep of generated code | `1.24.0` |
10
+ | `msrest` dep of generated code | `0.7.0` |
11
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
12
+
13
+ **New Features**
14
+ - Add _serialization.py for `--client-side-validation=false` generation, and migrate serilization from msrest to _serialization.py #1236
15
+
16
+ ### 2022-07-13 - 5.18.0
17
+
18
+ | Library | Min Version |
19
+ | ----------------------------------------------------------------------- | ----------- |
20
+ | `@autorest/core` | `3.8.1` |
21
+ | `@autorest/modelerfour` | `4.23.5` |
22
+ | `azure-core` dep of generated code | `1.24.0` |
23
+ | `msrest` dep of generated code | `0.7.0` |
24
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
25
+
26
+ **Breaking Changes in Version Tolerant**
27
+
28
+ - No longer allow users to specify `api_version` on the method level #1281
29
+ - Make `content_type` param required with no default if streaming with no `application/octet-stream` #1288
30
+
31
+ **Bug Fixes**
32
+
33
+ - Fix duplicate params in signature with `--payload-flattening-threshold` #1289
34
+ - Fix overloaded request builder signatures #1289
35
+ - Improve docstring templates, specifically for polymorphic bodies #1279
36
+
37
+
38
+ ### 2022-06-02 - 5.17.0
39
+
40
+ | Library | Min Version |
41
+ | ----------------------------------------------------------------------- | ----------- |
42
+ | `@autorest/core` | `3.8.1` |
43
+ | `@autorest/modelerfour` | `4.23.5` |
44
+ | `azure-core` dep of generated code | `1.23.0` |
45
+ | `msrest` dep of generated code | `0.6.21` |
46
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
47
+
48
+ **New Features**
49
+
50
+ - Hide `api_version` in doc string for singleapi SDK even if contains multi api versions #1239
51
+ - Add overloads for operations with different body types. We now sniff bodies and assign content type based off of body type. #1230
52
+ - Add flag `--postprocess`. Run this after doing customizations for full mypy support
53
+
54
+ **Breaking Changes in Version Tolerant**
55
+
56
+ - Have stream responses directly return an iterator of bytes, so you don't need to call `.iter_bytes()` on the response object. #1254
57
+ - If generating with `--models-mode=msrest` in version tolerant, we hide paging models #1259
58
+
59
+ **Breaking Changes in Request Builders**
60
+
61
+ - Request builders for LRO operations have the `_initial` suffix removed from their name #1241
62
+ - Request builders from groups with reserved words will now be padded with the word "Operations" instead of "Builders" #1243
63
+
64
+ **Bug Fixes**
65
+
66
+ - Make sure `any-object` schemas from swagger are typed with `MutableMapping`s #1243
67
+ - Make typing for parameters `Optional` only if `None` is a valid input, not only if it is specified as `optional` in swagger #1244
68
+ - Fix for render failure of `README.md` when `--package-mode==dataplane` #1247
69
+ - Fix typing for stream responses to iterators of bytes. #1254
70
+ - Additional linting support #1265
71
+ - Fix Sphinx documentation for raised exception #1264
72
+ - Use `api_version` in `_config` as default value for operation function #1268
73
+
74
+ **Other Changes**
75
+
76
+ - Update template files for `--package-mode` # 1248
2
77
 
3
78
  ### 2022-04-18 - 5.16.0
4
79
 
@@ -45,7 +120,7 @@
45
120
 
46
121
  **Breaking Changes in Version Tolerant Generation**
47
122
 
48
- - Change client filenames to `_client.py` #1206
123
+ - Change client filenames to `_client.py` #1206
49
124
  - Change the models filename from `_models_py3.py` to `_models.py` #1204
50
125
  - Change the enums filename to `_enums.py` #1204
51
126
 
@@ -716,7 +791,7 @@ Modelerfour version: 4.13.351
716
791
  **Bug Fixes**
717
792
 
718
793
  - Corrected ordering of summary and description in generated methods #640
719
- - Have `IOSchema` call super init to get all of the properties shared in `BaseSchema` #642
794
+ - Have `IOSchema` call super init to get all of the properties shared in `BaseType` #642
720
795
 
721
796
  ### 2020-05-15 - 5.0.0-preview.7
722
797
 
@@ -861,7 +936,7 @@ Modelerfour version: 4.12.276
861
936
 
862
937
  - Will no longer permit generated enums and models to have the same name #504
863
938
  - No longer exposing models from operation groups without importing them #486
864
- - Now correctly deserializes error's that have an empty object (AnySchema) as a model #516
939
+ - Now correctly deserializes error's that have an empty object (AnyType) as a model #516
865
940
  - Added a list of parameter names to reserved parameter words, so there won't be clashes #525
866
941
  - If a property's schema is readonly, we will show that property as being readonly (taken from m4 update #234)
867
942
  - Remove `"azure-"` prefix from user agent name #523
package/README.md CHANGED
@@ -30,13 +30,17 @@ modelerfour:
30
30
  flatten-payloads: true
31
31
  ```
32
32
 
33
+ ```yaml $(postprocess)
34
+ allow-no-input: true
35
+ ```
36
+
33
37
  ```yaml !$(multiapiscript)
34
38
  pass-thru:
35
39
  - model-deduplicator
36
40
  - subset-reducer
37
- version: ~3.6.2
41
+ version: ~3.8.1
38
42
  use-extension:
39
- "@autorest/modelerfour": ~4.19.1
43
+ "@autorest/modelerfour": ~4.23.5
40
44
 
41
45
  modelerfour:
42
46
  resolve-schema-name-collisons: true
@@ -69,11 +73,14 @@ pipeline:
69
73
  python/m2r:
70
74
  input: python
71
75
 
72
- python/namer:
76
+ python/m4reformatter:
73
77
  input: python/m2r
74
78
 
79
+ python/preprocess:
80
+ input: python/m4reformatter
81
+
75
82
  python/codegen:
76
- input: python/namer
83
+ input: python/preprocess
77
84
  output-artifact: python-files
78
85
 
79
86
  python/codegen/emitter:
@@ -126,6 +133,25 @@ scope-black/emitter:
126
133
  output-artifact: python-files
127
134
  ```
128
135
 
136
+ # Post-process customized code for mypy pipeline
137
+
138
+ ```yaml $(postprocess)
139
+ pipeline:
140
+ python/postprocess:
141
+ scope: postprocess
142
+ output-artifact: python-files
143
+
144
+ python/postprocess/emitter:
145
+ input: postprocess
146
+ scope: scope-postprocess/emitter
147
+
148
+ scope-postprocess/emitter:
149
+ input-artifact: python-files
150
+ output-uri-expr: $key
151
+
152
+ output-artifact: python-files
153
+ ```
154
+
129
155
  # Help
130
156
 
131
157
  ```yaml
@@ -61,7 +61,7 @@ class YamlUpdatePlugin(Plugin):
61
61
  def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
62
62
  """The code-model-v4-no-tags yaml model tree.
63
63
 
64
- :rtype: None
64
+ :rtype: updated yaml
65
65
  :raises Exception: Could raise any exception, stacktrace will be sent to autorest API
66
66
  """
67
67
  raise NotImplementedError()
@@ -5,29 +5,18 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
7
  import sys
8
- from typing import Dict, Any, Union, 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, RequestBuilder
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
19
  from .serializers import JinjaSerializer
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
- )
27
- from .models.credential_model import CredentialModel
28
-
29
- _AAD_TYPE = "AADToken"
30
- _KEY_TYPE = "AzureKey"
31
20
 
32
21
 
33
22
  def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -> None:
@@ -37,17 +26,13 @@ def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -
37
26
  OperationGroup.from_yaml(op_group, code_model)
38
27
  for op_group in yaml_data["operationGroups"]
39
28
  ]
40
- if yaml_data.get("schemas"):
41
- code_model.add_inheritance_to_models()
29
+ if yaml_data.get("types"):
42
30
  if code_model.options["models_mode"]:
43
- code_model.sort_schemas()
31
+ code_model.sort_model_types()
44
32
 
45
33
  if code_model.options["show_operations"]:
46
- code_model.generate_single_parameter_from_multiple_content_types_operation()
47
- code_model.link_operation_to_request_builder()
48
34
  # LRO operation
49
35
  code_model.format_lro_operations()
50
- code_model.remove_next_operation()
51
36
 
52
37
 
53
38
  def _validate_code_model_options(options: Dict[str, Any]) -> None:
@@ -112,6 +97,11 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
112
97
  "We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
113
98
  )
114
99
 
100
+ if options["client_side_validation"] and options["version_tolerant"]:
101
+ raise ValueError(
102
+ "Can not generate version tolerant with --client-side-validation. "
103
+ )
104
+
115
105
 
116
106
  _LOGGER = logging.getLogger(__name__)
117
107
 
@@ -145,204 +135,47 @@ class CodeGenerator(Plugin):
145
135
  def _build_package_dependency() -> Dict[str, str]:
146
136
  return {
147
137
  "dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.0",
148
- "dependency_azure_core": "azure-core<2.0.0,>=1.23.0",
149
- "dependency_msrest": "msrest>=0.6.21",
138
+ "dependency_azure_core": "azure-core<2.0.0,>=1.24.0",
139
+ "dependency_msrest": "msrest>=0.7.0",
150
140
  }
151
141
 
152
- @staticmethod
153
- def _build_with_security_definition(
154
- yaml_data: Dict[str, Any], credential_model: CredentialModel
155
- ):
156
- security_yaml = yaml_data.get("security", {})
157
- if security_yaml.get("authenticationRequired"):
158
- for scheme in security_yaml.get("schemes"):
159
- if _AAD_TYPE == scheme["type"]:
160
- credential_model.credential_scopes.update(scheme["scopes"])
161
- elif _KEY_TYPE == scheme["type"]:
162
- # only accept the last one
163
- credential_model.key_header_name = scheme["headerName"]
164
-
165
- if credential_model.credential_scopes:
166
- credential_model.policy_type = BearerTokenCredentialPolicy
167
- elif credential_model.key_header_name:
168
- credential_model.policy_type = AzureKeyCredentialPolicy
169
-
170
- @staticmethod
171
- def _build_credential_model(
172
- code_model: CodeModel, credential_model: CredentialModel
173
- ):
174
- if credential_model.policy_type:
175
- code_model.options["credential"] = True
176
- credential_model.build_authentication_policy()
177
- code_model.credential_model = credential_model
178
-
179
- def _handle_credential_model(
180
- self, yaml_data: Dict[str, Any], code_model: CodeModel
181
- ):
182
- credential_model = CredentialModel(code_model.options["azure_arm"])
183
-
184
- # credential info with security definition will be overridded by credential flags
185
- self._build_with_security_definition(yaml_data, credential_model)
186
- self._build_with_credential_flags(code_model, credential_model)
187
-
188
- self._build_credential_model(code_model, credential_model)
189
-
190
142
  def _create_code_model(
191
143
  self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]
192
144
  ) -> CodeModel:
193
145
  # Create a code model
194
146
 
195
147
  code_model = CodeModel(yaml_data, options=options)
196
- self._handle_credential_model(yaml_data, code_model)
197
- code_model.module_name = yaml_data["info"]["python_title"]
198
- code_model.class_name = yaml_data["info"]["pascal_case_title"]
199
- code_model.description = (
200
- yaml_data["info"]["description"]
201
- if yaml_data["info"].get("description")
202
- else ""
203
- )
204
-
205
- # Get my namespace
206
- namespace = self._autorestapi.get_value("namespace")
207
- _LOGGER.debug("Namespace parameter was %s", namespace)
208
- if not namespace:
209
- namespace = yaml_data["info"]["python_title"]
210
- code_model.namespace = namespace
211
-
212
- if yaml_data.get("schemas"):
213
- for type_list in yaml_data["schemas"].values():
214
- for schema in type_list:
215
- build_schema(yaml_data=schema, code_model=code_model)
216
-
217
- # Global parameters
218
- code_model.global_parameters = GlobalParameterList(
219
- code_model,
220
- [
221
- Parameter.from_yaml(param, code_model=code_model)
222
- for param in yaml_data.get("globalParameters", [])
223
- ],
224
- )
148
+ for type_yaml in yaml_data.get("types", []):
149
+ build_type(yaml_data=type_yaml, code_model=code_model)
225
150
 
226
- # Custom URL
227
- code_model.setup_client_input_parameters(yaml_data)
151
+ code_model.client = Client.from_yaml(yaml_data["client"], code_model)
152
+ code_model.config = Config.from_yaml(yaml_data["client"], code_model)
228
153
 
229
154
  # Build request builders
230
155
  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
- ]
236
- _build_convenience_layer(yaml_data=yaml_data, code_model=code_model)
237
-
238
- if options["credential"]:
239
- code_model.global_parameters.add_credential_global_parameter()
156
+ for og_group in yaml_data["operationGroups"]:
157
+ for operation_yaml in og_group["operations"]:
158
+ request_builder = get_request_builder(
159
+ operation_yaml, code_model=code_model
160
+ )
161
+ if request_builder.overloads:
162
+ code_model.request_builders.extend(request_builder.overloads) # type: ignore
163
+ code_model.request_builders.append(request_builder)
164
+ if operation_yaml.get("nextOperation"):
165
+ # i am a paging operation and i have a next operation. Make sure to include my next operation
166
+ code_model.request_builders.append(
167
+ get_request_builder(
168
+ operation_yaml["nextOperation"], code_model=code_model
169
+ )
170
+ )
240
171
 
172
+ _build_convenience_layer(yaml_data=yaml_data, code_model=code_model)
241
173
  code_model.package_dependency = self._build_package_dependency()
242
174
  return code_model
243
175
 
244
- def _get_credential_scopes(self, credential):
245
- credential_scopes_temp = self._autorestapi.get_value("credential-scopes")
246
- credential_scopes = (
247
- credential_scopes_temp.split(",") if credential_scopes_temp else None
248
- )
249
- if credential_scopes and not credential:
250
- raise ValueError(
251
- "--credential-scopes must be used with the --add-credential flag"
252
- )
253
-
254
- # check to see if user just passes in --credential-scopes with no value
255
- if (
256
- self._autorestapi.get_boolean_value("credential-scopes", False)
257
- and not credential_scopes
258
- ):
259
- raise ValueError(
260
- "--credential-scopes takes a list of scopes in comma separated format. "
261
- "For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
262
- )
263
- return credential_scopes
264
-
265
- def _update_with_credential_flags(
266
- self,
267
- code_model: CodeModel,
268
- credential_schema_policy: Type[CredentialSchemaPolicy],
269
- credential_model: CredentialModel,
270
- ):
271
- credential_model.policy_type = credential_schema_policy
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"]
280
-
281
- if hasattr(credential_schema_policy, "credential_scopes"):
282
- if not credential_scopes:
283
- if azure_arm:
284
- credential_scopes = ["https://management.azure.com/.default"]
285
- elif credential:
286
- # If add-credential is specified, we still want to add a credential_scopes variable.
287
- # Will make it an empty list so we can differentiate between this case and None
288
- _LOGGER.warning(
289
- "You have default credential policy %s "
290
- "but not the --credential-scopes flag set while generating non-management plane code. "
291
- "This is not recommend because it forces the customer to pass credential scopes "
292
- "through kwargs if they want to authenticate.",
293
- credential_schema_policy.name(),
294
- )
295
- credential_scopes = []
296
-
297
- if credential_key_header_name:
298
- raise ValueError(
299
- "You have passed in a credential key header name with default credential policy type "
300
- f"{credential_schema_policy.name()}. This is not allowed, since credential key header "
301
- "name is tied with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you "
302
- "pass in --credential-scopes."
303
- )
304
- credential_model.credential_scopes = set(credential_scopes)
305
- else:
306
- # currently the only other credential policy is AzureKeyCredentialPolicy
307
- if credential_scopes:
308
- raise ValueError(
309
- "You have passed in credential scopes with default credential policy type "
310
- "AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with "
311
- f"{credential_model.default_authentication_policy.name()}. Instead, with this policy "
312
- "you must pass in --credential-key-header-name."
313
- )
314
- if not credential_key_header_name:
315
- credential_key_header_name = "api-key"
316
- _LOGGER.info(
317
- "Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'"
318
- )
319
-
320
- credential_model.key_header_name = credential_key_header_name
321
-
322
- def _build_with_credential_flags(
323
- self, code_model: CodeModel, credential_model: CredentialModel
324
- ):
325
- if not code_model.options["credential"]:
326
- return
327
-
328
- credential_schema_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
334
- )
335
- self._update_with_credential_flags(
336
- code_model, credential_schema_policy_type, credential_model
337
- )
338
-
339
176
  def _build_code_model_options(self) -> Dict[str, Any]:
340
177
  """Build en options dict from the user input while running autorest."""
341
178
  azure_arm = self._autorestapi.get_boolean_value("azure-arm", False)
342
- credential = self._autorestapi.get_boolean_value(
343
- "add-credentials", False
344
- ) or self._autorestapi.get_boolean_value("add-credential", False)
345
-
346
179
  license_header = self._autorestapi.get_value("header-text")
347
180
  if license_header:
348
181
  license_header = license_header.replace("\n", "\n# ")
@@ -352,11 +185,11 @@ class CodeGenerator(Plugin):
352
185
  )
353
186
  license_header += "\n# --------------------------------------------------------------------------"
354
187
 
355
- low_level_client = self._autorestapi.get_boolean_value(
356
- "low-level-client", False
188
+ low_level_client = cast(
189
+ bool, self._autorestapi.get_boolean_value("low-level-client", False)
357
190
  )
358
- version_tolerant = self._autorestapi.get_boolean_value(
359
- "version-tolerant", False
191
+ version_tolerant = cast(
192
+ bool, self._autorestapi.get_boolean_value("version-tolerant", False)
360
193
  )
361
194
  show_operations = self._autorestapi.get_boolean_value(
362
195
  "show-operations", not low_level_client
@@ -364,13 +197,15 @@ class CodeGenerator(Plugin):
364
197
  models_mode_default = (
365
198
  "none" if low_level_client or version_tolerant else "msrest"
366
199
  )
367
- python3_only = self._autorestapi.get_boolean_value(
368
- "python3-only", low_level_client or version_tolerant
200
+ python3_only = cast(
201
+ bool,
202
+ self._autorestapi.get_boolean_value(
203
+ "python3-only", low_level_client or version_tolerant
204
+ ),
369
205
  )
370
206
 
371
207
  options: Dict[str, Any] = {
372
208
  "azure_arm": azure_arm,
373
- "credential": credential,
374
209
  "head_as_boolean": self._autorestapi.get_boolean_value(
375
210
  "head-as-boolean", False
376
211
  ),
@@ -407,7 +242,8 @@ class CodeGenerator(Plugin):
407
242
  low_level_client or version_tolerant,
408
243
  ),
409
244
  "add_python3_operation_files": self._autorestapi.get_boolean_value(
410
- "add-python3-operation-files", python3_only and not low_level_client
245
+ "add-python3-operation-files",
246
+ python3_only and not (low_level_client or version_tolerant),
411
247
  ),
412
248
  "version_tolerant": version_tolerant,
413
249
  "low_level_client": low_level_client,
@@ -444,7 +280,6 @@ class CodeGenerator(Plugin):
444
280
 
445
281
  # Force some options in ARM MODE:
446
282
  if azure_arm:
447
- options["credential"] = True
448
283
  options["head_as_boolean"] = True
449
284
  return options
450
285
 
@@ -455,7 +290,16 @@ class CodeGenerator(Plugin):
455
290
  if "code-model-v4-no-tags.yaml" not in inputs:
456
291
  raise ValueError("code-model-v4-no-tags.yaml must be a possible input")
457
292
 
458
- file_content = self._autorestapi.read_file("code-model-v4-no-tags.yaml")
293
+ if self._autorestapi.get_value("input-yaml"):
294
+ input_yaml = self._autorestapi.get_value("input-yaml")
295
+ file_content = self._autorestapi.read_file(input_yaml)
296
+ else:
297
+ inputs = self._autorestapi.list_inputs()
298
+ _LOGGER.debug("Possible Inputs: %s", inputs)
299
+ if "code-model-v4-no-tags.yaml" not in inputs:
300
+ raise ValueError("code-model-v4-no-tags.yaml must be a possible input")
301
+
302
+ file_content = self._autorestapi.read_file("code-model-v4-no-tags.yaml")
459
303
 
460
304
  # Parse the received YAML
461
305
  yaml_data = yaml.safe_load(file_content)