@autorest/python 5.15.0 → 5.18.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.
- package/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -5,42 +5,35 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
7
|
import sys
|
|
8
|
-
from typing import Dict, Any,
|
|
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
|
|
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_policy import BearerTokenCredentialPolicy, AzureKeyCredentialPolicy
|
|
22
|
-
from .models.credential_model import CredentialModel
|
|
23
20
|
|
|
24
|
-
_AAD_TYPE = "AADToken"
|
|
25
|
-
_KEY_TYPE = "AzureKey"
|
|
26
21
|
|
|
27
22
|
def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -> None:
|
|
28
23
|
# Create operations
|
|
29
24
|
if code_model.options["show_operations"] and yaml_data.get("operationGroups"):
|
|
30
25
|
code_model.operation_groups = [
|
|
31
|
-
OperationGroup.from_yaml(
|
|
26
|
+
OperationGroup.from_yaml(op_group, code_model)
|
|
27
|
+
for op_group in yaml_data["operationGroups"]
|
|
32
28
|
]
|
|
33
|
-
if yaml_data.get("
|
|
34
|
-
code_model.add_inheritance_to_models()
|
|
29
|
+
if yaml_data.get("types"):
|
|
35
30
|
if code_model.options["models_mode"]:
|
|
36
|
-
code_model.
|
|
31
|
+
code_model.sort_model_types()
|
|
37
32
|
|
|
38
33
|
if code_model.options["show_operations"]:
|
|
39
|
-
code_model.generate_single_parameter_from_multiple_content_types_operation()
|
|
40
|
-
code_model.link_operation_to_request_builder()
|
|
41
34
|
# LRO operation
|
|
42
35
|
code_model.format_lro_operations()
|
|
43
|
-
|
|
36
|
+
|
|
44
37
|
|
|
45
38
|
def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
46
39
|
|
|
@@ -84,7 +77,10 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
84
77
|
)
|
|
85
78
|
|
|
86
79
|
if options["package_mode"]:
|
|
87
|
-
if
|
|
80
|
+
if (
|
|
81
|
+
options["package_mode"] not in ("mgmtplane", "dataplane")
|
|
82
|
+
and not Path(options["package_mode"]).exists()
|
|
83
|
+
):
|
|
88
84
|
raise ValueError(
|
|
89
85
|
"--package-mode can only be 'mgmtplane' or 'dataplane' or directory which contains template files"
|
|
90
86
|
)
|
|
@@ -101,7 +97,10 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
101
97
|
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
102
98
|
)
|
|
103
99
|
|
|
100
|
+
|
|
104
101
|
_LOGGER = logging.getLogger(__name__)
|
|
102
|
+
|
|
103
|
+
|
|
105
104
|
class CodeGenerator(Plugin):
|
|
106
105
|
@staticmethod
|
|
107
106
|
def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
|
|
@@ -112,7 +111,11 @@ class CodeGenerator(Plugin):
|
|
|
112
111
|
i = 0
|
|
113
112
|
while i < len(operation["exceptions"]):
|
|
114
113
|
exception = operation["exceptions"][i]
|
|
115
|
-
if
|
|
114
|
+
if (
|
|
115
|
+
exception.get("schema")
|
|
116
|
+
and exception["schema"]["language"]["default"]["name"]
|
|
117
|
+
== "CloudError"
|
|
118
|
+
):
|
|
116
119
|
del operation["exceptions"][i]
|
|
117
120
|
i -= 1
|
|
118
121
|
i += 1
|
|
@@ -123,19 +126,6 @@ class CodeGenerator(Plugin):
|
|
|
123
126
|
del yaml_data["schemas"]["objects"][i]
|
|
124
127
|
break
|
|
125
128
|
|
|
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
129
|
@staticmethod
|
|
140
130
|
def _build_package_dependency() -> Dict[str, str]:
|
|
141
131
|
return {
|
|
@@ -144,227 +134,136 @@ class CodeGenerator(Plugin):
|
|
|
144
134
|
"dependency_msrest": "msrest>=0.6.21",
|
|
145
135
|
}
|
|
146
136
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if security_yaml.get("authenticationRequired"):
|
|
151
|
-
for scheme in security_yaml.get("schemes"):
|
|
152
|
-
if _AAD_TYPE == scheme["type"]:
|
|
153
|
-
credential_model.credential_scopes.update(scheme["scopes"])
|
|
154
|
-
elif _KEY_TYPE == scheme["type"]:
|
|
155
|
-
# only accept the last one
|
|
156
|
-
credential_model.key_header_name = scheme["headerName"]
|
|
157
|
-
|
|
158
|
-
if credential_model.credential_scopes:
|
|
159
|
-
credential_model.policy_type = BearerTokenCredentialPolicy
|
|
160
|
-
elif credential_model.key_header_name:
|
|
161
|
-
credential_model.policy_type = AzureKeyCredentialPolicy
|
|
162
|
-
|
|
163
|
-
@staticmethod
|
|
164
|
-
def _build_credential_model(code_model: CodeModel, credential_model: CredentialModel):
|
|
165
|
-
if credential_model.policy_type:
|
|
166
|
-
code_model.options["credential"] = True
|
|
167
|
-
credential_model.build_authentication_policy()
|
|
168
|
-
code_model.credential_model = credential_model
|
|
169
|
-
|
|
170
|
-
def _handle_credential_model(self, yaml_data: Dict[str, Any], code_model: CodeModel):
|
|
171
|
-
credential_model = CredentialModel(code_model.options["azure_arm"])
|
|
172
|
-
|
|
173
|
-
# credential info with security definition will be overridded by credential flags
|
|
174
|
-
self._build_with_security_definition(yaml_data, credential_model)
|
|
175
|
-
self._build_with_credential_flags(code_model, credential_model)
|
|
176
|
-
|
|
177
|
-
self._build_credential_model(code_model, credential_model)
|
|
178
|
-
|
|
179
|
-
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:
|
|
180
140
|
# Create a code model
|
|
181
141
|
|
|
182
|
-
code_model = CodeModel(options=options)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
code_model.class_name = yaml_data["info"]["pascal_case_title"]
|
|
186
|
-
code_model.description = (
|
|
187
|
-
yaml_data["info"]["description"] if yaml_data["info"].get("description") else ""
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
# Get my namespace
|
|
191
|
-
namespace = self._autorestapi.get_value("namespace")
|
|
192
|
-
_LOGGER.debug("Namespace parameter was %s", namespace)
|
|
193
|
-
if not namespace:
|
|
194
|
-
namespace = yaml_data["info"]["python_title"]
|
|
195
|
-
code_model.namespace = namespace
|
|
196
|
-
|
|
197
|
-
if yaml_data.get("schemas"):
|
|
198
|
-
exceptions_set = CodeGenerator._build_exceptions_set(yaml_data=yaml_data["operationGroups"])
|
|
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)
|
|
199
145
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
build_schema(yaml_data=schema, exceptions_set=exceptions_set, code_model=code_model)
|
|
146
|
+
code_model.client = Client.from_yaml(yaml_data["client"], code_model)
|
|
147
|
+
code_model.config = Config.from_yaml(yaml_data["client"], code_model)
|
|
203
148
|
|
|
204
|
-
#
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
+
)
|
|
213
166
|
|
|
214
|
-
code_model.rest = Rest.from_yaml(yaml_data, code_model=code_model)
|
|
215
167
|
_build_convenience_layer(yaml_data=yaml_data, code_model=code_model)
|
|
216
|
-
|
|
217
|
-
if options["credential"]:
|
|
218
|
-
code_model.global_parameters.add_credential_global_parameter()
|
|
219
|
-
|
|
220
168
|
code_model.package_dependency = self._build_package_dependency()
|
|
221
169
|
return code_model
|
|
222
170
|
|
|
223
|
-
def _get_credential_scopes(self, credential):
|
|
224
|
-
credential_scopes_temp = self._autorestapi.get_value("credential-scopes")
|
|
225
|
-
credential_scopes = credential_scopes_temp.split(",") if credential_scopes_temp else None
|
|
226
|
-
if credential_scopes and not credential:
|
|
227
|
-
raise ValueError("--credential-scopes must be used with the --add-credential flag")
|
|
228
|
-
|
|
229
|
-
# 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:
|
|
231
|
-
raise ValueError(
|
|
232
|
-
"--credential-scopes takes a list of scopes in comma separated format. "
|
|
233
|
-
"For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
|
|
234
|
-
)
|
|
235
|
-
return credential_scopes
|
|
236
|
-
|
|
237
|
-
def _update_with_credential_flags(
|
|
238
|
-
self,
|
|
239
|
-
code_model: CodeModel,
|
|
240
|
-
credential_schema_policy: Type[CredentialSchemaPolicy],
|
|
241
|
-
credential_model: CredentialModel
|
|
242
|
-
):
|
|
243
|
-
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']
|
|
248
|
-
|
|
249
|
-
if hasattr(credential_schema_policy, "credential_scopes"):
|
|
250
|
-
if not credential_scopes:
|
|
251
|
-
if azure_arm:
|
|
252
|
-
credential_scopes = ["https://management.azure.com/.default"]
|
|
253
|
-
elif credential:
|
|
254
|
-
# If add-credential is specified, we still want to add a credential_scopes variable.
|
|
255
|
-
# Will make it an empty list so we can differentiate between this case and None
|
|
256
|
-
_LOGGER.warning(
|
|
257
|
-
"You have default credential policy %s "
|
|
258
|
-
"but not the --credential-scopes flag set while generating non-management plane code. "
|
|
259
|
-
"This is not recommend because it forces the customer to pass credential scopes "
|
|
260
|
-
"through kwargs if they want to authenticate.",
|
|
261
|
-
credential_schema_policy.name()
|
|
262
|
-
)
|
|
263
|
-
credential_scopes = []
|
|
264
|
-
|
|
265
|
-
if credential_key_header_name:
|
|
266
|
-
raise ValueError(
|
|
267
|
-
"You have passed in a credential key header name with default credential policy type "
|
|
268
|
-
f"{credential_schema_policy.name()}. This is not allowed, since credential key header "
|
|
269
|
-
"name is tied with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you "
|
|
270
|
-
"pass in --credential-scopes."
|
|
271
|
-
)
|
|
272
|
-
credential_model.credential_scopes = set(credential_scopes)
|
|
273
|
-
else:
|
|
274
|
-
# currently the only other credential policy is AzureKeyCredentialPolicy
|
|
275
|
-
if credential_scopes:
|
|
276
|
-
raise ValueError(
|
|
277
|
-
"You have passed in credential scopes with default credential policy type "
|
|
278
|
-
"AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with "
|
|
279
|
-
f"{credential_model.default_authentication_policy.name()}. Instead, with this policy "
|
|
280
|
-
"you must pass in --credential-key-header-name."
|
|
281
|
-
)
|
|
282
|
-
if not credential_key_header_name:
|
|
283
|
-
credential_key_header_name = "api-key"
|
|
284
|
-
_LOGGER.info(
|
|
285
|
-
"Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'"
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
credential_model.key_header_name = credential_key_header_name
|
|
289
|
-
|
|
290
|
-
def _build_with_credential_flags(self, code_model: CodeModel, credential_model: CredentialModel):
|
|
291
|
-
if not code_model.options["credential"]:
|
|
292
|
-
return
|
|
293
|
-
|
|
294
|
-
credential_schema_policy_name = (
|
|
295
|
-
self._autorestapi.get_value("credential-default-policy-type") or
|
|
296
|
-
credential_model.default_authentication_policy.name()
|
|
297
|
-
)
|
|
298
|
-
credential_schema_policy_type = get_credential_schema_policy_type(credential_schema_policy_name)
|
|
299
|
-
self._update_with_credential_flags(
|
|
300
|
-
code_model, credential_schema_policy_type, credential_model
|
|
301
|
-
)
|
|
302
|
-
|
|
303
171
|
def _build_code_model_options(self) -> Dict[str, Any]:
|
|
304
|
-
"""Build en options dict from the user input while running autorest.
|
|
305
|
-
"""
|
|
172
|
+
"""Build en options dict from the user input while running autorest."""
|
|
306
173
|
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
|
-
)
|
|
311
|
-
|
|
312
174
|
license_header = self._autorestapi.get_value("header-text")
|
|
313
175
|
if license_header:
|
|
314
176
|
license_header = license_header.replace("\n", "\n# ")
|
|
315
177
|
license_header = (
|
|
316
|
-
"# --------------------------------------------------------------------------\n# "
|
|
178
|
+
"# --------------------------------------------------------------------------\n# "
|
|
179
|
+
+ license_header
|
|
317
180
|
)
|
|
318
181
|
license_header += "\n# --------------------------------------------------------------------------"
|
|
319
182
|
|
|
320
|
-
low_level_client =
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
+
)
|
|
325
201
|
|
|
326
202
|
options: Dict[str, Any] = {
|
|
327
203
|
"azure_arm": azure_arm,
|
|
328
|
-
"
|
|
329
|
-
|
|
204
|
+
"head_as_boolean": self._autorestapi.get_boolean_value(
|
|
205
|
+
"head-as-boolean", False
|
|
206
|
+
),
|
|
330
207
|
"license_header": license_header,
|
|
331
|
-
"keep_version_file": self._autorestapi.get_boolean_value(
|
|
208
|
+
"keep_version_file": self._autorestapi.get_boolean_value(
|
|
209
|
+
"keep-version-file", False
|
|
210
|
+
),
|
|
332
211
|
"no_async": self._autorestapi.get_boolean_value("no-async", False),
|
|
333
|
-
"no_namespace_folders": self._autorestapi.get_boolean_value(
|
|
334
|
-
|
|
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
|
+
),
|
|
335
218
|
"package_name": self._autorestapi.get_value("package-name"),
|
|
336
219
|
"package_version": self._autorestapi.get_value("package-version"),
|
|
337
|
-
"client_side_validation": self._autorestapi.get_boolean_value(
|
|
220
|
+
"client_side_validation": self._autorestapi.get_boolean_value(
|
|
221
|
+
"client-side-validation", False
|
|
222
|
+
),
|
|
338
223
|
"tracing": self._autorestapi.get_boolean_value("trace", show_operations),
|
|
339
224
|
"multiapi": self._autorestapi.get_boolean_value("multiapi", False),
|
|
340
|
-
"polymorphic_examples": self._autorestapi.get_value("polymorphic-examples")
|
|
341
|
-
|
|
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(),
|
|
342
230
|
"builders_visibility": self._autorestapi.get_value("builders-visibility"),
|
|
343
231
|
"show_operations": show_operations,
|
|
344
232
|
"show_send_request": self._autorestapi.get_boolean_value(
|
|
345
233
|
"show-send-request", low_level_client or version_tolerant
|
|
346
234
|
),
|
|
347
235
|
"only_path_and_body_params_positional": self._autorestapi.get_boolean_value(
|
|
348
|
-
"only-path-and-body-params-positional",
|
|
236
|
+
"only-path-and-body-params-positional",
|
|
237
|
+
low_level_client or version_tolerant,
|
|
349
238
|
),
|
|
350
239
|
"add_python3_operation_files": self._autorestapi.get_boolean_value(
|
|
351
|
-
"add-python3-operation-files",
|
|
240
|
+
"add-python3-operation-files",
|
|
241
|
+
python3_only and not (low_level_client or version_tolerant),
|
|
352
242
|
),
|
|
353
243
|
"version_tolerant": version_tolerant,
|
|
354
244
|
"low_level_client": low_level_client,
|
|
355
|
-
"combine_operation_files": self._autorestapi.get_boolean_value(
|
|
245
|
+
"combine_operation_files": self._autorestapi.get_boolean_value(
|
|
246
|
+
"combine-operation-files", version_tolerant
|
|
247
|
+
),
|
|
356
248
|
"python3_only": python3_only,
|
|
357
249
|
"package_mode": self._autorestapi.get_value("package-mode"),
|
|
358
250
|
"package_pprint_name": self._autorestapi.get_value("package-pprint-name"),
|
|
359
|
-
"package_configuration": self._autorestapi.get_value(
|
|
251
|
+
"package_configuration": self._autorestapi.get_value(
|
|
252
|
+
"package-configuration"
|
|
253
|
+
),
|
|
360
254
|
"default_optional_constants_to_none": self._autorestapi.get_boolean_value(
|
|
361
|
-
"default-optional-constants-to-none",
|
|
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
|
|
362
260
|
),
|
|
363
|
-
"reformat_next_link": self._autorestapi.get_boolean_value("reformat-next-link", not version_tolerant)
|
|
364
261
|
}
|
|
365
262
|
|
|
366
263
|
if options["builders_visibility"] is None:
|
|
367
|
-
options["builders_visibility"] =
|
|
264
|
+
options["builders_visibility"] = (
|
|
265
|
+
"public" if low_level_client else "embedded"
|
|
266
|
+
)
|
|
368
267
|
else:
|
|
369
268
|
options["builders_visibility"] = options["builders_visibility"].lower()
|
|
370
269
|
|
|
@@ -376,7 +275,6 @@ class CodeGenerator(Plugin):
|
|
|
376
275
|
|
|
377
276
|
# Force some options in ARM MODE:
|
|
378
277
|
if azure_arm:
|
|
379
|
-
options["credential"] = True
|
|
380
278
|
options["head_as_boolean"] = True
|
|
381
279
|
return options
|
|
382
280
|
|
|
@@ -387,7 +285,16 @@ class CodeGenerator(Plugin):
|
|
|
387
285
|
if "code-model-v4-no-tags.yaml" not in inputs:
|
|
388
286
|
raise ValueError("code-model-v4-no-tags.yaml must be a possible input")
|
|
389
287
|
|
|
390
|
-
|
|
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")
|
|
391
298
|
|
|
392
299
|
# Parse the received YAML
|
|
393
300
|
yaml_data = yaml.safe_load(file_content)
|
|
@@ -406,9 +313,13 @@ class CodeGenerator(Plugin):
|
|
|
406
313
|
|
|
407
314
|
|
|
408
315
|
def main(yaml_model_file: str) -> None:
|
|
409
|
-
from ..jsonrpc.localapi import
|
|
316
|
+
from ..jsonrpc.localapi import ( # pylint: disable=import-outside-toplevel
|
|
317
|
+
LocalAutorestAPI,
|
|
318
|
+
)
|
|
410
319
|
|
|
411
|
-
code_generator = CodeGenerator(
|
|
320
|
+
code_generator = CodeGenerator(
|
|
321
|
+
autorestapi=LocalAutorestAPI(reachable_files=[yaml_model_file])
|
|
322
|
+
)
|
|
412
323
|
if not code_generator.process():
|
|
413
324
|
raise SystemExit("Process didn't finish gracefully")
|
|
414
325
|
|