@autorest/python 6.13.1 → 6.13.4
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/autorest/_utils.py +6 -2
- package/autorest/codegen/__init__.py +20 -13
- package/autorest/codegen/models/__init__.py +2 -1
- package/autorest/codegen/models/client.py +3 -3
- package/autorest/codegen/models/code_model.py +5 -1
- package/autorest/codegen/models/credential_types.py +4 -8
- package/autorest/codegen/models/operation.py +1 -1
- package/autorest/codegen/models/response.py +2 -2
- package/autorest/codegen/serializers/__init__.py +1 -1
- package/autorest/codegen/serializers/builder_serializer.py +11 -9
- package/autorest/codegen/serializers/client_serializer.py +3 -3
- package/autorest/codegen/serializers/general_serializer.py +1 -1
- package/autorest/codegen/templates/config.py.jinja2 +1 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_base.py.jinja2 +2 -2
- package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +5 -5
- package/autorest/codegen/templates/vendor.py.jinja2 +2 -2
- package/autorest/m4reformatter/__init__.py +1 -1
- package/autorest/multiapi/models/code_model.py +1 -1
- package/autorest/multiapi/serializers/__init__.py +3 -1
- package/autorest/preprocess/__init__.py +5 -13
- package/package.json +1 -1
package/autorest/_utils.py
CHANGED
|
@@ -121,9 +121,13 @@ JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
|
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
def build_policies(
|
|
124
|
-
is_arm: bool,
|
|
124
|
+
is_arm: bool,
|
|
125
|
+
async_mode: bool,
|
|
126
|
+
*,
|
|
127
|
+
is_azure_flavor: bool = False,
|
|
128
|
+
tracing: bool = True,
|
|
125
129
|
) -> List[str]:
|
|
126
|
-
if
|
|
130
|
+
if is_azure_flavor:
|
|
127
131
|
# for Azure
|
|
128
132
|
async_prefix = "Async" if async_mode else ""
|
|
129
133
|
policies = [
|
|
@@ -26,7 +26,7 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
26
26
|
class OptionsRetriever:
|
|
27
27
|
OPTIONS_TO_DEFAULT = {
|
|
28
28
|
"azure-arm": False,
|
|
29
|
-
"
|
|
29
|
+
"flavor": "azure", # need to default to azure in shared code so we don't break swagger generation
|
|
30
30
|
"no-async": False,
|
|
31
31
|
"low-level-client": False,
|
|
32
32
|
"version-tolerant": True,
|
|
@@ -40,6 +40,10 @@ class OptionsRetriever:
|
|
|
40
40
|
"from-typespec": False,
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
@property
|
|
44
|
+
def is_azure_flavor(self) -> bool:
|
|
45
|
+
return self.flavor == "azure"
|
|
46
|
+
|
|
43
47
|
def __init__(self, options: Dict[str, Any]) -> None:
|
|
44
48
|
self.options = options
|
|
45
49
|
|
|
@@ -49,15 +53,17 @@ class OptionsRetriever:
|
|
|
49
53
|
|
|
50
54
|
@property
|
|
51
55
|
def company_name(self) -> str:
|
|
52
|
-
return self.options.get(
|
|
56
|
+
return self.options.get(
|
|
57
|
+
"company-name", "Microsoft" if self.is_azure_flavor else ""
|
|
58
|
+
)
|
|
53
59
|
|
|
54
60
|
@property
|
|
55
61
|
def license_header(self) -> str:
|
|
56
62
|
license_header = self.options.get(
|
|
57
63
|
"header-text",
|
|
58
|
-
|
|
59
|
-
if self.
|
|
60
|
-
else
|
|
64
|
+
DEFAULT_HEADER_TEXT.format(company_name=self.company_name)
|
|
65
|
+
if self.company_name
|
|
66
|
+
else "",
|
|
61
67
|
)
|
|
62
68
|
if license_header:
|
|
63
69
|
license_header = license_header.replace("\n", "\n# ")
|
|
@@ -96,7 +102,7 @@ class OptionsRetriever:
|
|
|
96
102
|
def tracing(self) -> bool:
|
|
97
103
|
return self.options.get(
|
|
98
104
|
"tracing",
|
|
99
|
-
self.show_operations and
|
|
105
|
+
self.show_operations and self.is_azure_flavor,
|
|
100
106
|
)
|
|
101
107
|
|
|
102
108
|
@property
|
|
@@ -264,10 +270,11 @@ class CodeGenerator(Plugin):
|
|
|
264
270
|
"Please read https://aka.ms/azsdk/dpcodegen for more details."
|
|
265
271
|
)
|
|
266
272
|
|
|
267
|
-
if
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
273
|
+
if (
|
|
274
|
+
not self.options_retriever.is_azure_flavor
|
|
275
|
+
and self.options_retriever.tracing
|
|
276
|
+
):
|
|
277
|
+
raise ValueError("Can only have tracing turned on for Azure SDKs.")
|
|
271
278
|
|
|
272
279
|
@staticmethod
|
|
273
280
|
def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
|
|
@@ -324,7 +331,7 @@ class CodeGenerator(Plugin):
|
|
|
324
331
|
"generate_sample",
|
|
325
332
|
"default_api_version",
|
|
326
333
|
"from_typespec",
|
|
327
|
-
"
|
|
334
|
+
"flavor",
|
|
328
335
|
"company_name",
|
|
329
336
|
]
|
|
330
337
|
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
@@ -347,10 +354,10 @@ class CodeGenerator(Plugin):
|
|
|
347
354
|
self.remove_cloud_errors(yaml_data)
|
|
348
355
|
|
|
349
356
|
code_model = CodeModel(yaml_data=yaml_data, options=options)
|
|
350
|
-
if self.options_retriever.
|
|
357
|
+
if not self.options_retriever.is_azure_flavor and any(
|
|
351
358
|
client.lro_operations for client in code_model.clients
|
|
352
359
|
):
|
|
353
|
-
raise ValueError("
|
|
360
|
+
raise ValueError("Only support LROs for Azure SDKs")
|
|
354
361
|
serializer = self.get_serializer(code_model)
|
|
355
362
|
serializer.serialize()
|
|
356
363
|
|
|
@@ -132,7 +132,8 @@ TYPE_TO_OBJECT = {
|
|
|
132
132
|
"enumvalue": EnumValue,
|
|
133
133
|
"binary": BinaryType,
|
|
134
134
|
"any": AnyType,
|
|
135
|
-
"
|
|
135
|
+
"utcDateTime": DatetimeType,
|
|
136
|
+
"offsetDateTime": DatetimeType,
|
|
136
137
|
"plainTime": TimeType,
|
|
137
138
|
"duration": DurationType,
|
|
138
139
|
"plainDate": DateType,
|
|
@@ -214,7 +214,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
214
214
|
)
|
|
215
215
|
else:
|
|
216
216
|
file_import.add_submodule_import(
|
|
217
|
-
"
|
|
217
|
+
"" if self.code_model.is_azure_flavor else "runtime",
|
|
218
218
|
self.pipeline_class(async_mode),
|
|
219
219
|
ImportType.SDKCORE,
|
|
220
220
|
)
|
|
@@ -240,7 +240,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
240
240
|
typing_section=TypingSection.REGULAR,
|
|
241
241
|
)
|
|
242
242
|
file_import.add_submodule_import(
|
|
243
|
-
"
|
|
243
|
+
"pipeline" if self.code_model.is_azure_flavor else "runtime",
|
|
244
244
|
"policies",
|
|
245
245
|
ImportType.SDKCORE,
|
|
246
246
|
)
|
|
@@ -428,7 +428,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
428
428
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
429
429
|
file_import = FileImport(self.code_model)
|
|
430
430
|
file_import.add_submodule_import(
|
|
431
|
-
"
|
|
431
|
+
"pipeline" if self.code_model.is_azure_flavor else "runtime",
|
|
432
432
|
"policies",
|
|
433
433
|
ImportType.SDKCORE,
|
|
434
434
|
)
|
|
@@ -119,6 +119,10 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
119
119
|
pass
|
|
120
120
|
raise KeyError(f"No request builder with id {request_builder_id} found.")
|
|
121
121
|
|
|
122
|
+
@property
|
|
123
|
+
def is_azure_flavor(self) -> bool:
|
|
124
|
+
return self.options["flavor"] == "azure"
|
|
125
|
+
|
|
122
126
|
@property
|
|
123
127
|
def rest_layer_name(self) -> str:
|
|
124
128
|
"""If we have a separate rest layer, what is its name?"""
|
|
@@ -210,7 +214,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
210
214
|
|
|
211
215
|
@property
|
|
212
216
|
def core_library(self) -> Literal["azure.core", "corehttp"]:
|
|
213
|
-
return "azure.core" if
|
|
217
|
+
return "azure.core" if self.is_azure_flavor else "corehttp"
|
|
214
218
|
|
|
215
219
|
def _sort_model_types_helper(
|
|
216
220
|
self,
|
|
@@ -86,9 +86,9 @@ class KeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
|
86
86
|
@property
|
|
87
87
|
def credential_name(self) -> str:
|
|
88
88
|
return (
|
|
89
|
-
"
|
|
90
|
-
if self.code_model.
|
|
91
|
-
else "
|
|
89
|
+
"AzureKeyCredential"
|
|
90
|
+
if self.code_model.is_azure_flavor
|
|
91
|
+
else "ServiceKeyCredential"
|
|
92
92
|
)
|
|
93
93
|
|
|
94
94
|
def call(self, async_mode: bool) -> str:
|
|
@@ -188,11 +188,7 @@ class TokenCredentialType(
|
|
|
188
188
|
|
|
189
189
|
@property
|
|
190
190
|
def credentials_subfolder(self) -> str:
|
|
191
|
-
return
|
|
192
|
-
"credentials"
|
|
193
|
-
if self.code_model.options["unbranded"]
|
|
194
|
-
else "credentials_async"
|
|
195
|
-
)
|
|
191
|
+
return "credentials_async" if self.code_model.is_azure_flavor else "credentials"
|
|
196
192
|
|
|
197
193
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
198
194
|
if kwargs.get("async_mode"):
|
|
@@ -450,7 +450,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
450
450
|
):
|
|
451
451
|
file_import.merge(self.request_builder.imports())
|
|
452
452
|
file_import.add_submodule_import(
|
|
453
|
-
f"{'
|
|
453
|
+
f"{'' if self.code_model.is_azure_flavor else 'runtime.'}pipeline",
|
|
454
454
|
"PipelineResponse",
|
|
455
455
|
ImportType.SDKCORE,
|
|
456
456
|
)
|
|
@@ -180,7 +180,7 @@ class PagingResponse(Response):
|
|
|
180
180
|
or f"{self.code_model.core_library}.paging.ItemPaged"
|
|
181
181
|
)
|
|
182
182
|
default_paging_submodule = (
|
|
183
|
-
f"{'' if self.code_model.
|
|
183
|
+
f"{'async_' if self.code_model.is_azure_flavor else ''}paging"
|
|
184
184
|
)
|
|
185
185
|
self.pager_async: str = (
|
|
186
186
|
self.yaml_data.get("pagerAsync")
|
|
@@ -231,7 +231,7 @@ class PagingResponse(Response):
|
|
|
231
231
|
async_mode = kwargs.get("async_mode")
|
|
232
232
|
if async_mode:
|
|
233
233
|
file_import.add_submodule_import(
|
|
234
|
-
f"{'' if self.code_model.
|
|
234
|
+
f"{'async_' if self.code_model.is_azure_flavor else ''}paging",
|
|
235
235
|
"AsyncList",
|
|
236
236
|
ImportType.SDKCORE,
|
|
237
237
|
)
|
|
@@ -242,7 +242,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
242
242
|
params = self.code_model.options["packaging_files_config"] or {}
|
|
243
243
|
for template_name in package_files:
|
|
244
244
|
if (
|
|
245
|
-
self.code_model.
|
|
245
|
+
not self.code_model.is_azure_flavor
|
|
246
246
|
and template_name == "dev_requirements.txt.jinja2"
|
|
247
247
|
):
|
|
248
248
|
continue
|
|
@@ -451,7 +451,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
451
451
|
|
|
452
452
|
@property
|
|
453
453
|
def pipeline_name(self) -> str:
|
|
454
|
-
return f"{'' if self.code_model.
|
|
454
|
+
return f"{'_' if self.code_model.is_azure_flavor else ''}pipeline"
|
|
455
455
|
|
|
456
456
|
|
|
457
457
|
############################## REQUEST BUILDERS ##############################
|
|
@@ -1112,16 +1112,18 @@ class _OperationSerializer(
|
|
|
1112
1112
|
if response.headers:
|
|
1113
1113
|
retval.append("")
|
|
1114
1114
|
deserialize_code: List[str] = []
|
|
1115
|
+
no_stream_logic = False
|
|
1115
1116
|
if builder.has_stream_response:
|
|
1116
1117
|
if isinstance(response.type, ByteArraySchema):
|
|
1117
|
-
|
|
1118
|
-
deserialized = "response.content"
|
|
1118
|
+
deserialized = f"{'await ' if self.async_mode else ''}response.read()"
|
|
1119
1119
|
else:
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1120
|
+
no_stream_logic = True
|
|
1121
|
+
if self.code_model.options["version_tolerant"]:
|
|
1122
|
+
deserialized = "response.iter_bytes()"
|
|
1123
|
+
else:
|
|
1124
|
+
deserialized = (
|
|
1125
|
+
f"response.stream_download(self._client.{self.pipeline_name})"
|
|
1126
|
+
)
|
|
1125
1127
|
deserialize_code.append(f"deserialized = {deserialized}")
|
|
1126
1128
|
elif response.type:
|
|
1127
1129
|
pylint_disable = ""
|
|
@@ -1169,7 +1171,7 @@ class _OperationSerializer(
|
|
|
1169
1171
|
deserialize_code.append("else:")
|
|
1170
1172
|
deserialize_code.append(" deserialized = None")
|
|
1171
1173
|
if len(deserialize_code) > 0:
|
|
1172
|
-
if builder.expose_stream_keyword and not
|
|
1174
|
+
if builder.expose_stream_keyword and not no_stream_logic:
|
|
1173
1175
|
retval.append("if _stream:")
|
|
1174
1176
|
retval.append(" deserialized = response.iter_bytes()")
|
|
1175
1177
|
retval.append("else:")
|
|
@@ -111,7 +111,7 @@ class ClientSerializer:
|
|
|
111
111
|
result = []
|
|
112
112
|
pipeline_client_name = self.client.pipeline_class(async_mode)
|
|
113
113
|
endpoint_name = (
|
|
114
|
-
"
|
|
114
|
+
"base_url" if self.client.code_model.is_azure_flavor else "endpoint"
|
|
115
115
|
)
|
|
116
116
|
params = {
|
|
117
117
|
endpoint_name: self.host_variable_name,
|
|
@@ -124,8 +124,8 @@ class ClientSerializer:
|
|
|
124
124
|
policies = build_policies(
|
|
125
125
|
self.client.code_model.options["azure_arm"],
|
|
126
126
|
async_mode,
|
|
127
|
-
self.client.code_model.
|
|
128
|
-
self.client.code_model.options["tracing"],
|
|
127
|
+
is_azure_flavor=self.client.code_model.is_azure_flavor,
|
|
128
|
+
tracing=self.client.code_model.options["tracing"],
|
|
129
129
|
)
|
|
130
130
|
result.extend(
|
|
131
131
|
[
|
|
@@ -107,7 +107,7 @@ class GeneralSerializer(BaseSerializer):
|
|
|
107
107
|
ImportType.STDLIB,
|
|
108
108
|
)
|
|
109
109
|
file_import.add_submodule_import(
|
|
110
|
-
"
|
|
110
|
+
"" if self.code_model.is_azure_flavor else "runtime",
|
|
111
111
|
f"{'Async' if self.async_mode else ''}PipelineClient",
|
|
112
112
|
ImportType.SDKCORE,
|
|
113
113
|
TypingSection.TYPING,
|
|
@@ -51,7 +51,7 @@ class {{ client.name }}Configuration: {{ client.config.pylint_disable }}
|
|
|
51
51
|
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
|
|
52
52
|
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
|
|
53
53
|
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
|
|
54
|
-
{% if
|
|
54
|
+
{% if code_model.is_azure_flavor %}
|
|
55
55
|
self.http_logging_policy = kwargs.get('http_logging_policy') or {{ "ARM" if client.code_model.options['azure_arm'] else "policies." }}HttpLoggingPolicy(**kwargs)
|
|
56
56
|
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
|
|
57
57
|
self.redirect_policy = kwargs.get('redirect_policy') or policies.{{ keywords.async_class }}RedirectPolicy(**kwargs)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{{ code_model.options['license_header'] }}
|
|
3
3
|
|
|
4
4
|
from enum import Enum
|
|
5
|
-
from {{ code_model.core_library }}{{ "
|
|
5
|
+
from {{ code_model.core_library }}{{ "" if code_model.is_azure_flavor else ".utils" }} import CaseInsensitiveEnumMeta
|
|
6
6
|
|
|
7
7
|
{% for enum in code_model.enums | sort %}
|
|
8
8
|
{% include "enum.py.jinja2" %}
|
|
@@ -22,8 +22,8 @@ from json import JSONEncoder
|
|
|
22
22
|
from typing_extensions import Self
|
|
23
23
|
import isodate
|
|
24
24
|
from {{ code_model.core_library }}.exceptions import DeserializationError
|
|
25
|
-
from {{ code_model.core_library }}{{ "
|
|
26
|
-
from {{ code_model.core_library }}.{{ "
|
|
25
|
+
from {{ code_model.core_library }}{{ "" if code_model.is_azure_flavor else ".utils" }} import CaseInsensitiveEnumMeta
|
|
26
|
+
from {{ code_model.core_library }}.{{ "" if code_model.is_azure_flavor else "runtime." }}pipeline import PipelineResponse
|
|
27
27
|
from {{ code_model.core_library }}.serialization import _Null
|
|
28
28
|
|
|
29
29
|
if sys.version_info >= (3, 9):
|
|
@@ -45,7 +45,7 @@ setup(
|
|
|
45
45
|
license="MIT License",
|
|
46
46
|
author="{{ code_model.options["company_name"] }} Corporation",
|
|
47
47
|
{% endif %}
|
|
48
|
-
{% if
|
|
48
|
+
{% if code_model.is_azure_flavor %}
|
|
49
49
|
author_email="{{ author_email }}",
|
|
50
50
|
url="{{ url }}",
|
|
51
51
|
keywords="azure, azure sdk",
|
|
@@ -89,12 +89,12 @@ setup(
|
|
|
89
89
|
{% else %}
|
|
90
90
|
"isodate<1.0.0,>=0.6.1",
|
|
91
91
|
{% endif %}
|
|
92
|
-
{% if
|
|
93
|
-
"corehttp[requests]",
|
|
94
|
-
{% elif azure_arm %}
|
|
92
|
+
{% if azure_arm %}
|
|
95
93
|
"azure-mgmt-core<2.0.0,>=1.3.2",
|
|
96
|
-
{%
|
|
94
|
+
{% elif code_model.is_azure_flavor %}
|
|
97
95
|
"azure-core<2.0.0,>=1.30.0",
|
|
96
|
+
{% else %}
|
|
97
|
+
"corehttp[requests]",
|
|
98
98
|
{% endif %}
|
|
99
99
|
{% if code_model.need_typing_extensions %}
|
|
100
100
|
"typing-extensions>=4.6.0",
|
|
@@ -65,7 +65,7 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi
|
|
|
65
65
|
return "*"
|
|
66
66
|
return None
|
|
67
67
|
{% endif %}
|
|
68
|
-
{% if code_model.has_form_data and code_model.options["models_mode"] == "dpg" %}
|
|
68
|
+
{% if code_model.has_form_data and code_model.options["models_mode"] == "dpg" and not async_mode %}
|
|
69
69
|
# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)`
|
|
70
70
|
FileContent = Union[str, bytes, IO[str], IO[bytes]]
|
|
71
71
|
|
|
@@ -103,4 +103,4 @@ def prepare_multipart_form_data(
|
|
|
103
103
|
data[data_field] = serialize_multipart_data_entry(data_entry)
|
|
104
104
|
|
|
105
105
|
return files, data
|
|
106
|
-
{% endif %}
|
|
106
|
+
{% endif %}
|
|
@@ -233,7 +233,7 @@ def update_primitive( # pylint: disable=too-many-return-statements
|
|
|
233
233
|
if type_group == "binary":
|
|
234
234
|
return KNOWN_TYPES["binary"]
|
|
235
235
|
if type_group == "date-time":
|
|
236
|
-
base = _update_type_base("
|
|
236
|
+
base = _update_type_base("utcDateTime", yaml_data)
|
|
237
237
|
base["encode"] = yaml_data["format"]
|
|
238
238
|
return base
|
|
239
239
|
if type_group == "byte-array":
|
|
@@ -45,7 +45,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
45
45
|
default_version_metadata["global_parameters"]
|
|
46
46
|
)
|
|
47
47
|
self.user_specified_default_api = user_specified_default_api
|
|
48
|
-
self.options: Dict[str, Any] = {"
|
|
48
|
+
self.options: Dict[str, Any] = {"flavor": "azure", "company_name": "Microsoft"}
|
|
49
49
|
self.core_library = "azure.core"
|
|
50
50
|
|
|
51
51
|
@property
|
|
@@ -87,7 +87,9 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
87
87
|
|
|
88
88
|
# serialize service client file
|
|
89
89
|
imports = FileImportSerializer(code_model.client.imports(async_mode))
|
|
90
|
-
config_policies = build_policies(
|
|
90
|
+
config_policies = build_policies(
|
|
91
|
+
code_model.azure_arm, async_mode, is_azure_flavor=True
|
|
92
|
+
)
|
|
91
93
|
self.write_file(
|
|
92
94
|
_get_file_path(code_model.client.filename, async_mode),
|
|
93
95
|
_render_template(
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import copy
|
|
9
9
|
from typing import Callable, Dict, Any, List, Optional
|
|
10
10
|
|
|
11
|
-
from .._utils import to_snake_case
|
|
11
|
+
from .._utils import to_snake_case
|
|
12
12
|
from .helpers import (
|
|
13
13
|
add_redefined_builtin_info,
|
|
14
14
|
pad_builtin_namespaces,
|
|
@@ -267,23 +267,15 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
267
267
|
type.get("description", ""), type["name"]
|
|
268
268
|
)
|
|
269
269
|
type["snakeCaseName"] = to_snake_case(type["name"])
|
|
270
|
-
if type.get("values")
|
|
270
|
+
if type.get("values"):
|
|
271
271
|
# we're enums
|
|
272
|
-
values_to_add = []
|
|
273
272
|
for value in type["values"]:
|
|
274
273
|
padded_name = self.pad_reserved_words(
|
|
275
274
|
value["name"].lower(), PadType.ENUM
|
|
276
275
|
).upper()
|
|
277
|
-
if
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
name=padded_name,
|
|
281
|
-
value=value["value"],
|
|
282
|
-
description=value["description"],
|
|
283
|
-
enum_type=value["enumType"],
|
|
284
|
-
)
|
|
285
|
-
)
|
|
286
|
-
type["values"].extend(values_to_add)
|
|
276
|
+
if padded_name[0] in "0123456789":
|
|
277
|
+
padded_name = "ENUM_" + padded_name
|
|
278
|
+
value["name"] = padded_name
|
|
287
279
|
|
|
288
280
|
# add type for reference
|
|
289
281
|
for v in HEADERS_CONVERT_IN_METHOD.values():
|